Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: 2.x
ref: 3.x
fetch-depth: 1

- name: Install dependencies
Expand All @@ -71,7 +71,7 @@ jobs:
bin/tools/phpbench/vendor/phpbench/phpbench/bin/phpbench run \
tests/Benchmark \
--report=aggregate \
--tag=2.x \
--tag=3.x \
--iterations=5 \
--progress=plain \
--retry-threshold=10
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
bin/tools/phpbench/vendor/phpbench/phpbench/bin/phpbench run \
tests/Benchmark \
--report=aggregate \
--ref=2.x \
--ref=3.x \
--iterations=5 \
--progress=plain \
--retry-threshold=10 \
Expand Down
1 change: 0 additions & 1 deletion config/makers.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
->set('.zenstruck_foundry.maker.factory.generator', FactoryGenerator::class)
->args([
service('.zenstruck_foundry.persistence_manager')->nullOnInvalid(),
service('kernel'),
tagged_iterator('foundry.make_factory.default_properties_guesser'),
service('.zenstruck_foundry.maker.factory.factory_class_map'),
service('.zenstruck_foundry.maker.namespace_guesser'),
Expand Down
2 changes: 0 additions & 2 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
->set('.zenstruck_foundry.faker.adapter', FakerAdapter::class)
->args([
service('.zenstruck_foundry.faker'),
param('zenstruck_foundry.faker.seed'),
env('default::int:FOUNDRY_FAKER_SEED'),
param('zenstruck_foundry.faker.manage_seed'),
])
Expand All @@ -50,7 +49,6 @@
service('.zenstruck_foundry.instantiator'),
service('.zenstruck_foundry.story_registry'),
service('.zenstruck_foundry.persistence_manager')->nullOnInvalid(),
param('zenstruck_foundry.persistence.flush_once'),
service('.zenstruck_foundry.in_memory.repository_registry'),
service('.foundry.persistence.objects_tracker')->nullOnInvalid(),
param('zenstruck_foundry.enable_auto_refresh_with_lazy_objects'),
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ parameters:
- identifier: missingType.generics
path: src/Maker/Factory/

# not relevant for factories generated by maker
- identifier: missingType.callable
path: tests/Fixture/Maker/expected/

# not relevant for files outside from Foundry's namespace
- identifier: classConstant.internalClass
path: config/
Expand Down
14 changes: 0 additions & 14 deletions skeleton/Factory.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@

/**
* @extends <?php echo $makeFactoryData->getFactoryClassShortName(); ?><<?php echo $makeFactoryData->getObjectShortName(); ?>>
<?php
if (count($makeFactoryData->getMethodsPHPDoc())) {
echo " *\n";
foreach ($makeFactoryData->getMethodsPHPDoc() as $methodPHPDoc) {
echo "{$methodPHPDoc->toString()}\n";
}

echo " *\n";

foreach ($makeFactoryData->getMethodsPHPDoc() as $methodPHPDoc) {
echo "{$methodPHPDoc->toString($makeFactoryData->staticAnalysisTool())}\n";
}
}
?>
*/
final class <?php echo $class_name; ?> extends <?php echo $makeFactoryData->getFactoryClassShortName(); ?>
{
Expand Down
1 change: 0 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function __construct(
callable $instantiator,
public readonly StoryRegistry $stories,
private readonly ?PersistenceManager $persistence = null,
public readonly bool $flushOnce = false,
public readonly ?InMemoryRepositoryRegistry $inMemoryRepositoryRegistry = null,
public readonly ?PersistedObjectsTracker $persistedObjectsTracker = null,
private readonly bool $enableAutoRefreshWithLazyObjects = false,
Expand Down
2 changes: 1 addition & 1 deletion src/FactoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function create(array|callable $attributes = []): array
{
$factories = $this->all();

if (Configuration::instance()->flushOnce && $this->isRootFactory && $this->factory instanceof PersistentObjectFactory && $this->factory->isPersisting()) {
if ($this->isRootFactory && $this->factory instanceof PersistentObjectFactory && $this->factory->isPersisting()) {
$lastFactory = \array_pop($factories);
// @phpstan-ignore method.notFound (phpstan does not understand that we only have persistent factories here)
$factories = \array_map(static fn(Factory $f) => $f->notRootFactory(), $factories);
Expand Down
5 changes: 1 addition & 4 deletions src/FakerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
final class FakerAdapter
{
private static ?int $fakerSeed = null;
private ?int $forcedFakerSeed;

private static bool $fakerSeedHasBeenSet = false;

public function __construct(
private readonly Faker\Generator $faker,
?int $forcedFakerSeedFromConfig = null,
?int $forcedFakerSeedFromEnv = null,
private ?int $forcedFakerSeed = null,
private bool $manageFakerSeed = true,
) {
$this->forcedFakerSeed = $forcedFakerSeedFromEnv ?? $forcedFakerSeedFromConfig;
}

public static function fakerSeed(): ?int
Expand Down
15 changes: 0 additions & 15 deletions src/Maker/Factory/FactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
*/
final class FactoryGenerator
{
public const PHPSTAN_PATH = '/vendor/phpstan/phpstan/phpstan';
public const PSALM_PATH = '/vendor/vimeo/psalm/psalm';

/** @param \Traversable<int, DefaultPropertiesGuesser> $defaultPropertiesGuessers */
public function __construct(
private ?PersistenceManager $persistenceManager,
private KernelInterface $kernel,
private \Traversable $defaultPropertiesGuessers,
private FactoryClassMap $factoryClassMap,
private NamespaceGuesser $namespaceGuesser,
Expand Down Expand Up @@ -148,20 +144,9 @@ private function createMakeFactoryData(Generator $generator, string $class, Make
$object,
$factory,
$repository ?? null,
$this->staticAnalysisTool(),
$persisted ?? false,
$makeFactoryQuery->addPhpDoc(),
$this->forceProperties,
$makeFactoryQuery->shouldAddHints(),
);
}

private function staticAnalysisTool(): string
{
return match (true) {
\file_exists($this->kernel->getProjectDir().self::PHPSTAN_PATH) => MakeFactoryData::STATIC_ANALYSIS_TOOL_PHPSTAN,
\file_exists($this->kernel->getProjectDir().self::PSALM_PATH) => MakeFactoryData::STATIC_ANALYSIS_TOOL_PSALM,
default => MakeFactoryData::STATIC_ANALYSIS_TOOL_NONE,
};
}
}
32 changes: 0 additions & 32 deletions src/Maker/Factory/MakeFactoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,18 @@
*/
final class MakeFactoryData
{
public const STATIC_ANALYSIS_TOOL_NONE = 'none';
public const STATIC_ANALYSIS_TOOL_PHPSTAN = 'phpstan';
public const STATIC_ANALYSIS_TOOL_PSALM = 'psalm';

private static ?ReflectionExtractor $propertyInfo = null;

/** @var list<string> */
private array $uses;
/** @var array<string, string> */
private array $defaultProperties = [];
/** @var list<MakeFactoryPHPDocMethod> */
private array $methodsInPHPDoc;

public function __construct(
private \ReflectionClass $object,
private ClassNameDetails $factoryClassNameDetails,
private ?\ReflectionClass $repository,
private string $staticAnalysisTool,
private bool $persisted,
bool $withPhpDoc,
private bool $forceProperties,
private bool $addHints,
) {
Expand All @@ -60,8 +52,6 @@ public function __construct(
$this->uses[] = \is_a($repository->getName(), DocumentRepository::class, allow_string: true) ? DocumentRepository::class : EntityRepository::class;
}
}

$this->methodsInPHPDoc = $withPhpDoc ? MakeFactoryPHPDocMethod::createAll($this) : [];
}

// @phpstan-ignore-next-line
Expand Down Expand Up @@ -109,16 +99,6 @@ public function isPersisted(): bool
return $this->persisted;
}

public function staticAnalysisTool(): string
{
// if none was detected, let's fallback on phpstan: both psalm and phpstan can read `@phpstan` annotations
if (self::STATIC_ANALYSIS_TOOL_NONE === $this->staticAnalysisTool) {
return self::STATIC_ANALYSIS_TOOL_PHPSTAN;
}

return $this->staticAnalysisTool;
}

/** @param class-string $use */
public function addUse(string $use): void
{
Expand Down Expand Up @@ -175,18 +155,6 @@ public function getDefaultProperties(): array
return $defaultProperties;
}

/** @return list<MakeFactoryPHPDocMethod> */
public function getMethodsPHPDoc(): array
{
$methodsInPHPDoc = $this->methodsInPHPDoc;
\usort(
$methodsInPHPDoc,
static fn(MakeFactoryPHPDocMethod $m1, MakeFactoryPHPDocMethod $m2) => $m1->sortValue() <=> $m2->sortValue(),
);

return $methodsInPHPDoc;
}

public function addEnumDefaultProperty(string $propertyName, string $enumClass): void
{
if (\PHP_VERSION_ID < 80100) {
Expand Down
93 changes: 0 additions & 93 deletions src/Maker/Factory/MakeFactoryPHPDocMethod.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Maker/Factory/MakeFactoryQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ private function __construct(
private bool $test,
private bool $persisted,
private bool $allFields,
private bool $withPhpDoc,
private string $class,
private bool $generateAllFactories,
private bool $addHints,
Expand All @@ -39,7 +38,6 @@ public static function fromInput(InputInterface $input, string $class, bool $gen
test: (bool) $input->getOption('test'),
persisted: !$input->getOption('no-persistence'),
allFields: (bool) $input->getOption('all-fields'),
withPhpDoc: (bool) $input->getOption('with-phpdoc'),
class: $class,
generateAllFactories: $generateAllFactories,
addHints: $addHints,
Expand Down Expand Up @@ -67,11 +65,6 @@ public function isAllFields(): bool
return $this->allFields;
}

public function addPhpDoc(): bool
{
return $this->withPhpDoc;
}

public function getClass(): string
{
return $this->class;
Expand Down
1 change: 0 additions & 1 deletion src/Maker/MakeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
->addOption('test', null, InputOption::VALUE_NONE, 'Create in <fg=yellow>tests/</> instead of <fg=yellow>src/</>')
->addOption('all-fields', null, InputOption::VALUE_NONE, 'Create defaults for all entity fields, not only required fields')
->addOption('no-persistence', null, InputOption::VALUE_NONE, 'Create a factory for an object not managed by Doctrine')
->addOption('with-phpdoc', null, InputOption::VALUE_NONE, 'Adds @method and @phpstan-method to the Factory (can help with autocompletion in some cases)')
;

$inputConfig->setArgumentAsNonInteractive('class');
Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/PersistentObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function create(callable|array $attributes = []): object
return $object;
}

if ($configuration->flushOnce && !$this->isRootFactory) {
if (!$this->isRootFactory) {
return $object;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Test/UnitTestConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function build(): Configuration

return new Configuration(
new FactoryRegistry([]),
new FakerAdapter($faker, forcedFakerSeedFromEnv: $_SERVER['FOUNDRY_FAKER_SEED'] ?? $_ENV['FOUNDRY_FAKER_SEED'] ?? (\getenv('FOUNDRY_FAKER_SEED') ?: null)),
new FakerAdapter($faker, forcedFakerSeed: $_SERVER['FOUNDRY_FAKER_SEED'] ?? $_ENV['FOUNDRY_FAKER_SEED'] ?? (\getenv('FOUNDRY_FAKER_SEED') ?: null)),
self::$instantiator ?? Instantiator::withConstructor(),
new StoryRegistry([]),
);
Expand Down
Loading
Loading