From 0e0af7223b13d5cd7a3a9ed7b09030ee14a54f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Fri, 4 Mar 2022 14:01:18 +0100 Subject: [PATCH] Add property typehints, use arrow functions, remove deprecated DBAL features --- bundle/Command/MigrateCommand.php | 22 +++++------------- .../EnhancedSelectionStorage/Gateway.php | 9 -------- .../Gateway/DoctrineStorage.php | 23 ++++++------------- .../Core/FieldType/EnhancedSelection/Type.php | 2 +- .../FieldType/EnhancedSelection/Value.php | 2 +- .../FieldType/EnhancedSelectionFieldType.php | 5 +--- .../Type/FieldType/FieldValueTransformer.php | 12 +++------- bundle/Installer/BuildSchemaListener.php | 5 +--- .../Twig/NetgenEnhancedSelectionRuntime.php | 5 +--- .../EnhancedSelectionStorageTest.php | 13 ++++------- .../FieldType/EnhancedSelection/TypeTest.php | 19 ++++----------- .../FieldType/EnhancedSelection/ValueTest.php | 2 +- .../EnhancedSelectionConverterTest.php | 5 +--- .../EnhancedSelectionTest.php | 5 +--- .../NetgenEnhancedSelectionExtensionTest.php | 5 +--- .../NetgenEnhancedSelectionRuntimeTest.php | 13 ++++------- 16 files changed, 38 insertions(+), 109 deletions(-) diff --git a/bundle/Command/MigrateCommand.php b/bundle/Command/MigrateCommand.php index 4e6d30e..1abd6d1 100644 --- a/bundle/Command/MigrateCommand.php +++ b/bundle/Command/MigrateCommand.php @@ -5,8 +5,7 @@ namespace Netgen\Bundle\EnhancedSelectionBundle\Command; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\Statement; -use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\Driver\Result; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Type as EnhancedSelectionType; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -17,20 +16,11 @@ final class MigrateCommand extends Command { - /** - * @var \Doctrine\DBAL\Connection - */ - private $db; + private Connection $db; - /** - * @var string - */ - private $typeIdentifier; + private string $typeIdentifier; - /** - * @var \Symfony\Component\Console\Style\SymfonyStyle - */ - private $io; + private SymfonyStyle $io; public function __construct(Connection $db, EnhancedSelectionType $type) { @@ -56,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int $statement = $this->getFields(); $this->io->progressStart($statement->rowCount()); - while ($row = $statement->fetch(FetchMode::ASSOCIATIVE)) { + while ($row = $statement->fetchAssociative()) { if ($row['data_text'] !== null) { $fieldId = (int) $row['id']; $version = (int) $row['version']; @@ -79,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int return 0; } - private function getFields(): Statement + private function getFields(): Result { $builder = $this->db->createQueryBuilder(); $builder->select('a.id', 'a.version', 'a.data_text') diff --git a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway.php b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway.php index 526e9fd..31ef922 100644 --- a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway.php +++ b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway.php @@ -12,26 +12,17 @@ abstract class Gateway extends StorageGateway { /** * Stores the identifiers in the database based on the given field data. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\VersionInfo $versionInfo - * @param \Ibexa\Contracts\Core\Persistence\Content\Field $field */ abstract public function storeFieldData(VersionInfo $versionInfo, Field $field): void; /** * Gets the identifiers stored in the field. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\VersionInfo $versionInfo - * @param \Ibexa\Contracts\Core\Persistence\Content\Field $field */ abstract public function getFieldData(VersionInfo $versionInfo, Field $field): void; /** * Deletes field data for all $fieldIds in the version identified by * $versionInfo. - * - * @param \Ibexa\Contracts\Core\Persistence\Content\VersionInfo $versionInfo - * @param array $fieldIds */ abstract public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void; } diff --git a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php index 2a647bd..e02bb82 100644 --- a/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php +++ b/bundle/Core/FieldType/EnhancedSelection/EnhancedSelectionStorage/Gateway/DoctrineStorage.php @@ -5,7 +5,6 @@ namespace Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\EnhancedSelectionStorage\Gateway; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Types\Types; use Ibexa\Contracts\Core\Persistence\Content\Field; use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; @@ -14,10 +13,7 @@ final class DoctrineStorage extends Gateway { - /** - * @var \Doctrine\DBAL\Connection - */ - private $connection; + private Connection $connection; public function __construct(Connection $connection) { @@ -56,7 +52,7 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void $query ->delete($this->connection->quoteIdentifier('sckenhancedselection')) ->where( - $query->expr()->andX( + $query->expr()->and( $query->expr()->in('contentobject_attribute_id', [':contentobject_attribute_id']), $query->expr()->eq('contentobject_attribute_version', ':contentobject_attribute_version') ) @@ -70,19 +66,16 @@ public function deleteFieldData(VersionInfo $versionInfo, array $fieldIds): void /** * Returns the data for the given $fieldId and $versionNo. * - * @param mixed $fieldId - * @param mixed $versionNo - * - * @return array + * @return string[] */ - private function loadFieldData($fieldId, $versionNo): array + private function loadFieldData(int $fieldId, int $versionNo): array { $query = $this->connection->createQueryBuilder(); $query ->select('DISTINCT identifier') ->from($this->connection->quoteIdentifier('sckenhancedselection')) ->where( - $query->expr()->andX( + $query->expr()->and( $query->expr()->eq('contentobject_attribute_id', ':contentobject_attribute_id'), $query->expr()->eq('contentobject_attribute_version', ':contentobject_attribute_version') ) @@ -92,12 +85,10 @@ private function loadFieldData($fieldId, $versionNo): array $statement = $query->execute(); - $rows = $statement->fetchAll(FetchMode::ASSOCIATIVE); + $rows = $statement->fetchAllAssociative(); return array_map( - static function (array $row) { - return $row['identifier']; - }, + static fn (array $row): string => $row['identifier'], $rows ); } diff --git a/bundle/Core/FieldType/EnhancedSelection/Type.php b/bundle/Core/FieldType/EnhancedSelection/Type.php index 19adff2..627f1b3 100644 --- a/bundle/Core/FieldType/EnhancedSelection/Type.php +++ b/bundle/Core/FieldType/EnhancedSelection/Type.php @@ -19,7 +19,7 @@ final class Type extends FieldType { /** - * @var array + * @var array> */ protected $settingsSchema = [ 'options' => [ diff --git a/bundle/Core/FieldType/EnhancedSelection/Value.php b/bundle/Core/FieldType/EnhancedSelection/Value.php index 150721f..9b1e5e9 100644 --- a/bundle/Core/FieldType/EnhancedSelection/Value.php +++ b/bundle/Core/FieldType/EnhancedSelection/Value.php @@ -14,7 +14,7 @@ final class Value extends BaseValue * * @var string[] */ - public $identifiers = []; + public array $identifiers = []; /** * @param string[] $identifiers diff --git a/bundle/Form/Type/FieldType/EnhancedSelectionFieldType.php b/bundle/Form/Type/FieldType/EnhancedSelectionFieldType.php index b41288b..dd1d7c4 100644 --- a/bundle/Form/Type/FieldType/EnhancedSelectionFieldType.php +++ b/bundle/Form/Type/FieldType/EnhancedSelectionFieldType.php @@ -13,10 +13,7 @@ final class EnhancedSelectionFieldType extends AbstractType { - /** - * @var \Ibexa\Contracts\Core\Repository\FieldTypeService - */ - private $fieldTypeService; + private FieldTypeService $fieldTypeService; public function __construct(FieldTypeService $fieldTypeService) { diff --git a/bundle/Form/Type/FieldType/FieldValueTransformer.php b/bundle/Form/Type/FieldType/FieldValueTransformer.php index f0308ae..d09fed0 100644 --- a/bundle/Form/Type/FieldType/FieldValueTransformer.php +++ b/bundle/Form/Type/FieldType/FieldValueTransformer.php @@ -12,15 +12,9 @@ final class FieldValueTransformer implements DataTransformerInterface { - /** - * @var \Ibexa\Contracts\Core\Repository\FieldType - */ - private $fieldType; - - /** - * @var \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition - */ - private $fieldDefinition; + private FieldType $fieldType; + + private FieldDefinition $fieldDefinition; public function __construct(FieldType $fieldType, FieldDefinition $fieldDefinition) { diff --git a/bundle/Installer/BuildSchemaListener.php b/bundle/Installer/BuildSchemaListener.php index d6e8334..975f4d1 100644 --- a/bundle/Installer/BuildSchemaListener.php +++ b/bundle/Installer/BuildSchemaListener.php @@ -10,10 +10,7 @@ final class BuildSchemaListener implements EventSubscriberInterface { - /** - * @var string - */ - private $schemaPath; + private string $schemaPath; public function __construct(string $schemaPath) { diff --git a/bundle/Templating/Twig/NetgenEnhancedSelectionRuntime.php b/bundle/Templating/Twig/NetgenEnhancedSelectionRuntime.php index 9cfa814..ac2980f 100644 --- a/bundle/Templating/Twig/NetgenEnhancedSelectionRuntime.php +++ b/bundle/Templating/Twig/NetgenEnhancedSelectionRuntime.php @@ -10,10 +10,7 @@ final class NetgenEnhancedSelectionRuntime { - /** - * @var \Ibexa\Contracts\Core\Repository\ContentTypeService - */ - private $contentTypeService; + private ContentTypeService $contentTypeService; public function __construct(ContentTypeService $contentTypeService) { diff --git a/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php b/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php index bf01915..4164fa8 100644 --- a/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php +++ b/tests/Core/FieldType/EnhancedSelection/EnhancedSelectionStorageTest.php @@ -9,19 +9,14 @@ use Ibexa\Contracts\Core\Persistence\Content\VersionInfo; use Ibexa\Core\FieldType\StorageGateway; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\EnhancedSelectionStorage; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; final class EnhancedSelectionStorageTest extends TestCase { - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $gateway; - - /** - * @var EnhancedSelectionStorage - */ - private $storage; + private MockObject $gateway; + + private EnhancedSelectionStorage $storage; protected function setUp(): void { diff --git a/tests/Core/FieldType/EnhancedSelection/TypeTest.php b/tests/Core/FieldType/EnhancedSelection/TypeTest.php index 800c87b..dc3d53c 100644 --- a/tests/Core/FieldType/EnhancedSelection/TypeTest.php +++ b/tests/Core/FieldType/EnhancedSelection/TypeTest.php @@ -16,25 +16,16 @@ final class TypeTest extends TestCase { - /** - * @var Type - */ - private $type; + private Type $type; /** - * @var array + * @var string[] */ - private $identifiers = ['identifier0', 'identifier1']; + private array $identifiers = ['identifier0', 'identifier1']; - /** - * @var Value - */ - private $value; + private Value $value; - /** - * @var Value - */ - private $emptyValue; + private Value $emptyValue; protected function setUp(): void { diff --git a/tests/Core/FieldType/EnhancedSelection/ValueTest.php b/tests/Core/FieldType/EnhancedSelection/ValueTest.php index 9e14200..28f8fc1 100644 --- a/tests/Core/FieldType/EnhancedSelection/ValueTest.php +++ b/tests/Core/FieldType/EnhancedSelection/ValueTest.php @@ -10,7 +10,7 @@ final class ValueTest extends TestCase { - private $value; + private Value $value; protected function setUp(): void { diff --git a/tests/Core/Persistence/Legacy/Content/FieldValue/Converter/EnhancedSelectionConverterTest.php b/tests/Core/Persistence/Legacy/Content/FieldValue/Converter/EnhancedSelectionConverterTest.php index 1f6a276..7f2ac56 100644 --- a/tests/Core/Persistence/Legacy/Content/FieldValue/Converter/EnhancedSelectionConverterTest.php +++ b/tests/Core/Persistence/Legacy/Content/FieldValue/Converter/EnhancedSelectionConverterTest.php @@ -14,10 +14,7 @@ final class EnhancedSelectionConverterTest extends TestCase { - /** - * @var Converter - */ - private $converter; + private EnhancedSelectionConverter $converter; protected function setUp(): void { diff --git a/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php b/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php index c420143..7dd1b02 100644 --- a/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php +++ b/tests/Form/FieldTypeHandler/EnhancedSelectionTest.php @@ -13,10 +13,7 @@ final class EnhancedSelectionTest extends TestCase { - /** - * @var EnhancedSelection - */ - private $handler; + private EnhancedSelection $handler; protected function setUp(): void { diff --git a/tests/Templating/Twig/NetgenEnhancedSelectionExtensionTest.php b/tests/Templating/Twig/NetgenEnhancedSelectionExtensionTest.php index a2a12ab..20a9859 100644 --- a/tests/Templating/Twig/NetgenEnhancedSelectionExtensionTest.php +++ b/tests/Templating/Twig/NetgenEnhancedSelectionExtensionTest.php @@ -11,10 +11,7 @@ final class NetgenEnhancedSelectionExtensionTest extends TestCase { - /** - * @var NetgenEnhancedSelectionExtension - */ - private $extension; + private NetgenEnhancedSelectionExtension $extension; protected function setUp(): void { diff --git a/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php b/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php index a2068a4..e144851 100644 --- a/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php +++ b/tests/Templating/Twig/NetgenEnhancedSelectionRuntimeTest.php @@ -14,19 +14,14 @@ use Ibexa\Core\Repository\Values\ContentType\FieldDefinitionCollection; use Netgen\Bundle\EnhancedSelectionBundle\Core\FieldType\EnhancedSelection\Value; use Netgen\Bundle\EnhancedSelectionBundle\Templating\Twig\NetgenEnhancedSelectionRuntime; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; final class NetgenEnhancedSelectionRuntimeTest extends TestCase { - /** - * @var NetgenEnhancedSelectionRuntime - */ - private $runtime; - - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $contentTypeService; + private NetgenEnhancedSelectionRuntime $runtime; + + private MockObject $contentTypeService; protected function setUp(): void {