Skip to content

Commit 3e23fda

Browse files
committed
refactor(maker): deprecate --with-phpdocs for PHP >=8.4 (#952)
1 parent 61cabac commit 3e23fda

13 files changed

+45
-75
lines changed

docs/index.rst

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -209,53 +209,6 @@ This command will generate a ``PostFactory`` class that looks like this:
209209
make_factory:
210210
add_hints: false
211211
212-
.. note::
213-
214-
You can add the option ``--with-phpdoc`` in order to add the following ``@method`` docblocks.
215-
This would ease autocompletion in your IDE (might be not useful anymore since Foundry v2, at least in PHPStorm):
216-
217-
::
218-
219-
/**
220-
* @method Post create(array|callable $attributes = [])
221-
* @method static Post createOne(array $attributes = [])
222-
* @method static Post find(object|array|mixed $criteria)
223-
* @method static Post findOrCreate(array $attributes)
224-
* @method static Post first(string $sortBy = 'id')
225-
* @method static Post last(string $sortBy = 'id')
226-
* @method static Post random(array $attributes = [])
227-
* @method static Post randomOrCreate(array $attributes = []))
228-
* @method static PostRepository|RepositoryProxy repository()
229-
* @method static Post[] all()
230-
* @method static Post[] createMany(int $number, array|callable $attributes = [])
231-
* @method static Post[] createSequence(iterable|callable $sequence)
232-
* @method static Post[] findBy(array $attributes)
233-
* @method static Post[] randomRange(int $min, int $max, array $attributes = []))
234-
* @method static Post[] randomRangeOrCreate(int $min, int $max, array $attributes = [])
235-
* @method static Post[] randomSet(int $number, array $attributes = []))
236-
*
237-
* @phpstan-method Post create(array|callable $attributes = [])
238-
* @phpstan-method static Post createOne(array $attributes = [])
239-
* @phpstan-method static Post find(object|array|mixed $criteria)
240-
* @phpstan-method static Post findOrCreate(array $attributes)
241-
* @phpstan-method static Post first(string $sortBy = 'id')
242-
* @phpstan-method static Post last(string $sortBy = 'id')
243-
* @phpstan-method static Post random(array $attributes = [])
244-
* @phpstan-method static Post randomOrCreate(array $attributes = [])
245-
* @phpstan-method static list<Post> all()
246-
* @phpstan-method static list<Post> createMany(int $number, array|callable $attributes = [])
247-
* @phpstan-method static list<Post> createSequence(array|callable $sequence)
248-
* @phpstan-method static list<Post> findBy(array $attributes)
249-
* @phpstan-method static list<Post> randomRange(int $min, int $max, array $attributes = [])
250-
* @phpstan-method static list<Post> randomRangeOrCreate(int $min, int $max, array $attributes = [])
251-
* @phpstan-method static list<Post> randomSet(int $number, array $attributes = [])
252-
* @phpstan-method static RepositoryDecorator<Post, ObjectRepository<Post>> repository()
253-
*/
254-
final class PostFactory extends PersistentObjectFactory
255-
{
256-
// ...
257-
}
258-
259212
.. _defaults:
260213

261214
In the ``defaults()``, you can return an array of all default values that any new object

src/Maker/Factory/MakeFactoryData.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
1818
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1919
use Zenstruck\Foundry\ObjectFactory;
20+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
2021
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
2122
use Zenstruck\Foundry\Persistence\Proxy;
2223
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
@@ -85,7 +86,9 @@ public function getObjectShortName(): string
8586
*/
8687
public function getFactoryClass(): string
8788
{
88-
return $this->isPersisted() ? PersistentProxyObjectFactory::class : ObjectFactory::class;
89+
return $this->isPersisted()
90+
? (\PHP_VERSION_ID >= 80400 ? PersistentObjectFactory::class : PersistentProxyObjectFactory::class)
91+
: ObjectFactory::class;
8992
}
9093

9194
public function getFactoryClassShortName(): string

src/Maker/MakeFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
7777

7878
public function interact(InputInterface $input, ConsoleStyle $io, Command $command): void
7979
{
80+
if ($input->getOption('with-phpdoc') && \PHP_VERSION_ID >= 80400) {
81+
trigger_deprecation(
82+
'zenstruck/foundry',
83+
'2.7',
84+
'The --with-phpdoc option is deprecated and will be removed in 3.0.',
85+
);
86+
}
87+
8088
if (!$this->doctrineEnabled() && !$input->getOption('no-persistence')) {
8189
$io->text('// Note: Doctrine not enabled: auto-activating <fg=yellow>--no-persistence</> option.');
8290
$io->newLine();

tests/Fixture/Maker/expected/can_create_factory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace App\Factory;
1313

14-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
14+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1515
use Zenstruck\Foundry\Tests\Fixture\Entity\Category;
1616

1717
/**
18-
* @extends PersistentProxyObjectFactory<Category>
18+
* @extends PersistentObjectFactory<Category>
1919
*/
20-
final class CategoryFactory extends PersistentProxyObjectFactory
20+
final class CategoryFactory extends PersistentObjectFactory
2121
{
2222
/**
2323
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

tests/Fixture/Maker/expected/can_create_factory_for_entity_with_repository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
namespace App\Factory;
1313

1414
use Doctrine\ORM\EntityRepository;
15-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
15+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1616
use Zenstruck\Foundry\Persistence\Proxy;
1717
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
1818
use Zenstruck\Foundry\Tests\Fixture\Entity\GenericEntity;
1919
use Zenstruck\Foundry\Tests\Fixture\Entity\Repository\GenericEntityRepository;
2020

2121
/**
22-
* @extends PersistentProxyObjectFactory<GenericEntity>
22+
* @extends PersistentObjectFactory<GenericEntity>
2323
*
2424
* @method GenericEntity|Proxy create(array|callable $attributes = [])
2525
* @method static GenericEntity|Proxy createOne(array $attributes = [])
@@ -55,7 +55,7 @@
5555
* @phpstan-method static list<GenericEntity&Proxy<GenericEntity>> randomRangeOrCreate(int $min, int $max, array $attributes = [])
5656
* @phpstan-method static list<GenericEntity&Proxy<GenericEntity>> randomSet(int $number, array $attributes = [])
5757
*/
58-
final class GenericEntityFactory extends PersistentProxyObjectFactory
58+
final class GenericEntityFactory extends PersistentObjectFactory
5959
{
6060
/**
6161
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

tests/Fixture/Maker/expected/can_create_factory_interactively.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace App\Factory;
1313

14-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
14+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1515
use Zenstruck\Foundry\Tests\Fixture\Entity\Contact;
1616

1717
/**
18-
* @extends PersistentProxyObjectFactory<Contact>
18+
* @extends PersistentObjectFactory<Contact>
1919
*/
20-
final class ContactFactory extends PersistentProxyObjectFactory
20+
final class ContactFactory extends PersistentObjectFactory
2121
{
2222
/**
2323
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

tests/Fixture/Maker/expected/can_create_factory_with_all_fields.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace App\Factory;
1313

14-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
14+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1515
use Zenstruck\Foundry\Tests\Fixture\Entity\GenericEntity;
1616

1717
/**
18-
* @extends PersistentProxyObjectFactory<GenericEntity>
18+
* @extends PersistentObjectFactory<GenericEntity>
1919
*/
20-
final class GenericEntityFactory extends PersistentProxyObjectFactory
20+
final class GenericEntityFactory extends PersistentObjectFactory
2121
{
2222
/**
2323
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

tests/Fixture/Maker/expected/can_create_factory_with_embeddable_with_data_set_odm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace App\Factory;
1313

14-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
14+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1515
use Zenstruck\Foundry\Tests\Fixture\Document\WithEmbeddableDocument;
1616

1717
/**
18-
* @extends PersistentProxyObjectFactory<WithEmbeddableDocument>
18+
* @extends PersistentObjectFactory<WithEmbeddableDocument>
1919
*/
20-
final class WithEmbeddableDocumentFactory extends PersistentProxyObjectFactory
20+
final class WithEmbeddableDocumentFactory extends PersistentObjectFactory
2121
{
2222
/**
2323
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

tests/Fixture/Maker/expected/can_create_factory_with_embeddable_with_data_set_orm.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
namespace App\Factory;
1313

14-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
14+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1515
use Zenstruck\Foundry\Tests\Fixture\Entity\WithEmbeddableEntity;
1616

1717
/**
18-
* @extends PersistentProxyObjectFactory<WithEmbeddableEntity>
18+
* @extends PersistentObjectFactory<WithEmbeddableEntity>
1919
*/
20-
final class WithEmbeddableEntityFactory extends PersistentProxyObjectFactory
20+
final class WithEmbeddableEntityFactory extends PersistentObjectFactory
2121
{
2222
/**
2323
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

tests/Fixture/Maker/expected/can_create_factory_with_static_analysis_annotations_with_data_set_phpstan.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
namespace App\Tests\Factory;
1313

1414
use Doctrine\ORM\EntityRepository;
15-
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
15+
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;
1616
use Zenstruck\Foundry\Persistence\Proxy;
1717
use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator;
1818
use Zenstruck\Foundry\Tests\Fixture\Entity\Category;
1919

2020
/**
21-
* @extends PersistentProxyObjectFactory<Category>
21+
* @extends PersistentObjectFactory<Category>
2222
*
2323
* @method Category|Proxy create(array|callable $attributes = [])
2424
* @method static Category|Proxy createOne(array $attributes = [])
@@ -54,7 +54,7 @@
5454
* @phpstan-method static list<Category&Proxy<Category>> randomRangeOrCreate(int $min, int $max, array $attributes = [])
5555
* @phpstan-method static list<Category&Proxy<Category>> randomSet(int $number, array $attributes = [])
5656
*/
57-
final class CategoryFactory extends PersistentProxyObjectFactory
57+
final class CategoryFactory extends PersistentObjectFactory
5858
{
5959
/**
6060
* @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services

0 commit comments

Comments
 (0)