Skip to content

Commit

Permalink
refactor: fix last deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Dec 21, 2023
1 parent 81d6bc7 commit be7b9f9
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 94 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"psr-4": {"Zenstruck\\Foundry\\": "src/"},
"files": [
"src/functions.php",
"src/deprecations.php",
"src/Persistence/functions.php"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private function configureDatabaseResetter(array $config, ContainerBuilder $cont
$legacyConfig = $config['database_resetter'];

if (false === $legacyConfig['enabled']) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Disabling database reset via bundle configuration is deprecated and will be removed in 2.0. Instead you should not use "%s" trait in your test.', ResetDatabase::class));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Disabling database reset via bundle configuration is deprecated and will be removed in 2.0. Instead you should not use "%s" trait in your test.', ResetDatabase::class);

$configurationDefinition->addMethodCall('disableDatabaseReset');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getAutocompleteValues(): array

$class = $this->toPSR4($rootPath, $phpFile, $namespacePrefix);

if (\in_array($class, ['Zenstruck\Foundry\Proxy', 'Zenstruck\Foundry\RepositoryProxy'])) {
if (\in_array($class, ['Zenstruck\Foundry\Proxy', 'Zenstruck\Foundry\RepositoryProxy', 'Zenstruck\Foundry\RepositoryAssertions'])) {
// do not load legacy Proxy: prevents deprecations in tests.
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function create(
bool $noProxy = false
): object {
if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__);
}

// merge the factory attribute set with the passed attributes
Expand Down Expand Up @@ -203,7 +203,7 @@ final public function many(int $min, ?int $max = null): FactoryCollection
final public function sequence(iterable|callable $sequence): FactoryCollection
{
if (\is_callable($sequence)) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Passing a callable to method "%s()" is deprecated and will be removed in 2.0.', __METHOD__));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Passing a callable to method "%s()" is deprecated and will be removed in 2.0.', __METHOD__);

$sequence = $sequence();
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public function withoutPersisting(): self
*/
final public function withAttributes($attributes = []): self
{
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in 2.0. Use "%s::with()" instead.', __METHOD__, self::class));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in 2.0. Use "%s::with()" instead.', __METHOD__, self::class);

return $this->with($attributes);
}
Expand Down Expand Up @@ -352,7 +352,7 @@ final public static function faker(): Faker\Generator
*/
final public static function delayFlush(callable $callback): mixed
{
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\flush_after()" instead.', __METHOD__));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in Foundry 2.0. Use "Zenstruck\Foundry\Persistence\flush_after()" instead.', __METHOD__);

return self::configuration()->delayFlush($callback);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FactoryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function create(
bool $noProxy = false
): array {
if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__);
}

$objects = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Instantiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class Instantiator
public function __construct(bool $calledInternally = false)
{
if (!$calledInternally) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('%1$s constructor will be private in Foundry 2.0. Use either "%1$s::withConstructor()" or "%1$s::withoutConstructor()"', self::class));
trigger_deprecation('zenstruck\foundry', '1.37.0', '%1$s constructor will be private in Foundry 2.0. Use either "%1$s::withConstructor()" or "%1$s::withoutConstructor()"', self::class);
}
}

Expand Down
22 changes: 10 additions & 12 deletions src/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ public function __construct()

trigger_deprecation(
'zenstruck\foundry', '1.37.0',
\sprintf(
<<<MESSAGE
Class "%s" is deprecated and will be removed in version 2.0. Use "%s" instead.
Be aware that both classes exist "%s" and "%s".
You should use the first one if you don't need a proxy or if the target class of the factory is final:
in Foundry 2.0 proxy system will leverage Symfony's lazy object system and it will be impossible to create a proxy for a final class.
MESSAGE,
self::class,
$newFactoryClass,
PersistentObjectFactory::class,
PersistentProxyObjectFactory::class
)
<<<MESSAGE
Class "%s" is deprecated and will be removed in version 2.0. Use "%s" instead.
Be aware that both classes exist "%s" and "%s".
You should use the first one if you don't need a proxy or if the target class of the factory is final:
in Foundry 2.0 proxy system will leverage Symfony's lazy object system and it will be impossible to create a proxy for a final class.
MESSAGE,
self::class,
$newFactoryClass,
PersistentObjectFactory::class,
PersistentProxyObjectFactory::class
);

