Skip to content

Commit 70fc3c1

Browse files
authored
Merge pull request #16 from gameeapp/major_upgrade_v4
Major upgrade to v4
2 parents a98df61 + 192d6d9 commit 70fc3c1

31 files changed

+3386
-1006
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ composer.lock
66
*.iml
77
out
88
gen
9+
10+
# Test
11+
tests/_data/*
12+
!tests/_data/.gitkeep
13+
tests/_output/*
14+
!tests/_output/.gitkeep
15+
tests/temp/*
16+
!tests/temp/.gitkeep
17+
tests/log/*
18+
!tests/log/.gitkeep

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
language: php
22

33
php:
4-
- 7.4
4+
- 8.0
55

66
install:
77
- composer install -a --no-interaction --prefer-source
88

99
script:
10-
- composer tests
11-
- composer phpstan
12-
- composer phpcs
10+
- make unit-ci
11+
- make stan-ci
12+
- make cs

codeception.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
actor_suffix: Tester
8+
extensions:
9+
enabled:
10+
- Codeception\Extension\RunFailed
11+
12+
coverage:
13+
enabled: true
14+
include:
15+
- src/*

composer.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
{
2-
"name": "gamee/php-collections",
3-
"description": "package of usefull collections for php",
4-
"type": "library",
5-
"license": "MIT",
6-
"authors": [
7-
{
8-
"name": "Gamee",
9-
"email": "[email protected]"
10-
}
11-
],
12-
"minimum-stability": "dev",
13-
"prefer-stable": true,
14-
"require": {
15-
"php": ">=7.4"
16-
},
17-
"require-dev": {
18-
"nette/tester": "^2.0",
19-
"gamee/php-code-checker-rules": "^2.0"
20-
},
21-
"autoload": {
22-
"psr-4": {
23-
"Gamee\\Collections\\": "src/"
24-
}
25-
},
26-
"autoload-dev": {
27-
"psr-4": {
28-
"Gamee\\Collections\\Tests\\": "tests/"
29-
}
30-
},
31-
"scripts": {
32-
"tests": "php vendor/nette/tester/src/tester.php tests -C",
33-
"phpstan": "vendor/bin/phpstan analyse src tests -c phpstan.neon --level 8",
34-
"phpcs": "vendor/bin/phpcs --standard=vendor/gamee/php-code-checker-rules/ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=temp -sp src tests",
35-
"phpcsfix": "vendor/bin/phpcbf --standard=vendor/gamee/php-code-checker-rules/ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=temp -sp src tests"
36-
}
37-
}
2+
"name": "gamee/php-collections",
3+
"description": "package of useful collections for php",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Gamee",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"prefer-stable": true,
14+
"require": {
15+
"php": ">=8.0"
16+
},
17+
"require-dev": {
18+
"codeception/codeception": "^4.1",
19+
"codeception/module-asserts": "^1.3",
20+
"gamee/php-code-checker-rules": "^3.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Gamee\\Collections\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Gamee\\Collections\\": "tests/unit/"
30+
}
31+
},
32+
"config": {
33+
"allow-plugins": {
34+
"dealerdirect/phpcodesniffer-composer-installer": false
35+
}
36+
}
37+
}

makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
TARGETS=src tests/unit
2+
PHP_STAN=php vendor/bin/phpstan analyse $(TARGETS) -c phpstan.neon --level 8
3+
PHP_CS_SETTINGS=--standard=./vendor/gamee/php-code-checker-rules/ruleset.xml --extensions=php --ignore=temp
4+
TEST_UNIT=XDEBUG_MODE=coverage php vendor/bin/codecept run unit --coverage-cobertura
5+
6+
.PHONY: stan
7+
stan:
8+
$(PHP_STAN)
9+
10+
.PHONY: stan-ci
11+
stan-ci:
12+
$(PHP_STAN) --no-progress
13+
14+
.PHONY: cs
15+
cs:
16+
vendor/bin/phpcs $(PHP_CS_SETTINGS) -sp $(TARGETS) --parallel=8
17+
18+
.PHONY: csfix
19+
csfix:
20+
vendor/bin/phpcbf $(PHP_CS_SETTINGS) -sp $(TARGETS)
21+
22+
.PHONY: unit
23+
unit:
24+
$(TEST_UNIT) --no-exit --verbose
25+
26+
.PHONY: unit-ci
27+
unit-ci:
28+
$(TEST_UNIT)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gamee\Collections\Collection;
6+
7+
class CollectionException extends \RuntimeException
8+
{
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Gamee\Collections\Collection;
6+
7+
final class CollectionIsNotEmptyException extends CollectionException
8+
{
9+
public function __construct()
10+
{
11+
parent::__construct(
12+
'Collection is not empty.'
13+
);
14+
}
15+
}

src/Collection/DuplicateKeyException.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44

55
namespace Gamee\Collections\Collection;
66

7-
final class DuplicateKeyException extends \Exception
7+
final class DuplicateKeyException extends CollectionException
88
{
9-
10-
/**
11-
* DuplicateKeyException constructor.
12-
*
13-
* @param string|int $key
14-
*/
15-
public function __construct($key)
16-
{
17-
parent::__construct(
18-
sprintf(
19-
'Item with key: "%s" already exists.',
20-
$key
21-
)
22-
);
23-
}
9+
public function __construct(string|int $key)
10+
{
11+
parent::__construct(
12+
\sprintf(
13+
'Item with key: "%s" already exists.',
14+
$key,
15+
),
16+
);
17+
}
2418
}
Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

