├── .gitignore
├── phpstan.neon
├── src
├── Exceptions
│ └── InvalidOperationException.php
└── Eloquent
│ └── TypeSafeCollection.php
├── tests
├── Data
│ ├── User.php
│ ├── Comment.php
│ ├── UserCollection.php
│ └── CommentCollection.php
├── Feature
│ ├── DumpTest.php
│ ├── PushTest.php
│ ├── MapIntoTest.php
│ ├── CollapseTest.php
│ ├── ContainsTest.php
│ ├── ContainsStrictTest.php
│ ├── EachTest.php
│ ├── KeysTest.php
│ ├── FlipTest.php
│ ├── CombineTest.php
│ ├── ExceptTest.php
│ ├── DiffKeysTest.php
│ ├── FilterTest.php
│ ├── MapTest.php
│ ├── DiffTest.php
│ ├── ModeTest.php
│ ├── DiffAssocTest.php
│ ├── MapToGroupsTest.php
│ ├── MapWithKeysTest.php
│ ├── CrossJoinTest.php
│ ├── AvgTest.php
│ ├── ZipTest.php
│ ├── PartitionTest.php
│ ├── AddTest.php
│ ├── DuplicatesTest.php
│ ├── PrependTest.php
│ ├── DuplicatesStrictTest.php
│ ├── MakeTest.php
│ ├── WrapTest.php
│ ├── CountByTest.php
│ ├── MedianTest.php
│ ├── OffsetSetTest.php
│ ├── TimesTest.php
│ ├── DiffKeysUsingTest.php
│ ├── MapToDictionaryTest.php
│ ├── ConstructorTest.php
│ ├── DiffUsingTest.php
│ ├── MergeTest.php
│ ├── UnionTest.php
│ ├── GroupByTest.php
│ ├── ChunkTest.php
│ └── DiffAssocUsingTest.php
└── TestCase.php
├── .editorconfig
├── .php_cs
├── .scrutinizer.yml
├── phpunit.xml
├── LICENSE.md
├── composer.json
├── .travis.yml
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | .php_cs.cache
3 | .phpunit.result.cache
4 | composer.lock
5 |
--------------------------------------------------------------------------------
/phpstan.neon:
--------------------------------------------------------------------------------
1 | parameters:
2 | ignoreErrors:
3 | - '#Unsafe usage of new static\(\)#'
4 | checkMissingIterableValueType: false
5 | reportUnmatchedIgnoredErrors: false
6 |
--------------------------------------------------------------------------------
/src/Exceptions/InvalidOperationException.php:
--------------------------------------------------------------------------------
1 | dump();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/Feature/PushTest.php:
--------------------------------------------------------------------------------
1 | push(new User());
14 |
15 | $this->assertInstanceOf(UserCollection::class, $result);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/Feature/MapIntoTest.php:
--------------------------------------------------------------------------------
1 | mapInto(Comment::class);
15 |
16 | $this->assertInstanceOf(Collection::class, $result);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/Feature/CollapseTest.php:
--------------------------------------------------------------------------------
1 | new User(),
15 | ]);
16 |
17 | $this->assertInstanceOf(UserCollection::class, $collection->collapse());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/Feature/ContainsTest.php:
--------------------------------------------------------------------------------
1 | contains('test');
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Feature/ContainsStrictTest.php:
--------------------------------------------------------------------------------
1 | containsStrict('test');
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Feature/EachTest.php:
--------------------------------------------------------------------------------
1 | each(function (User $user) {
21 | });
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Feature/KeysTest.php:
--------------------------------------------------------------------------------
1 | keys();
18 |
19 | $this->assertInstanceOf(Collection::class, $result);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tests/Feature/FlipTest.php:
--------------------------------------------------------------------------------
1 | flip();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Feature/CombineTest.php:
--------------------------------------------------------------------------------
1 | combine([]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/Feature/ExceptTest.php:
--------------------------------------------------------------------------------
1 | new User(),
15 | ]);
16 |
17 | $result = $collection->except([
18 | 'test',
19 | ]);
20 |
21 | $this->assertInstanceOf(Usercollection::class, $result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Feature/DiffKeysTest.php:
--------------------------------------------------------------------------------
1 | new User(),
15 | ]);
16 |
17 | $result = $collection->diffKeys([
18 | 'test',
19 | ]);
20 |
21 | $this->assertInstanceOf(UserCollection::class, $result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Feature/FilterTest.php:
--------------------------------------------------------------------------------
1 | new User(),
15 | ]);
16 |
17 | $result = $collection->filter(function (User $user) {
18 | return true;
19 | });
20 |
21 | $this->assertInstanceOf(Usercollection::class, $result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/.php_cs:
--------------------------------------------------------------------------------
1 | setRules([
5 | '@Symfony' => true,
6 | '@Symfony:risky' => true,
7 | 'array_syntax' => ['syntax' => 'short'],
8 | 'protected_to_private' => false,
9 | 'compact_nullable_typehint' => true,
10 | 'concat_space' => ['spacing' => 'one'],
11 | 'phpdoc_separation' => false,
12 | 'yoda_style' => null,
13 | ])
14 | ->setRiskyAllowed(true)
15 | ->setFinder(
16 | PhpCsFixer\Finder::create()
17 | ->in([
18 | __DIR__ . '/src',
19 | __DIR__ . '/tests',
20 | ])
21 | ->append([__FILE__])
22 | );
23 |
--------------------------------------------------------------------------------
/tests/Feature/MapTest.php:
--------------------------------------------------------------------------------
1 | map(function (User $user) {
18 | return $user->toArray();
19 | });
20 |
21 | $this->assertInstanceOf(Collection::class, $result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Feature/DiffTest.php:
--------------------------------------------------------------------------------
1 | diff([
19 | new Comment(),
20 | ]);
21 |
22 | $this->assertInstanceOf(UserCollection::class, $result);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/Feature/ModeTest.php:
--------------------------------------------------------------------------------
1 | mode('test');
23 | } catch (\Throwable $e) {
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 | useDatabasePath(__DIR__ . '/database');
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/Feature/DiffAssocTest.php:
--------------------------------------------------------------------------------
1 | new User(),
16 | ]);
17 |
18 | $result = $collection->diffAssoc([
19 | 'test' => new Comment(),
20 | ]);
21 |
22 | $this->assertInstanceOf(UserCollection::class, $result);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/Feature/MapToGroupsTest.php:
--------------------------------------------------------------------------------
1 | mapToGroups(function (User $user, $index) {
18 | return ['group-' . $index => $user];
19 | });
20 |
21 | $this->assertInstanceOf(Collection::class, $result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Feature/MapWithKeysTest.php:
--------------------------------------------------------------------------------
1 | mapWithKeys(function (User $user, $index) {
18 | return ['key-' . $index => $user];
19 | });
20 |
21 | $this->assertInstanceOf(Collection::class, $result);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/Feature/CrossJoinTest.php:
--------------------------------------------------------------------------------
1 | crossJoin([
20 | new Comment(),
21 | ]);
22 |
23 | $this->assertInstanceOf(Collection::class, $result);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/Feature/AvgTest.php:
--------------------------------------------------------------------------------
1 | avg(function () {
21 | return 1;
22 | });
23 |
24 | $collection->avg('test');
25 |
26 | // FIXME: This errors due to invalid types
27 | // $collection->avg();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Feature/ZipTest.php:
--------------------------------------------------------------------------------
1 | zip([
18 | new User(),
19 | new User(),
20 | ]);
21 |
22 | $this->assertInstanceOf(Collection::class, $result);
23 | $this->assertInstanceOf(UserCollection::class, $result->first());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/Feature/PartitionTest.php:
--------------------------------------------------------------------------------
1 | partition(function () {
18 | return true;
19 | });
20 |
21 | $this->assertInstanceOf(Collection::class, $result);
22 | $this->assertInstanceOf(UserCollection::class, $result->first());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/Feature/AddTest.php:
--------------------------------------------------------------------------------
1 | add(new User());
15 |
16 | $this->assertInstanceOf(UserCollection::class, $result);
17 | }
18 |
19 | /**
20 | * @expectedException \InvalidArgumentException
21 | */
22 | public function testIncorrect(): void
23 | {
24 | (new UserCollection())->add(new Comment());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/Feature/DuplicatesTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
20 |
21 | return;
22 | }
23 |
24 | $result = $collection->duplicates();
25 |
26 | $this->assertInstanceOf(UserCollection::class, $result);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/Feature/PrependTest.php:
--------------------------------------------------------------------------------
1 | prepend(new User());
15 |
16 | $this->assertInstanceOf(UserCollection::class, $result);
17 | }
18 |
19 | /**
20 | * @expectedException \InvalidArgumentException
21 | */
22 | public function testIncorrect(): void
23 | {
24 | (new UserCollection())->prepend(new Comment());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/Feature/DuplicatesStrictTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
20 |
21 | return;
22 | }
23 |
24 | $result = $collection->duplicatesStrict();
25 |
26 | $this->assertInstanceOf(UserCollection::class, $result);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/Feature/MakeTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(UserCollection::class, $result);
19 | }
20 |
21 | /**
22 | * @expectedException \InvalidArgumentException
23 | */
24 | public function testIncorrect(): void
25 | {
26 | UserCollection::make([
27 | new Comment(),
28 | ]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Feature/WrapTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(UserCollection::class, $result);
19 | }
20 |
21 | /**
22 | * @expectedException \InvalidArgumentException
23 | */
24 | public function testIncorrect(): void
25 | {
26 | UserCollection::wrap([
27 | new Comment(),
28 | ]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Feature/CountByTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
20 |
21 | return;
22 | }
23 |
24 | $result = $collection->countBy(function () {
25 | return 'test';
26 | });
27 |
28 | $this->assertInstanceOf(Collection::class, $result);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Feature/MedianTest.php:
--------------------------------------------------------------------------------
1 | median('test');
23 |
24 | // This breaks < 5.7
25 | /* @phpstan-ignore-next-line */
26 | if (version_compare(Application::VERSION, '5.7', '>=')) {
27 | $collection->median();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Feature/OffsetSetTest.php:
--------------------------------------------------------------------------------
1 | offsetSet(0, new User());
20 | }
21 |
22 | /**
23 | * @expectedException \InvalidArgumentException
24 | */
25 | public function testIncorrect(): void
26 | {
27 | (new UserCollection([
28 | new User(),
29 | ]))->offsetSet(0, new Comment());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/Feature/TimesTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(UserCollection::class, $result);
19 | }
20 |
21 | /**
22 | * @expectedException \InvalidArgumentException
23 | */
24 | public function testIncorrect(): void
25 | {
26 | UserCollection::times(2, function () {
27 | return new Comment();
28 | });
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/Feature/DiffKeysUsingTest.php:
--------------------------------------------------------------------------------
1 | new User(),
15 | ]);
16 |
17 | if (!method_exists($collection, 'diffKeysUsing')) {
18 | $this->assertTrue(true);
19 |
20 | return;
21 | }
22 |
23 | $result = $collection->diffKeysUsing([
24 | 'test',
25 | ], function ($key1, $key2) {
26 | return true;
27 | });
28 |
29 | $this->assertInstanceOf(UserCollection::class, $result);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/Feature/MapToDictionaryTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
16 |
17 | return;
18 | }
19 |
20 | $result = (new UserCollection([
21 | new User(),
22 | new User(),
23 | ]))->mapToDictionary(function (User $user, $index) {
24 | return ['index-' . $index => $user];
25 | });
26 |
27 | $this->assertInstanceOf(Collection::class, $result);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Feature/ConstructorTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
20 |
21 | return;
22 | }
23 |
24 | $result = $collection->diffUsing([
25 | new Comment(),
26 | ], function ($original, $other) {
27 | return true;
28 | });
29 |
30 | $this->assertInstanceOf(UserCollection::class, $result);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/Feature/MergeTest.php:
--------------------------------------------------------------------------------
1 | merge([
17 | new User(),
18 | ]);
19 |
20 | $this->assertInstanceOf(UserCollection::class, $result);
21 | }
22 |
23 | /**
24 | * @expectedException \InvalidArgumentException
25 | */
26 | public function testIncorrect(): void
27 | {
28 | $collection = new UserCollection([]);
29 |
30 | $collection->merge([
31 | new Comment(),
32 | ]);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/Feature/UnionTest.php:
--------------------------------------------------------------------------------
1 | union([
17 | new User(),
18 | ]);
19 |
20 | $this->assertInstanceOf(UserCollection::class, $result);
21 | }
22 |
23 | /**
24 | * @expectedException \InvalidArgumentException
25 | */
26 | public function testIncorrect(): void
27 | {
28 | $collection = new UserCollection([]);
29 |
30 | $collection->union([
31 | new Comment(),
32 | ]);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/Feature/GroupByTest.php:
--------------------------------------------------------------------------------
1 | groupBy(function () {
18 | return 'test';
19 | });
20 |
21 | $this->assertInstanceOf(Collection::class, $result);
22 | }
23 |
24 | public function testCorrectWithKey(): void
25 | {
26 | $result = (new UserCollection([
27 | new User(),
28 | new User(),
29 | ]))->groupBy('test');
30 |
31 | $this->assertInstanceOf(Collection::class, $result);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/Feature/ChunkTest.php:
--------------------------------------------------------------------------------
1 | chunk(1);
18 |
19 | $this->assertInstanceOf(Collection::class, $result);
20 | $this->assertInstanceOf(UserCollection::class, $result->first());
21 | }
22 |
23 | public function testCorrectEmpty(): void
24 | {
25 | $result = (new UserCollection([
26 | new User(),
27 | new User(),
28 | ]))->chunk(0);
29 |
30 | $this->assertInstanceOf(Collection::class, $result);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/Feature/DiffAssocUsingTest.php:
--------------------------------------------------------------------------------
1 | new User(),
16 | ]);
17 |
18 | if (!method_exists($collection, 'diffAssocUsing')) {
19 | $this->assertTrue(true);
20 |
21 | return;
22 | }
23 |
24 | $result = $collection->diffAssocUsing([
25 | 'test' => new Comment(),
26 | ], function ($original, $other) {
27 | return true;
28 | });
29 |
30 | $this->assertInstanceOf(UserCollection::class, $result);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/.scrutinizer.yml:
--------------------------------------------------------------------------------
1 | filter:
2 | excluded_paths: [tests/*]
3 |
4 | checks:
5 | php:
6 | remove_extra_empty_lines: true
7 | remove_php_closing_tag: true
8 | remove_trailing_whitespace: true
9 | fix_use_statements:
10 | remove_unused: true
11 | preserve_multiple: false
12 | preserve_blanklines: true
13 | order_alphabetically: true
14 | fix_php_opening_tag: true
15 | fix_linefeed: true
16 | fix_line_ending: true
17 | fix_identation_4spaces: true
18 | fix_doc_comments: true
19 | code_rating: true
20 | duplication: true
21 |
22 | build:
23 | nodes:
24 | php71:
25 | environment:
26 | php:
27 | version: 7.1.12
28 | services:
29 | mysql: 5.7
30 | tests:
31 | override:
32 | - php-scrutinizer-run
33 | -
34 | command: mysql -e 'CREATE DATABASE db_rebuild;' && vendor/bin/phpunit --coverage-clover=coverage71
35 | coverage:
36 | file: coverage71
37 | format: php-clover
38 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |