diff --git a/composer.json b/composer.json index f92d022..fc87889 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "php": "^7.0", "doctrine/common": "^2.0", "doctrine/inflector": "^1.0", + "symfony/polyfill-php71": "^1.0", "zendframework/zend-paginator": "^2.6" }, "require-dev": { @@ -56,29 +57,28 @@ "bin": [ ], "config": { - "preferred-install": "dist" + "preferred-install": "dist", + "sort-packages": true }, "scripts": { - "php-lint": "php -l src && php -l tests", + "phplint": "php -l src && php -l tests", "phpcs": "phpcs --standard=PSR2 src tests", "phpcs-lint": "php-cs-fixer fix --dry-run --verbose", "phpcpd": "phpcpd src", - "phpstan": "phpstan analyse --level 1 src tests", "phpmd": "phpmd src text unusedcode,naming,design,controversial,codesize", - "phpmetrics": "phpmetrics --failure-condition='average.maintainabilityIndex < 50' src", - "phpmetrics-report": "phpmetrics --report-html=build/metrics/index.html --offline src", + "phpmetrics-report": "phpmetrics --report-html=build/metrics/index.html --report-violations=build/logs/violations.xml --offline src", + "phpstan": "phpstan analyse --level 7 src", "phpunit": "phpunit", "phpunit-coverage": "phpunit --coverage-html build/coverage", "phpunit-clover": "phpunit --coverage-clover build/logs/clover.xml", "humbug": "humbug", "qa": [ - "@php-lint", + "@phplint", "@phpcs", "@phpcs-lint", "@phpcpd", "@phpmd", - "@phpstan", - "@phpmetrics" + "@phpstan" ], "reports": [ "@phpmetrics-report", @@ -87,7 +87,7 @@ "fix": "php-cs-fixer fix --verbose", "security": "composer outdated", "test": [ - "@php-lint", + "@qa", "@phpunit", "@humbug" ] diff --git a/src/Repository.php b/src/Repository.php index a3dc69c..e8551c5 100644 --- a/src/Repository.php +++ b/src/Repository.php @@ -130,8 +130,8 @@ public function getNew(); /** * Add objects. * - * @param object|object[]|\Traversable $objects - * @param bool $flush + * @param object|iterable $objects + * @param bool $flush */ public function add($objects, bool $flush = false); @@ -161,22 +161,22 @@ public function removeOneBy(array $criteria, bool $flush = false); /** * Remove objects. * - * @param object|object[]|\Traversable|string|int $objects - * @param bool $flush + * @param object|iterable|string|int $objects + * @param bool $flush */ public function remove($objects, bool $flush = false); /** * Refresh objects. * - * @param object|object[]|\Traversable $objects + * @param object|iterable $objects */ public function refresh($objects); /** * Detach objects. * - * @param object|object[]|\Traversable $objects + * @param object|iterable $objects */ public function detach($objects); diff --git a/src/RepositoryTrait.php b/src/RepositoryTrait.php index 53b8669..0220692 100644 --- a/src/RepositoryTrait.php +++ b/src/RepositoryTrait.php @@ -156,8 +156,8 @@ public function setObjectFactory(callable $objectFactory) /** * Add objects. * - * @param object|object[]|\Traversable $objects - * @param bool $flush + * @param object|iterable $objects + * @param bool $flush * * @throws \InvalidArgumentException */ @@ -201,14 +201,14 @@ public function removeOneBy(array $criteria, bool $flush = false) /** * Remove objects. * - * @param object|object[]|\Traversable|string|int $objects - * @param bool $flush + * @param object|iterable|string|int $objects + * @param bool $flush * * @throws \InvalidArgumentException */ public function remove($objects, bool $flush = false) { - if (!is_object($objects) && !is_array($objects) && !$objects instanceof \Traversable) { + if (!is_object($objects) && !is_iterable($objects)) { $objects = $this->find($objects); } @@ -218,7 +218,7 @@ public function remove($objects, bool $flush = false) /** * Refresh objects. * - * @param object|object[]|\Traversable $objects + * @param object|iterable $objects * * @throws \InvalidArgumentException */ @@ -235,7 +235,7 @@ public function refresh($objects) /** * Detach objects. * - * @param object|object[]|\Traversable $objects + * @param object|iterable $objects * * @throws \InvalidArgumentException */ @@ -362,9 +362,9 @@ protected function callSupportedMethod(string $method, string $fieldName, array /** * Run manager action. * - * @param string $action - * @param object|object[]|\Traversable $objects - * @param bool $flush + * @param string $action + * @param object|iterable $objects + * @param bool $flush * * @throws \InvalidArgumentException */ @@ -372,7 +372,7 @@ protected function runManagerAction(string $action, $objects, bool $flush) { $manager = $this->getManager(); - if (!$this->isTraversable($objects)) { + if (!is_iterable($objects)) { $objects = array_filter([$objects]); } @@ -390,24 +390,24 @@ protected function runManagerAction(string $action, $objects, bool $flush) $manager->$action($object); } + // @codeCoverageIgnoreStart + if ($objects instanceof \Traversable) { + $objects = iterator_to_array($objects); + } + // @codeCoverageIgnoreEnd + $this->flushObjects($objects, $flush); } /** * Flush managed objects. * - * @param object|object[]|\Traversable $objects - * @param bool $flush + * @param array $objects + * @param bool $flush */ - protected function flushObjects($objects, bool $flush) + protected function flushObjects(array $objects, bool $flush) { if ($flush || $this->autoFlush) { - // @codeCoverageIgnoreStart - if ($objects instanceof \Traversable) { - $objects = iterator_to_array($objects); - } - // @codeCoverageIgnoreEnd - $this->getManager()->flush($objects); } } @@ -446,16 +446,4 @@ abstract protected function getManager(); * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata */ abstract protected function getClassMetadata(); - - /** - * Is traversable. - * - * @param mixed $object - * - * @return bool - */ - private function isTraversable($object): bool - { - return is_array($object) || $object instanceof \Traversable; - } }