diff --git a/composer.json b/composer.json index e2c3d07..25d30ce 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ } }, "require": { - "artemeon/database": "^4.0", + "artemeon/database": "^4.0.1", "doctrine/collections": "^2.0", "php": ">=8.4", "psr/simple-cache": "^3.0" @@ -44,6 +44,7 @@ "symfony/cache": "^6.0" }, "config": { + "process-timeout": 0, "allow-plugins": { "pestphp/pest-plugin": true, "phpstan/extension-installer": true diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aec37cc..364905f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,16 +1,2 @@ parameters: ignoreErrors: - - - message: "#^Call to an undefined method Artemeon\\\\Database\\\\ConnectionInterface\\:\\:flushPreparedStatementsCache\\(\\)\\.$#" - count: 1 - path: tests/EntityManagerTestCase.php - - - - message: "#^Call to an undefined method Artemeon\\\\Database\\\\ConnectionInterface\\:\\:flushQueryCache\\(\\)\\.$#" - count: 1 - path: tests/EntityManagerTestCase.php - - - - message: "#^Call to an undefined method Artemeon\\\\Database\\\\ConnectionInterface\\:\\:flushTablesCache\\(\\)\\.$#" - count: 1 - path: tests/EntityManagerTestCase.php diff --git a/phpstan.neon b/phpstan.neon index 407209e..8dafb33 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,8 @@ includes: - - phar://phpstan.phar/conf/bleedingEdge.neon - phpstan-baseline.neon parameters: - level: 5 + level: 6 paths: - src - tests diff --git a/rector.php b/rector.php index 2abb8d5..ba03486 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,6 @@ codingStyle: true, typeDeclarations: true, earlyReturn: true, - strictBooleans: true, ) ->withPhpSets() ->withAttributesSets(phpunit: true) diff --git a/src/Attribute/OneToMany.php b/src/Attribute/OneToMany.php index de7a00d..ec00438 100644 --- a/src/Attribute/OneToMany.php +++ b/src/Attribute/OneToMany.php @@ -10,6 +10,9 @@ #[Attribute(Attribute::TARGET_PROPERTY)] class OneToMany { + /** + * @param list $type + */ public function __construct( public string $relationTable, public string $sourceColumn, diff --git a/src/Collection.php b/src/Collection.php index 3ef2faa..64465f5 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -16,6 +16,9 @@ */ class Collection extends AbstractLazyCollection { + /** + * @param list $type + */ public function __construct( private readonly string $relationTable, private readonly string $sourceColumn, diff --git a/src/Condition.php b/src/Condition.php index 504b60b..a8fb6f9 100644 --- a/src/Condition.php +++ b/src/Condition.php @@ -19,14 +19,23 @@ class Condition implements ConditionInterface { protected string $where = ''; + /** + * @var list + */ protected array $params = []; + /** + * @param list $params + */ public function __construct(string $where, array $params = []) { $this->setWhere($where); $this->setParams($params); } + /** + * @param list $params + */ public function setParams(array $params): void { $this->params = $params; diff --git a/src/Condition/InCondition.php b/src/Condition/InCondition.php index 56213d0..d2ede47 100644 --- a/src/Condition/InCondition.php +++ b/src/Condition/InCondition.php @@ -19,6 +19,9 @@ */ public const int MAX_IN_VALUES = 950; + /** + * @param list $params + */ public function __construct( private string $columnName, private array $params, diff --git a/src/ConditionInterface.php b/src/ConditionInterface.php index 03f8a08..ed06627 100644 --- a/src/ConditionInterface.php +++ b/src/ConditionInterface.php @@ -17,6 +17,8 @@ public function getWhere(): string; /** * Returns an array of the params for the given condition. + * + * @return list */ public function getParams(): array; } diff --git a/src/EntityManager.php b/src/EntityManager.php index 2508026..7c2b029 100644 --- a/src/EntityManager.php +++ b/src/EntityManager.php @@ -16,8 +16,8 @@ public function __construct(private readonly ConnectionInterface $connection, pr } /** - * @param array $conditions - * @param array $sorting + * @param list $conditions + * @param list $sorting * * @throws OrmException * @@ -83,6 +83,12 @@ public function getCount(string $targetClass, array $conditions): int return (int) $row['cnt']; } + /** + * @param list $conditions + * @param list $sorting + * + * @return array{string, list} + */ private function getQuery(string $targetClass, array $conditions = [], array $sorting = []): array { $from = $this->queryBuilder->buildFrom($targetClass); @@ -243,6 +249,13 @@ public function delete(EntityInterface $entity): void $this->connection->transactionCommit(); } + /** + * @param list $config + * + * @throws OrmException + * + * @return array{DoctrineCollection,string,string,string,list} + */ private function getRelation(EntityInterface $entity, array $config): array { [$type, $class, $setter, $getter, $relationTable, $sourceColumn, $targetColumn, $types] = $config; @@ -260,6 +273,9 @@ private function getRelation(EntityInterface $entity, array $config): array return [$value, $relationTable, $sourceColumn, $targetColumn, $types]; } + /** + * @param list,string,string,string,list}> $relations + */ private function handleRelations(EntityInterface $entity, array $relations): void { $sourcePrimaryId = $this->entityMeta->getPrimaryId($entity); @@ -270,7 +286,7 @@ private function handleRelations(EntityInterface $entity, array $relations): voi $this->connection->delete($relationTable, [$sourceColumn => $sourcePrimaryId]); foreach ($collection as $relationEntity) { $relationEntityId = $this->entityMeta->getPrimaryId($relationEntity); - if ($relationEntityId === null || $relationEntityId === '' || $relationEntityId === '0') { + if (in_array($relationEntityId, [null, '', '0'], true)) { $relationEntityId = $this->insert($relationEntity); } diff --git a/src/EntityMeta.php b/src/EntityMeta.php index 11ac3ba..b9a3797 100644 --- a/src/EntityMeta.php +++ b/src/EntityMeta.php @@ -28,6 +28,11 @@ public function __construct(private readonly CacheInterface $cache) { } + /** + * @param class-string $entityClass + * + * @return array + */ public function getProperties(string $entityClass): array { $cacheKey = 'entity-meta-properties-' . str_replace('\\', '-', $entityClass); @@ -72,6 +77,11 @@ public function getPrimaryId(EntityInterface $entity): ?string return null; } + /** + * @param class-string $entityClass + * + * @return array + */ public function getTableNames(string $entityClass): array { $cacheKey = 'entity-meta-table-names-' . str_replace('\\', '-', $entityClass); @@ -85,6 +95,11 @@ public function getTableNames(string $entityClass): array return $types; } + /** + * @param class-string $entityClass + * + * @return array + */ private function getTableNamesFromEntity(string $entityClass): array { $class = new ReflectionClass($entityClass); @@ -107,6 +122,16 @@ private function getTableNamesFromEntity(string $entityClass): array return $result; } + /** + * @param class-string $entityClass + * + * @return array + */ private function getTypesFromEntity(string $entityClass): array { $class = new ReflectionClass($entityClass); @@ -166,6 +191,9 @@ private function findTableColumnAttribute(ReflectionProperty $property): ?TableC return null; } + /** + * @param ReflectionClass $class + */ private function findTableNameAttribute(ReflectionClass $class): ?TableName { foreach ($class->getAttributes() as $attribute) { @@ -210,6 +238,9 @@ private function getTypeHintForProperty(ReflectionProperty $property): ?string return $type->getName(); } + /** + * @param ReflectionClass $class + */ private function getSetter(ReflectionClass $class, string $propertyName): ?string { $setter = null; @@ -238,6 +269,9 @@ private function getSetter(ReflectionClass $class, string $propertyName): ?strin return $setter; } + /** + * @param ReflectionClass $class + */ private function getGetter(ReflectionClass $class, string $propertyName): ?string { $getter = null; diff --git a/src/FieldMapper.php b/src/FieldMapper.php index 2c21d78..7aa918f 100644 --- a/src/FieldMapper.php +++ b/src/FieldMapper.php @@ -22,6 +22,9 @@ public function __construct( $this->queryBuilder = new QueryBuilder($this->connection, $this->entityMeta); } + /** + * @param array $row + */ public function map(EntityInterface $entity, array $row): void { $sourcePrimaryColumn = $this->entityMeta->getPrimaryColumn($entity::class); diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index f6a5d64..216357b 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -12,6 +12,9 @@ */ class QueryBuilder { + /** + * @var list + */ private array $blockedTableAlias = ['user']; public function __construct( diff --git a/src/SchemaManager.php b/src/SchemaManager.php index 2a69086..2f6d95d 100644 --- a/src/SchemaManager.php +++ b/src/SchemaManager.php @@ -33,6 +33,13 @@ public function createTable(string $entityClass): void } } + /** + * @param class-string $entityClass + * @param list $keys + * @param array $relationTables + * + * @return array> + */ private function getFieldsForEntity(string $entityClass, array &$keys, array &$relationTables): array { $properties = $this->entityMeta->getProperties($entityClass); diff --git a/tests/Condition/CompositeConditionTest.php b/tests/Condition/CompositeConditionTest.php index 1ed1ca9..5e0f100 100644 --- a/tests/Condition/CompositeConditionTest.php +++ b/tests/Condition/CompositeConditionTest.php @@ -25,6 +25,9 @@ public function testSingleCondition(): void self::assertSame(['bar'], $condition->getParams()); } + /** + * @return iterable + */ public static function multipleConditionsProvider(): iterable { foreach (Conjunction::cases() as $conjunction) { diff --git a/tests/FieldMapper/TestModel.php b/tests/FieldMapper/TestModel.php index 398b9f1..b9861cf 100644 --- a/tests/FieldMapper/TestModel.php +++ b/tests/FieldMapper/TestModel.php @@ -29,6 +29,9 @@ class TestModel extends TestParent #[TableColumn('purchasing_relevance', DataType::INT)] private ?int $purchasingRelevance = 0; + /** + * @var Collection|null + */ #[OneToMany('agp_contracts_con2foo', 'contract_id', 'system_id', [TestParent::class])] private ?Collection $relations = null; @@ -82,11 +85,17 @@ public function setPurchasingRelevance(?int $purchasingRelevance): void $this->purchasingRelevance = $purchasingRelevance; } + /** + * @return Collection|null + */ public function getRelations(): ?Collection { return $this->relations; } + /** + * @param Collection|null $relations + */ public function setRelations(?Collection $relations): void { $this->relations = $relations; diff --git a/tests/FieldMapper/TestModelWithTooLongRelation.php b/tests/FieldMapper/TestModelWithTooLongRelation.php index 3ca1053..69d1382 100644 --- a/tests/FieldMapper/TestModelWithTooLongRelation.php +++ b/tests/FieldMapper/TestModelWithTooLongRelation.php @@ -16,6 +16,9 @@ class TestModelWithTooLongRelation implements EntityInterface #[TablePrimary('my_id')] private string $myId; + /** + * @var Collection|null + */ #[OneToMany('some_really_long__relation_name', 'contract_id', 'system_id', [TestParent::class])] private ?Collection $relations = null; @@ -29,11 +32,17 @@ public function setMyId(string $myId): void $this->myId = $myId; } + /** + * @return Collection|null + */ public function getRelations(): ?Collection { return $this->relations; } + /** + * @param Collection|null $relations + */ public function setRelations(?Collection $relations): void { $this->relations = $relations; diff --git a/tests/FieldMapperTest.php b/tests/FieldMapperTest.php index 5847532..b2f2960 100644 --- a/tests/FieldMapperTest.php +++ b/tests/FieldMapperTest.php @@ -8,6 +8,7 @@ use Artemeon\Orm\Converter; use Artemeon\Orm\EntityInterface; use Artemeon\Orm\EntityMeta; +use Artemeon\Orm\Exception\OrmException; use Artemeon\Orm\FieldMapper; use Artemeon\Orm\Tests\FieldMapper\TestModel; use PHPUnit\Framework\Attributes\DataProvider; @@ -20,6 +21,12 @@ */ class FieldMapperTest extends TestCase { + /** + * @param array $row + * @param array $expects + * + * @throws OrmException + */ #[DataProvider('mapDataProvider')] public static function testMap(EntityInterface $entity, array $row, array $expects): void { @@ -32,6 +39,13 @@ public static function testMap(EntityInterface $entity, array $row, array $expec } } + /** + * @return array{ + * object, + * array, + * array, + * }[] + */ public static function mapDataProvider(): array { return [