From fd7de15b76e4ec51efe096e0e52f0608dc62d1e6 Mon Sep 17 00:00:00 2001 From: thp Date: Thu, 17 Mar 2022 17:16:04 +0100 Subject: [PATCH 1/2] fix php 8.1 compatibility ReadOnly and add toArray method annotation --- src/Utils/AbstractBeanPropertyDescriptor.php | 2 +- src/Utils/Annotation/AnnotationParser.php | 2 +- src/Utils/Annotation/{ReadOnly.php => ReadOnlyColumn.php} | 2 +- src/Utils/BeanDescriptor.php | 2 +- src/Utils/ObjectBeanPropertyDescriptor.php | 2 +- src/Utils/ScalarBeanPropertyDescriptor.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/Utils/Annotation/{ReadOnly.php => ReadOnlyColumn.php} (92%) diff --git a/src/Utils/AbstractBeanPropertyDescriptor.php b/src/Utils/AbstractBeanPropertyDescriptor.php index 9ce1a1c7..3e58335e 100644 --- a/src/Utils/AbstractBeanPropertyDescriptor.php +++ b/src/Utils/AbstractBeanPropertyDescriptor.php @@ -4,7 +4,7 @@ namespace TheCodingMachine\TDBM\Utils; use Doctrine\DBAL\Schema\Table; -use TheCodingMachine\TDBM\Utils\Annotation\ReadOnly; +use TheCodingMachine\TDBM\Utils\Annotation\ReadOnlyColumn; use Laminas\Code\Generator\DocBlock\Tag\ParamTag; use Laminas\Code\Generator\MethodGenerator; diff --git a/src/Utils/Annotation/AnnotationParser.php b/src/Utils/Annotation/AnnotationParser.php index 2d8ff01c..94650094 100644 --- a/src/Utils/Annotation/AnnotationParser.php +++ b/src/Utils/Annotation/AnnotationParser.php @@ -43,7 +43,7 @@ public static function buildWithDefaultAnnotations(array $additionalAnnotations) 'ProtectedGetter' => ProtectedGetter::class, 'ProtectedSetter' => ProtectedSetter::class, 'ProtectedOneToMany' => ProtectedOneToMany::class, - 'ReadOnly' => ReadOnly::class, + 'ReadOnly' => ReadOnlyColumn::class, 'JsonKey' => JsonKey::class, 'JsonIgnore' => JsonIgnore::class, 'JsonInclude' => JsonInclude::class, diff --git a/src/Utils/Annotation/ReadOnly.php b/src/Utils/Annotation/ReadOnlyColumn.php similarity index 92% rename from src/Utils/Annotation/ReadOnly.php rename to src/Utils/Annotation/ReadOnlyColumn.php index cc5a8896..e4efc927 100644 --- a/src/Utils/Annotation/ReadOnly.php +++ b/src/Utils/Annotation/ReadOnlyColumn.php @@ -10,6 +10,6 @@ * * @Annotation */ -final class ReadOnly +final class ReadOnlyColumn { } diff --git a/src/Utils/BeanDescriptor.php b/src/Utils/BeanDescriptor.php index 0fc93070..8fa5fc2f 100644 --- a/src/Utils/BeanDescriptor.php +++ b/src/Utils/BeanDescriptor.php @@ -1198,7 +1198,7 @@ public function generateResultIteratorPhpCode(): ?FileGenerator $class->setDocBlock((new DocBlockGenerator( "The $baseClassName class will iterate over results of $beanClassWithoutNameSpace class.", null, - [new Tag\MethodTag('getIterator', ['\\' . $beanClassName . '[]'])] + [new Tag\MethodTag('getIterator', ['\\' . $beanClassName . '[]']), new Tag\MethodTag('toArray', ['\\' . $beanClassName . '[]'])] ))->setWordWrap(false)); $file = $this->codeGeneratorListener->onBaseResultIteratorGenerated($file, $this, $this->configuration); diff --git a/src/Utils/ObjectBeanPropertyDescriptor.php b/src/Utils/ObjectBeanPropertyDescriptor.php index 317b50a5..ce167564 100644 --- a/src/Utils/ObjectBeanPropertyDescriptor.php +++ b/src/Utils/ObjectBeanPropertyDescriptor.php @@ -345,7 +345,7 @@ private function isSetterProtected(): bool public function isReadOnly(): bool { - return $this->findAnnotation(Annotation\ReadOnly::class) !== null; + return $this->findAnnotation(Annotation\ReadOnlyColumn::class) !== null; } /** diff --git a/src/Utils/ScalarBeanPropertyDescriptor.php b/src/Utils/ScalarBeanPropertyDescriptor.php index fd276500..bc1d4e18 100644 --- a/src/Utils/ScalarBeanPropertyDescriptor.php +++ b/src/Utils/ScalarBeanPropertyDescriptor.php @@ -421,7 +421,7 @@ private function isSetterProtected(): bool public function isReadOnly(): bool { - return $this->findAnnotation(Annotation\ReadOnly::class) !== null; + return $this->findAnnotation(Annotation\ReadOnlyColumn::class) !== null; } private function findAnnotation(string $type): ?object From 8922eef91f22113159e17e070cfc87056fe6a5ab Mon Sep 17 00:00:00 2001 From: Guillaume Date: Thu, 17 Mar 2022 17:27:07 +0100 Subject: [PATCH 2/2] Cast `Statement::rowCount` return value to `int` --- src/InnerResultIterator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/InnerResultIterator.php b/src/InnerResultIterator.php index 8f5bacd9..66ed3f6d 100644 --- a/src/InnerResultIterator.php +++ b/src/InnerResultIterator.php @@ -135,7 +135,7 @@ public function count() if ($this->fetchStarted && $this->tdbmService->getConnection()->getDatabasePlatform() instanceof MySqlPlatform) { // Optimisation: we don't need a separate "count" SQL request in MySQL. assert($this->statement instanceof Statement); - $this->count = $this->statement->rowCount(); + $this->count = (int)$this->statement->rowCount(); return $this->count; } return $this->getRowCountViaSqlQuery();