parent::__construct();
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/PersistentObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function create(
bool $noProxy = false
): object {
if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__);
}

return parent::create(
Expand Down Expand Up @@ -340,7 +340,7 @@ protected function initialize()
*/
final protected function addState(array|callable $attributes = []): static
{
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Method "%s()" is deprecated and will be removed in version 2.0. Use "%s::with()" instead.', __METHOD__, Factory::class));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Method "%s()" is deprecated and will be removed in version 2.0. Use "%s::with()" instead.', __METHOD__, Factory::class);

return $this->with($attributes);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Persistence/PersistentProxyObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ final public static function new(array|callable|string $defaultAttributes = [],
if ((new \ReflectionClass(static::class()))->isFinal()) {
trigger_deprecation(
'zenstruck\foundry', '1.37.0',
\sprintf('Using a proxy factory with a final class is deprecated and will throw an error in Foundry 2.0. Use "%s" instead, or unfinalize "%s" class.', self::class, static::class())
'Using a proxy factory with a final class is deprecated and will throw an error in Foundry 2.0. Use "%s" instead, or unfinalize "%s" class.',
self::class,
static::class()
);
}

Expand All @@ -63,7 +65,7 @@ final public function create(
bool $noProxy = false
): object {
if (2 === \count(\func_get_args()) && !\str_starts_with(\debug_backtrace(options: \DEBUG_BACKTRACE_IGNORE_ARGS, limit: 1)[0]['class'] ?? '', 'Zenstruck\Foundry')) {
trigger_deprecation('zenstruck\foundry', '1.37.0', \sprintf('Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__));
trigger_deprecation('zenstruck\foundry', '1.37.0', 'Parameter "$noProxy" of method "%s()" is deprecated and will be removed in Foundry 2.0.', __METHOD__);
}

return Factory::create($attributes, noProxy: false);
Expand Down
69 changes: 69 additions & 0 deletions src/Persistence/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,73 @@ public function _disableAutoRefresh(): static;
* @param callable $callback (object|Proxy $object): void
*/
public function _withoutAutoRefresh(callable $callback): static;

/**
* @return TProxiedObject
*
* @deprecated Use method "_real()" instead
*/
public function object(): object;

/**
* @deprecated Use method "_save()" instead
*/
public function save(): static;

/**
* @deprecated Use method "_delete()" instead
*/
public function remove(): static;

/**
* @deprecated Use method "_refresh()" instead
*/
public function refresh(): static;

/**
* @deprecated Use method "_set()" instead
*/
public function forceSet(string $property, mixed $value): static;

/**
* @deprecated without replacement
*/
public function forceSetAll(array $properties): static;

/**
* @deprecated Use method "_get()" instead
*/
public function get(string $property): mixed;

/**
* @deprecated Use method "_repository()" instead
*/
public function repository(): RepositoryDecorator;

/**
* @deprecated Use method "_enableAutoRefresh()" instead
*/
public function enableAutoRefresh(): static;

/**
* @deprecated Use method "_disableAutoRefresh()" instead
*/
public function disableAutoRefresh(): static;

/**
* @param callable $callback (object|Proxy $object): void
*
* @deprecated Use method "_withoutAutoRefresh()" instead
*/
public function withoutAutoRefresh(callable $callback): static;

/**
* @deprecated without replacement
*/
public function assertPersisted(string $message = '{entity} is not persisted.'): self;

/**
* @deprecated without replacement
*/
public function assertNotPersisted(string $message = '{entity} is persisted but it should not be.'): self;
}
2 changes: 2 additions & 0 deletions src/Persistence/RepositoryAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ public function notExists($criteria, string $message = 'Expected {entity} to not
return $this;
}
}

class_exists(\Zenstruck\Foundry\RepositoryAssertions::class);
2 changes: 2 additions & 0 deletions src/Persistence/RepositoryDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,5 @@ private function getObjectManager(): ObjectManager
return Factory::configuration()->objectManagerFor($this->getClassName());
}
}

class_exists(\Zenstruck\Foundry\RepositoryProxy::class);
Loading

0 comments on commit be7b9f9

Please sign in to comment.