Skip to content

Commit

Permalink
#11 cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhoelzel committed Mar 26, 2024
1 parent 1e78f64 commit e23a80e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 34 deletions.
10 changes: 3 additions & 7 deletions src/Component/ComponentItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Component/Data/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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];
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/Component/Data/FixtureData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class FixtureData
public function __construct(
public readonly string $className,
/** @param array<string, Type> $properties */
public readonly array $properties,
public readonly array $params = []
public readonly array $properties,
public readonly array $params = []
) {
}
}
11 changes: 5 additions & 6 deletions tests/Functional/Service/ComponentItemFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -142,18 +141,18 @@ public function testCreateForObjectParameter(): void
'path' => 'path',
'renderPath' => 'renderPath',
'parameters' => [
'car' => Car::class
'car' => Car::class,
],
'variations' => [
'fuchsia' => [
'car' => [
'color' => 'fuchsia',
'manufacturer' => [
'name' => 'Mitsubishi',
]
]
]
]
],
],
],
],
];

/** @var ComponentItemFactory $factory */
Expand Down
7 changes: 4 additions & 3 deletions tests/TestApp/Entity/Car.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/TestApp/Entity/Manufacturer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Component/Data/FakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function testGetFakeDataWithoutVariationData(): void
'someDouble' => 'Double',
'someResource' => 'Resource',
'someNull' => 'null',
]
]
],
],
];

$faker = new Faker();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e23a80e

Please sign in to comment.