33
/**
4-
* @copyright Copyright (c) 2018 gameeapp.com <[email protected]>
5-
* @author Pavel Janda <[email protected]>
6-
* @package Gamee
4+
* @copyright Copyright (c) 2018 gameeapp.com <[email protected]>
5+
*
6+
* @author Pavel Janda <[email protected]>
7+
*
8+
* @package Gamee
79
*/
810

911
declare(strict_types=1);
@@ -12,50 +14,51 @@
1214

1315
use Gamee\Collections\Iterator\ObjectIterator;
1416

17+
/**
18+
* @deprecated will be removed in 5.0, use UniqueObjectCollection
19+
*/
1520
abstract class ImmutableObjectCollection extends ObjectIterator implements \Countable
1621
{
17-
18-
abstract protected function getItemType(): string;
19-
20-
21-
final public function __construct(array $data)
22-
{
23-
$classItemName = $this->getItemType();
24-
25-
foreach ($data as $item) {
26-
if (!$item instanceof $classItemName) {
27-
throw new \InvalidArgumentException(self::class . ' only accepts ' . $this->getItemType());
28-
}
29-
}
30-
31-
parent::__construct($data);
32-
}
33-
34-
/**
35-
* @param mixed $item
36-
*
37-
* @throws \InvalidArgumentException
38-
*/
39-
public function addItem($item): self
40-
{
41-
$classItemName = $this->getItemType();
42-
43-
if (!$item instanceof $classItemName) {
44-
throw new \InvalidArgumentException(self::class . '::addItem() only accepts ' . $this->getItemType());
45-
}
46-
47-
return new static(array_merge($this->data, [$item]));
48-
}
49-
50-
51-
public function count(): int
52-
{
53-
return count($this->data);
54-
}
55-
56-
57-
public function isEmpty(): bool
58-
{
59-
return $this->data === [];
60-
}
22+
final public function __construct(array $data)
23+
{
24+
$classItemName = $this->getItemType();
25+
26+
foreach ($data as $item) {
27+
if (!$item instanceof $classItemName) {
28+
throw new \InvalidArgumentException(self::class . ' only accepts ' . $this->getItemType());
29+
}
30+
}
31+
32+
parent::__construct($data);
33+
}
34+
35+
36+
abstract protected function getItemType(): string;
37+
38+
39+
/**
40+
* @throws \InvalidArgumentException
41+
*/
42+
public function addItem(mixed $item): self
43+
{
44+
$classItemName = $this->getItemType();
45+
46+
if (!$item instanceof $classItemName) {
47+
throw new \InvalidArgumentException(self::class . '::addItem() only accepts ' . $this->getItemType());
48+
}
49+
50+
return new static(\array_merge($this->data, [$item]));
51+
}
52+
53+
54+
public function count(): int
55+
{
56+
return \count($this->data);
57+
}
58+
59+
60+
public function isEmpty(): bool
61+
{
62+
return $this->data === [];
63+
}
6164
}

src/Collection/ItemDoesNotExistException.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
namespace Gamee\Collections\Collection;
66

7-
final class ItemDoesNotExistException extends \Exception
7+
final class ItemDoesNotExistException extends CollectionException
88
{
9-
10-
/**
11-
* @param string|int $key
12-
*/
13-
public function __construct($key)
14-
{
15-
parent::__construct(
16-
sprintf(
17-
'Item with key "%s" does not exist.',
18-
$key
19-
)
20-
);
21-
}
9+
public function __construct(string|int $key, string $type = 'key')
10+
{
11+
parent::__construct(
12+
\sprintf(
13+
'Item with %s "%s" does not exist.',
14+
$type,
15+
$key,
16+
),
17+
);
18+
}
2219
}

0 commit comments

Comments
 (0)