From e23a80e04c9dda1a593bff7b804580c34b00b38c Mon Sep 17 00:00:00 2001 From: david Date: Tue, 26 Mar 2024 14:16:42 +0100 Subject: [PATCH] #11 cs-fixer --- src/Component/ComponentItemFactory.php | 10 +++------- src/Component/Data/Faker.php | 18 +++++++++--------- src/Component/Data/FixtureData.php | 4 ++-- .../Service/ComponentItemFactoryTest.php | 11 +++++------ tests/TestApp/Entity/Car.php | 7 ++++--- tests/TestApp/Entity/Manufacturer.php | 2 +- tests/Unit/Component/Data/FakerTest.php | 12 ++++++------ 7 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/Component/ComponentItemFactory.php b/src/Component/ComponentItemFactory.php index cf8f64b..b167eef 100644 --- a/src/Component/ComponentItemFactory.php +++ b/src/Component/ComponentItemFactory.php @@ -103,19 +103,15 @@ private function parseVariations(?array $variations, ?array $parameters): array if (!$variations) { return [ - 'default' => $this->faker->getFakeData($parameters) + 'default' => $this->faker->getFakeData($parameters), ]; } $result = []; foreach ($variations as $variationName => $variationParams) { - if (!is_array($variationParams)) { - throw new InvalidComponentConfigurationException( - ConstraintViolationList::createFromMessage( - sprintf('A component variation must contain an array of parameters. Variation Name: %s', $variationName) - ) - ); + if (!\is_array($variationParams)) { + throw new InvalidComponentConfigurationException(ConstraintViolationList::createFromMessage(sprintf('A component variation must contain an array of parameters. Variation Name: %s', $variationName))); } $result[$variationName] = $this->faker->getFakeData($parameters, $variationParams); } diff --git a/src/Component/Data/Faker.php b/src/Component/Data/Faker.php index e0c273f..5631f04 100644 --- a/src/Component/Data/Faker.php +++ b/src/Component/Data/Faker.php @@ -10,7 +10,7 @@ use Symfony\Component\PropertyInfo\Type; /** - * Creates fake data to be used in variation display for components + * Creates fake data to be used in variation display for components. * * Provide seed in constructor to get reproducible random values */ @@ -41,7 +41,7 @@ private function collectClasses(array $params, array $variation = []): ?array { $classes = []; foreach ($params as $name => $type) { - if (is_array($type)) { + if (\is_array($type)) { $classes[$name] = $this->collectClasses($type, $variation[$name] ?? []); } elseif (class_exists($type)) { $propertyInfo = $this->getPropertyInfo($type); @@ -62,7 +62,7 @@ private function collectClasses(array $params, array $variation = []): ?array private function getFixtureParams(string $className, array $props = [], array $params = []): array { foreach ($props as $prop => $type) { - if (!array_key_exists($prop, $params) && $this->extractor->isWritable($className, $prop)) { + if (!\array_key_exists($prop, $params) && $this->extractor->isWritable($className, $prop)) { $params[$prop] = $this->createParamValue($type->getBuiltinType()); } } @@ -128,9 +128,9 @@ private function getFixture(string $fixtureSetName, FixtureData $data): object $prop => array_merge( $data->params[$prop] ?? $this->getFixtureParams($type->getClassName(), $this->getPropertyInfo($type->getClassName())), - ['__construct' => false, ] - ) - ] ; + ['__construct' => false] + ), + ]; $fixtureParams[$prop] = sprintf('@%s', $prop); } } @@ -141,7 +141,7 @@ private function getFixture(string $fixtureSetName, FixtureData $data): object // disable constructor until we have time to fake constructor arguments :-) '__construct' => false, ]), - ] + ], ]); return $this->loader->loadData($fixtureData)->getObjects()[$fixtureSetName]; @@ -153,7 +153,7 @@ public function createVariationParameters(array $parameters, array $variation): foreach ($parameters as $name => $type) { if (\is_array($type)) { $paramValue = $this->createVariationParameters($type, $variation[$name] ?? []); - } elseif (array_key_exists($name, $variation)) { + } elseif (\array_key_exists($name, $variation)) { $paramValue = $variation[$name]; } else { $paramValue = $this->createParamValue($type); @@ -189,7 +189,7 @@ private function arrayDiffKeyRecursive(array $arr1, array $arr2): array $intersect = array_intersect_key($arr1, $arr2); foreach ($intersect as $k => $v) { - if (is_array($arr1[$k]) && is_array($arr2[$k])) { + if (\is_array($arr1[$k]) && \is_array($arr2[$k])) { $d = $this->arrayDiffKeyRecursive($arr1[$k], $arr2[$k]); if ($d) { diff --git a/src/Component/Data/FixtureData.php b/src/Component/Data/FixtureData.php index f526176..b1b681c 100644 --- a/src/Component/Data/FixtureData.php +++ b/src/Component/Data/FixtureData.php @@ -12,8 +12,8 @@ class FixtureData public function __construct( public readonly string $className, /** @param array $properties */ - public readonly array $properties, - public readonly array $params = [] + public readonly array $properties, + public readonly array $params = [] ) { } } diff --git a/tests/Functional/Service/ComponentItemFactoryTest.php b/tests/Functional/Service/ComponentItemFactoryTest.php index 75d6875..d85f95d 100644 --- a/tests/Functional/Service/ComponentItemFactoryTest.php +++ b/tests/Functional/Service/ComponentItemFactoryTest.php @@ -13,7 +13,6 @@ use Qossmic\TwigDocBundle\Exception\InvalidComponentConfigurationException; use Qossmic\TwigDocBundle\Service\CategoryService; use Qossmic\TwigDocBundle\Tests\TestApp\Entity\Car; -use Qossmic\TwigDocBundle\Tests\TestApp\Entity\Manufacturer; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -142,7 +141,7 @@ public function testCreateForObjectParameter(): void 'path' => 'path', 'renderPath' => 'renderPath', 'parameters' => [ - 'car' => Car::class + 'car' => Car::class, ], 'variations' => [ 'fuchsia' => [ @@ -150,10 +149,10 @@ public function testCreateForObjectParameter(): void 'color' => 'fuchsia', 'manufacturer' => [ 'name' => 'Mitsubishi', - ] - ] - ] - ] + ], + ], + ], + ], ]; /** @var ComponentItemFactory $factory */ diff --git a/tests/TestApp/Entity/Car.php b/tests/TestApp/Entity/Car.php index c83b25c..6d9b66d 100644 --- a/tests/TestApp/Entity/Car.php +++ b/tests/TestApp/Entity/Car.php @@ -12,18 +12,19 @@ class Car public function __construct(private readonly string $blub) { - } + public function getBlub(): string { return $this->blub; } + public function getManufacturer(): ?Manufacturer { return $this->manufacturer; } - public function setManufacturer(Manufacturer $manufacturer): Car + public function setManufacturer(Manufacturer $manufacturer): self { $this->manufacturer = $manufacturer; @@ -35,7 +36,7 @@ public function getColor(): string return $this->color; } - public function setColor(string $color): Car + public function setColor(string $color): self { $this->color = $color; diff --git a/tests/TestApp/Entity/Manufacturer.php b/tests/TestApp/Entity/Manufacturer.php index a989c20..de6580f 100644 --- a/tests/TestApp/Entity/Manufacturer.php +++ b/tests/TestApp/Entity/Manufacturer.php @@ -11,7 +11,7 @@ public function getName(): string return $this->name; } - public function setName(string $name): Manufacturer + public function setName(string $name): self { $this->name = $name; diff --git a/tests/Unit/Component/Data/FakerTest.php b/tests/Unit/Component/Data/FakerTest.php index 203d2bd..ed6331b 100644 --- a/tests/Unit/Component/Data/FakerTest.php +++ b/tests/Unit/Component/Data/FakerTest.php @@ -33,8 +33,8 @@ public function testGetFakeDataWithoutVariationData(): void 'someDouble' => 'Double', 'someResource' => 'Resource', 'someNull' => 'null', - ] - ] + ], + ], ]; $faker = new Faker(); @@ -65,21 +65,21 @@ public function testGetFakeDataForVariation(): void 'text' => 'String', 'complex' => [ 'manufacturer' => Manufacturer::class, - ] + ], ]; $variation = [ 'car' => [ 'color' => 'pink', 'manufacturer' => [ 'name' => 'Toyota', - ] + ], ], 'text' => 'shouldStayAsIs', 'complex' => [ 'manufacturer' => [ 'name' => 'Mitsubishi', - ] - ] + ], + ], ]; $faker = new Faker();