From cc411976680834eba54eea5f4209484d96a2e643 Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sat, 2 Feb 2019 22:43:09 +0100 Subject: [PATCH] phpstan: upgrade to 0.11 --- composer.json | 4 ++-- src/Entity/AbstractEntity.php | 2 +- src/Mapper/Dbal/StorageReflection/StorageReflection.php | 5 +++-- src/Mapper/Memory/RelationshipMapperOneHasMany.php | 7 +++---- src/TestHelper/EntityCreator.php | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 8f7079cd..b3cf9bff 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,8 @@ "nette/tester": "~2.1", "marc-mabe/php-enum": "~3.0", "mockery/mockery": "~1.2", - "phpstan/phpstan-shim": "0.10.7", - "phpstan/phpstan-nette": "0.10.1", + "phpstan/phpstan-shim": "0.11.1", + "phpstan/phpstan-nette": "0.11", "tracy/tracy": "~2.3" }, "autoload": { diff --git a/src/Entity/AbstractEntity.php b/src/Entity/AbstractEntity.php index bac09692..ed0d00c3 100644 --- a/src/Entity/AbstractEntity.php +++ b/src/Entity/AbstractEntity.php @@ -448,7 +448,7 @@ private function &internalGetValue(PropertyMetadata $metadata, string $name) } else { $value = $this->data[$name]; } - if (!isset($value) && !$metadata->isNullable) { + if ($value === null && !$metadata->isNullable) { $class = get_class($this); throw new InvalidStateException("Property {$class}::\${$name} is not set."); } diff --git a/src/Mapper/Dbal/StorageReflection/StorageReflection.php b/src/Mapper/Dbal/StorageReflection/StorageReflection.php index 9c003e9e..9199f0f6 100644 --- a/src/Mapper/Dbal/StorageReflection/StorageReflection.php +++ b/src/Mapper/Dbal/StorageReflection/StorageReflection.php @@ -229,6 +229,7 @@ public function addModifier(string $storageKey, string $saveModifier): StorageRe protected function findManyHasManyPrimaryColumns($joinTable, $sourceTable, $targetTable): array { + $sourceId = $targetId = null; $useFQN = strpos($sourceTable, '.') !== false; $keys = $this->platform->getForeignKeys($joinTable); foreach ($keys as $column => $meta) { @@ -236,14 +237,14 @@ protected function findManyHasManyPrimaryColumns($joinTable, $sourceTable, $targ ? $meta['ref_table'] : preg_replace('#^(.*\.)?(.*)$#', '$2', $meta['ref_table']); - if ($table === $sourceTable && !isset($sourceId)) { + if ($table === $sourceTable && $sourceId === null) { $sourceId = $column; } elseif ($table === $targetTable) { $targetId = $column; } } - if (!isset($sourceId, $targetId)) { + if ($sourceId === null || $targetId === null) { throw new InvalidStateException("No primary keys detected for many has many '{$joinTable}' join table."); } diff --git a/src/Mapper/Memory/RelationshipMapperOneHasMany.php b/src/Mapper/Memory/RelationshipMapperOneHasMany.php index 291a073a..b507733e 100644 --- a/src/Mapper/Memory/RelationshipMapperOneHasMany.php +++ b/src/Mapper/Memory/RelationshipMapperOneHasMany.php @@ -39,9 +39,6 @@ public function clearCache() } - /** - * @return EntityIterator - */ public function getIterator(IEntity $parent, ICollection $collection): Iterator { $className = $this->metadata->relationship->entityMetadata->className; @@ -52,6 +49,8 @@ public function getIterator(IEntity $parent, ICollection $collection): Iterator public function getIteratorCount(IEntity $parent, ICollection $collection): int { - return count($this->getIterator($parent, $collection)); + $iterator = $this->getIterator($parent, $collection); + assert($iterator instanceof \Countable); + return count($iterator); } } diff --git a/src/TestHelper/EntityCreator.php b/src/TestHelper/EntityCreator.php index ee9319b9..43ff8624 100644 --- a/src/TestHelper/EntityCreator.php +++ b/src/TestHelper/EntityCreator.php @@ -98,7 +98,7 @@ protected function random(PropertyMetadata $property) } } - if (!$possibilities) { + if (count($possibilities) === 0) { return null; }