From 733006653b91b4d89d68aa15124f32459a709de1 Mon Sep 17 00:00:00 2001 From: Christian Krzeminski Date: Thu, 20 Jun 2024 08:31:20 +0200 Subject: [PATCH] refactor: code style --- Classes/Command/AbstractCommand.php | 8 +++----- .../Domain/Repository/FeatureFlagRepository.php | 8 +++----- Classes/Service/FeatureFlagService.php | 15 +++------------ Classes/System/Typo3/Configuration.php | 2 +- Classes/System/Typo3/TcaPostProcessor.php | 2 +- .../Repository/FeatureFlagRepositoryTest.php | 1 - Tests/Unit/Command/AbstractCommandTestCase.php | 4 ++-- Tests/Unit/Domain/Model/FeatureFlagTest.php | 4 ++-- Tests/Unit/Domain/Model/MappingTest.php | 12 ++++++------ 9 files changed, 21 insertions(+), 35 deletions(-) diff --git a/Classes/Command/AbstractCommand.php b/Classes/Command/AbstractCommand.php index 5c00869..9974a6e 100644 --- a/Classes/Command/AbstractCommand.php +++ b/Classes/Command/AbstractCommand.php @@ -32,14 +32,12 @@ abstract class AbstractCommand extends Command { - protected FeatureFlagService $featureFlagService; - protected SymfonyStyle $inputOutput; - public function __construct(FeatureFlagService $featureFlagService) - { + public function __construct( + protected FeatureFlagService $featureFlagService + ) { parent::__construct(); - $this->featureFlagService = $featureFlagService; } /** diff --git a/Classes/Domain/Repository/FeatureFlagRepository.php b/Classes/Domain/Repository/FeatureFlagRepository.php index 54a0379..ff86295 100644 --- a/Classes/Domain/Repository/FeatureFlagRepository.php +++ b/Classes/Domain/Repository/FeatureFlagRepository.php @@ -34,11 +34,9 @@ class FeatureFlagRepository extends Repository { - private FeatureFlagData $featureFlagData; - - public function __construct(FeatureFlagData $featureFlagData) - { - $this->featureFlagData = $featureFlagData; + public function __construct( + private readonly FeatureFlagData $featureFlagData + ) { parent::__construct(); } diff --git a/Classes/Service/FeatureFlagService.php b/Classes/Service/FeatureFlagService.php index 363c076..331c2f1 100644 --- a/Classes/Service/FeatureFlagService.php +++ b/Classes/Service/FeatureFlagService.php @@ -44,22 +44,13 @@ class FeatureFlagService */ public const BEHAVIOR_SHOW = 1; - private FeatureFlagRepository $featureFlagRepository; - - private PersistenceManagerInterface $persistenceManager; - - private Configuration $configuration; - private array $cachedFlags = []; public function __construct( - FeatureFlagRepository $featureFlagRepository, - PersistenceManagerInterface $persistenceManager, - Configuration $configuration + private readonly FeatureFlagRepository $featureFlagRepository, + private readonly PersistenceManagerInterface $persistenceManager, + private readonly Configuration $configuration ) { - $this->featureFlagRepository = $featureFlagRepository; - $this->persistenceManager = $persistenceManager; - $this->configuration = $configuration; } public function isFeatureEnabled(string $flag): bool diff --git a/Classes/System/Typo3/Configuration.php b/Classes/System/Typo3/Configuration.php index 5b99008..6449f8e 100644 --- a/Classes/System/Typo3/Configuration.php +++ b/Classes/System/Typo3/Configuration.php @@ -49,7 +49,7 @@ public function __construct(ExtensionConfiguration $extensionConfiguration) public function getTables(): array { - return explode(',', $this->get(self::CONF_TABLES)); + return explode(',', (string) $this->get(self::CONF_TABLES)); } /** diff --git a/Classes/System/Typo3/TcaPostProcessor.php b/Classes/System/Typo3/TcaPostProcessor.php index af3b7e7..eac2835 100644 --- a/Classes/System/Typo3/TcaPostProcessor.php +++ b/Classes/System/Typo3/TcaPostProcessor.php @@ -87,7 +87,7 @@ private function getTcaTablesWithFeatureFlagSupport(): array $config = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('feature_flag'); if (isset($config['tables'])) { - return explode(',', $config['tables']); + return explode(',', (string) $config['tables']); } return []; diff --git a/Tests/Functional/Domain/Repository/FeatureFlagRepositoryTest.php b/Tests/Functional/Domain/Repository/FeatureFlagRepositoryTest.php index 68f2ffc..7510dea 100644 --- a/Tests/Functional/Domain/Repository/FeatureFlagRepositoryTest.php +++ b/Tests/Functional/Domain/Repository/FeatureFlagRepositoryTest.php @@ -120,7 +120,6 @@ public function testShouldShowElementForBehaviorHideAndDisabledFeatureFlag(): vo $this->assertSame(0, $contentElements[0]['hidden']); } - public function getElementsData(string $table, int $uid): array { /** @var QueryBuilder $queryBuilder */ diff --git a/Tests/Unit/Command/AbstractCommandTestCase.php b/Tests/Unit/Command/AbstractCommandTestCase.php index f6974a0..9513c27 100644 --- a/Tests/Unit/Command/AbstractCommandTestCase.php +++ b/Tests/Unit/Command/AbstractCommandTestCase.php @@ -85,7 +85,7 @@ protected function assertThatFeaturesAreNotActivated() protected function assertThatFeaturesAreDeactivated(array $expectedFeatures) { - $this->assertEquals($expectedFeatures, $this->deactivatedFeatures); + $this->assertSame($expectedFeatures, $this->deactivatedFeatures); } /** @@ -98,7 +98,7 @@ protected function assertThatFeaturesAreNotDeactivated() protected function assertThatInfosAreShown(array $expectedInfos) { - $this->assertEquals($expectedInfos, $this->shownInfos); + $this->assertSame($expectedInfos, $this->shownInfos); } protected function runCommand(string $commandClass, string $commaSeparatedListOfFeatures = '') diff --git a/Tests/Unit/Domain/Model/FeatureFlagTest.php b/Tests/Unit/Domain/Model/FeatureFlagTest.php index cc34aba..28ae636 100644 --- a/Tests/Unit/Domain/Model/FeatureFlagTest.php +++ b/Tests/Unit/Domain/Model/FeatureFlagTest.php @@ -59,7 +59,7 @@ public function testCheckProperties(): void $this->featureFlag->setEnabled(true); $this->featureFlag->setFlag('my_new_feature_flag'); $this->assertTrue($this->featureFlag->isEnabled()); - $this->assertEquals($this->featureFlag->getDescription(), 'This is a test description'); - $this->assertEquals($this->featureFlag->getFlag(), 'my_new_feature_flag'); + $this->assertSame('This is a test description', $this->featureFlag->getDescription()); + $this->assertSame('my_new_feature_flag', $this->featureFlag->getFlag()); } } diff --git a/Tests/Unit/Domain/Model/MappingTest.php b/Tests/Unit/Domain/Model/MappingTest.php index d417e99..1591f19 100644 --- a/Tests/Unit/Domain/Model/MappingTest.php +++ b/Tests/Unit/Domain/Model/MappingTest.php @@ -57,13 +57,13 @@ protected function tearDown(): void public function testTstamp(): void { $this->mapping->setTstamp(2183466346); - $this->assertEquals(2183466346, $this->mapping->getTstamp()); + $this->assertSame('2183466346', $this->mapping->getTstamp()); } public function testCrdate(): void { $this->mapping->setCrdate(2183466347); - $this->assertEquals(2183466347, $this->mapping->getCrdate()); + $this->assertSame('2183466347', $this->mapping->getCrdate()); } public function testFeatureFlag(): void @@ -72,25 +72,25 @@ public function testFeatureFlag(): void $featureFlag->method('getFlag') ->willReturn('my_awesome_feature_flag'); $this->mapping->setFeatureFlag($featureFlag); - $this->assertEquals('my_awesome_feature_flag', $this->mapping->getFeatureFlag()->getFlag()); + $this->assertSame('my_awesome_feature_flag', $this->mapping->getFeatureFlag()->getFlag()); } public function testForeignTableColumn(): void { $this->mapping->setForeignTableColumn('my_foreign_column'); - $this->assertEquals('my_foreign_column', $this->mapping->getForeignTableColumn()); + $this->assertSame('my_foreign_column', $this->mapping->getForeignTableColumn()); } public function testForeignTableName(): void { $this->mapping->setForeignTableName('my_foreign_table'); - $this->assertEquals('my_foreign_table', $this->mapping->getForeignTableName()); + $this->assertSame('my_foreign_table', $this->mapping->getForeignTableName()); } public function testForeignTableUid(): void { $this->mapping->setForeignTableUid(4711); - $this->assertEquals(4711, $this->mapping->getForeignTableUid()); + $this->assertSame(4711, $this->mapping->getForeignTableUid()); } public function testBehavior(): void