Skip to content

Commit

Permalink
bot: fix cs [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil authored and kbond committed Dec 21, 2024
1 parent 9948d6a commit 9810cbb
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 63 deletions.
14 changes: 11 additions & 3 deletions src/Attribute/WithStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Attribute;

use Zenstruck\Foundry\Story;
Expand All @@ -11,9 +20,8 @@ final class WithStory
{
public function __construct(
/** @var class-string<Story> $story */
public readonly string $story
)
{
public readonly string $story,
) {
if (!\is_subclass_of($story, Story::class)) {
throw new \InvalidArgumentException(\sprintf('"%s" is not a valid story class.', $story));
}
Expand Down
24 changes: 10 additions & 14 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,22 @@
*/
abstract class Factory
{
/** @phpstan-var Attributes[] */
private array $attributes;

/**
* Memoization of normalized parameters
* Memoization of normalized parameters.
*
* @internal
* @var Parameters|null
*/
protected array|null $normalizedParameters = null;
protected ?array $normalizedParameters = null;
/** @phpstan-var Attributes[] */
private array $attributes;

// keep an empty constructor for BC
public function __construct()
{
}

/**
* @return static
* @phpstan-return static
* @phpstan-param Attributes $attributes
*/
Expand Down Expand Up @@ -161,8 +159,6 @@ final protected static function faker(): Faker\Generator

/**
* Override to adjust default attributes & config.
*
* @return static
*/
protected function initialize(): static
{
Expand Down Expand Up @@ -212,9 +208,9 @@ protected function initializeInternal(): static
*/
protected function normalizeParameters(array $parameters): array
{
return $this->normalizedParameters = array_combine(
array_keys($parameters),
\array_map($this->normalizeParameter(...), array_keys($parameters), $parameters)
return $this->normalizedParameters = \array_combine(
\array_keys($parameters),
\array_map($this->normalizeParameter(...), \array_keys($parameters), $parameters)
);
}

Expand All @@ -240,9 +236,9 @@ protected function normalizeParameter(string $field, mixed $value): mixed
}

if (\is_array($value)) {
return array_combine(
array_keys($value),
\array_map($this->normalizeParameter(...), array_fill(0, count($value), $field), $value)
return \array_combine(
\array_keys($value),
\array_map($this->normalizeParameter(...), \array_fill(0, \count($value), $field), $value)
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/FactoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function __construct(public readonly Factory $factory, private \Closure
*/
public static function accepts(mixed $potentialFactories): bool
{
if (!is_array($potentialFactories) || count($potentialFactories) === 0 || !array_is_list($potentialFactories)) {
if (!\is_array($potentialFactories) || 0 === \count($potentialFactories) || !\array_is_list($potentialFactories)) {
return false;
}

Expand All @@ -47,7 +47,7 @@ public static function accepts(mixed $potentialFactories): bool

foreach ($potentialFactories as $potentialFactory) {
if (!$potentialFactory instanceof ObjectFactory
|| $potentialFactory::class() !== $potentialFactories[0]::class()) {
|| $potentialFactories[0]::class() !== $potentialFactory::class()) {
return false;
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function range(Factory $factory, int $min, int $max): self
}

/**
* @param TFactory $factory
* @param TFactory $factory
* @phpstan-param iterable<Attributes> $items
* @return self<T, TFactory>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/LazyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function memoize(callable $factory): self
}

/**
* @param array<array-key, mixed> $value
* @param array<array-key, mixed> $value
* @return array<array-key, mixed>
*/
private static function normalizeArray(array $value): array
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/Factory/MakeFactoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function addEnumDefaultProperty(string $propertyName, string $enumClass):
throw new \LogicException('Cannot add enum for php version inferior than 8.1');
}

if (!enum_exists($enumClass)) {
if (!\enum_exists($enumClass)) {
throw new \InvalidArgumentException("Enum of class \"{$enumClass}\" does not exist.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/Maker/Factory/ObjectDefaultPropertiesGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(SymfonyStyle $io, MakeFactoryData $makeFactoryData, Mak

$value = \sprintf('null, // TODO add %svalue manually', $type ? "{$type} " : '');

if (\PHP_VERSION_ID >= 80100 && enum_exists($type)) {
if (\PHP_VERSION_ID >= 80100 && \enum_exists($type)) {
$makeFactoryData->addEnumDefaultProperty($property->getName(), $type);

continue;
Expand Down
12 changes: 10 additions & 2 deletions src/ORM/ResetDatabase/BaseOrmResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\ORM\ResetDatabase;

use Doctrine\Bundle\DoctrineBundle\Registry;
Expand All @@ -11,7 +20,6 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;

use Zenstruck\Foundry\ORM\DoctrineOrmVersionGuesser;

use function Zenstruck\Foundry\runCommand;
Expand Down Expand Up @@ -61,7 +69,7 @@ final protected function dropAndResetDatabase(Application $application): void

$dbPath = $connection->getParams()['path'] ?? null;
if (DoctrineOrmVersionGuesser::isOrmV3() && $dbPath && (new Filesystem())->exists($dbPath)) {
file_put_contents($dbPath, '');
\file_put_contents($dbPath, '');
}

continue;
Expand Down
15 changes: 11 additions & 4 deletions src/ORM/ResetDatabase/MigrateDatabaseResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\ORM\ResetDatabase;

use Doctrine\Bundle\DoctrineBundle\Registry;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\HttpKernel\KernelInterface;

use function Zenstruck\Foundry\application;
Expand All @@ -25,12 +33,11 @@ public function __construct(
Registry $registry,
array $managers,
array $connections,
)
{
) {
parent::__construct($registry, $managers, $connections);
}

final public function resetBeforeFirstTest(KernelInterface $kernel): void
public function resetBeforeFirstTest(KernelInterface $kernel): void
{
$this->resetWithMigration($kernel);
}
Expand Down
9 changes: 9 additions & 0 deletions src/ORM/ResetDatabase/ResetDatabaseMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\ORM\ResetDatabase;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/PersistenceStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function inversedRelationshipMetadata(string $parent, string $child, stri

/**
* @template T of object
* @param class-string<T> $class
* @param class-string<T> $class
* @return ClassMetadata<T>
*
* @throws MappingException If $class is not managed by Doctrine
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/RepositoryDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function lastOrFail(string $sortBy = 'id'): object
*/
public function find($id): ?object
{
if (\is_array($id) && (empty($id) || !array_is_list($id))) {
if (\is_array($id) && (empty($id) || !\array_is_list($id))) {
/** @var T|null $object */
$object = $this->findOneBy($id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Tests\Fixture\DoctrineCascadeRelationship;

/**
Expand All @@ -16,6 +25,11 @@ private function __construct(
) {
}

public function __toString(): string
{
return \sprintf('%s::$%s - %s', $this->class, $this->field, $this->cascade ? 'cascade' : 'no cascade');
}

/**
* @param array{class: class-string, field: string} $source
*/
Expand All @@ -24,34 +38,29 @@ public static function fromArray(array $source, bool $cascade = false): self
return new self(class: $source['class'], field: $source['field'], cascade: $cascade);
}

public function __toString(): string
{
return \sprintf('%s::$%s - %s', $this->class, $this->field, $this->cascade ? 'cascade' : 'no cascade');
}

/**
* @param list<array{class: class-string, field: string}> $relationshipFields
* @param list<array{class: class-string, field: string}> $relationshipFields
* @return \Generator<list<static>>
*/
public static function allCombinations(array $relationshipFields): iterable
{
// prevent too long test suite permutation when Dama is disabled
if (!\getenv('USE_DAMA_DOCTRINE_TEST_BUNDLE')) {
$metadata = DoctrineCascadeRelationshipMetadata::fromArray($relationshipFields[0]);
$metadata = self::fromArray($relationshipFields[0]);

yield "{$metadata}\n" => [$metadata];

return;
}

$total = pow(2, count($relationshipFields));
$total = 2 ** \count($relationshipFields);

for ($i = 0; $i < $total; $i++) {
for ($i = 0; $i < $total; ++$i) {
$temp = [];

$permutationName = "\n";
for ($j = 0; $j < count($relationshipFields); $j++) {
$metadata = DoctrineCascadeRelationshipMetadata::fromArray($relationshipFields[$j], cascade: (bool)(($i >> $j) & 1));
for ($j = 0; $j < \count($relationshipFields); ++$j) {
$metadata = self::fromArray($relationshipFields[$j], cascade: (bool) (($i >> $j) & 1));

$temp[] = $metadata;
$permutationName = "{$permutationName}$metadata\n";
Expand Down
14 changes: 11 additions & 3 deletions tests/Fixture/DoctrineCascadeRelationship/UsingRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

declare(strict_types=1);

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Tests\Fixture\DoctrineCascadeRelationship;

/**
Expand All @@ -13,8 +22,7 @@ final class UsingRelationships
public function __construct(
/** @var class-string */
public readonly string $class,
public readonly array $relationShips
)
{
public readonly array $relationShips,
) {
}
}
3 changes: 1 addition & 2 deletions tests/Fixture/Document/DocumentWithReadonly.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function __construct(

#[MongoDB\Field()]
public readonly \DateTimeImmutable $date,
)
{
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function __construct(

#[ORM\Column()]
public readonly \DateTimeImmutable $date,
)
{
) {
}
}
14 changes: 11 additions & 3 deletions tests/Fixture/ObjectWithEnum.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

/*
* This file is part of the zenstruck/foundry package.
*
* (c) Kevin Bond <kevinbond@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zenstruck\Foundry\Tests\Fixture;

final class ObjectWithEnum
{
public function __construct(
public readonly SomeEnum $someEnum
)
{
public readonly SomeEnum $someEnum,
) {
}
}
Loading

0 comments on commit 9810cbb

Please sign in to comment.