Skip to content

Remove deadcode after the bump to PHP >= 8.4 #60666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
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
30 changes: 0 additions & 30 deletions src/Symfony/Bridge/Doctrine/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Bridge\Doctrine;

use Doctrine\Persistence\AbstractManagerRegistry;
use ProxyManager\Proxy\GhostObjectInterface;
use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\VarExporter\LazyObjectInterface;

Expand Down Expand Up @@ -45,34 +43,6 @@ protected function resetService($name): void

return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the if ($manager instanceof LazyObjectInterface) { above also dead code ? Or is there still a case where we use a LazyObjectInterface of var-exporter instead of a native lazy object on PHP 8.4+ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LazyObjectInterface is not deprecated, it's still used for lazy decorators, which is the remaining feature on the topic.

}
if (\PHP_VERSION_ID < 80400) {
if (!$manager instanceof LazyLoadingInterface) {
throw new \LogicException(\sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
}
trigger_deprecation('symfony/doctrine-bridge', '7.3', 'Support for proxy-manager is deprecated.');

if ($manager instanceof GhostObjectInterface) {
throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.');
}
$manager->setProxyInitializer(\Closure::bind(
function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) {
$name = $this->aliases[$name] ?? $name;
$wrappedInstance = match (true) {
isset($this->fileMap[$name]) => $this->load($this->fileMap[$name], false),
!$method = $this->methodMap[$name] ?? null => throw new \LogicException(\sprintf('The "%s" service is synthetic and cannot be reset.', $name)),
(new \ReflectionMethod($this, $method))->isStatic() => $this->{$method}($this, false),
default => $this->{$method}(false),
};
$manager->setProxyInitializer(null);

return true;
},
$this->container,
Container::class
));

return;
}

$r = new \ReflectionClass($manager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function refreshUser(UserInterface $user): UserInterface

if ($refreshedUser instanceof Proxy && !$refreshedUser->__isInitialized()) {
$refreshedUser->__load();
} elseif (\PHP_VERSION_ID >= 80400 && ($r = new \ReflectionClass($refreshedUser))->isUninitializedLazyObject($refreshedUser)) {
} elseif (($r = new \ReflectionClass($refreshedUser))->isUninitializedLazyObject($refreshedUser)) {
$r->initializeLazyObject($refreshedUser);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function createTestEntityManager(?Configuration $config = null): E
$config ??= self::createTestConfiguration();
$eventManager = new EventManager();

if (\PHP_VERSION_ID >= 80400 && method_exists($config, 'enableNativeLazyObjects')) {
if (method_exists($config, 'enableNativeLazyObjects')) {
$config->enableNativeLazyObjects(true);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public function testResetService()
}

/**
* @requires PHP 8.4
*
* @dataProvider provideResetServiceWithNativeLazyObjectsCases
*/
public function testResetServiceWithNativeLazyObjects(string $class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function testRefreshedUserProxyIsLoaded()
$provider = new EntityUserProvider($this->getManager($em), User::class);
$refreshedUser = $provider->refreshUser($user);

if (\PHP_VERSION_ID >= 80400 && method_exists(Configuration::class, 'enableNativeLazyObjects')) {
if (method_exists(Configuration::class, 'enableNativeLazyObjects')) {
$this->assertFalse((new \ReflectionClass(User::class))->isUninitializedLazyObject($refreshedUser));
$this->assertSame('user1', $refreshedUser->name);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
Test that a PHP deprecation from a vendor class autoload is considered indirect.
--SKIPIF--
<?php if (\PHP_VERSION_ID < 80100) echo 'skip'; ?>
--FILE--
<?php

Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Bridge/PhpUnit/Tests/EnumExistsMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
use Symfony\Bridge\PhpUnit\Tests\Fixtures\ExistingEnum;
use Symfony\Bridge\PhpUnit\Tests\Fixtures\ExistingEnumReal;

/**
* @requires PHP 8.1
*/
class EnumExistsMockTest extends TestCase
{
public static function setUpBeforeClass(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
use Symfony\Bridge\PhpUnit\Metadata\AttributeReader;
use Symfony\Bridge\PhpUnit\Tests\Metadata\Fixtures\FooBar;

/**
* @requires PHP 8.0
*/
final class AttributeReaderTest extends TestCase
class AttributeReaderTest extends TestCase
{
/**
* @dataProvider provideReadCases
Expand Down
25 changes: 4 additions & 21 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@
}
};

if (\PHP_VERSION_ID >= 80000) {
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.6') ?: '9.6';
} else {
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.5') ?: '8.5';
}
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.6') ?: '9.6';

$MAX_PHPUNIT_VERSION = $getEnvVar('SYMFONY_MAX_PHPUNIT_VERSION', false);

Expand Down Expand Up @@ -178,7 +174,7 @@
$prevCacheDir = false;
}
}
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : ''));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we really dropping support for older PHPUnit versions ? There is a difference between the default version and the supported versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

older phpunit versions don't support PHP 8, but we bumped the bridge to PHP >= 8.1 (to keep using it when testing Symfony 6.4)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a proper cleanup to remove all code related to using older PHPUnit versions then. For instance, there is no need to remove the prophecy dependency in PHPUnit 9.6 anymore (as it is not installed by default anymore).
And we probably need a check on $PHPUNIT_VERSION to fail properly if the env variable specifies an unsupported PHPUnit version.

$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy');
$SYMFONY_PHPUNIT_REQUIRE = $getEnvVar('SYMFONY_PHPUNIT_REQUIRE', '');
$configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, $SYMFONY_PHPUNIT_REQUIRE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT]));
$PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT);
Expand Down Expand Up @@ -240,9 +236,6 @@
if ($SYMFONY_PHPUNIT_REQUIRE) {
$passthruOrFail("$COMPOSER require --no-update ".$SYMFONY_PHPUNIT_REQUIRE);
}
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
}

if (preg_match('{\^((\d++\.)\d++)[\d\.]*$}', $info['requires']['php'], $phpVersion) && version_compare($phpVersion[2].'99', \PHP_VERSION, '<')) {
$passthruOrFail("$COMPOSER config platform.php \"$phpVersion[1].99\"");
Expand All @@ -267,9 +260,8 @@
}
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
$q = '\\' === \DIRECTORY_SEPARATOR && \PHP_VERSION_ID < 80000 ? '"' : '';
// --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS
$exit = proc_close(proc_open("$q$COMPOSER update --no-dev --prefer-dist --no-progress $q", [], $p, getcwd()));
$exit = proc_close(proc_open("$COMPOSER update --no-dev --prefer-dist --no-progress", [], $p, getcwd()));
putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : ''));
if ($prevCacheDir) {
putenv("COMPOSER_CACHE_DIR=$prevCacheDir");
Expand Down Expand Up @@ -340,16 +332,7 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
}
chdir($oldPwd);

if ($PHPUNIT_VERSION < 8.0) {
$argv = array_filter($argv, function ($v) use (&$argc) {
if ('--do-not-cache-result' !== $v) {
return true;
}
--$argc;

return false;
});
} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), \FILTER_VALIDATE_BOOLEAN)) {
if (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), \FILTER_VALIDATE_BOOLEAN)) {
$argv[] = '--do-not-cache-result';
++$argc;
}
Expand Down
14 changes: 0 additions & 14 deletions src/Symfony/Bridge/PhpUnit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/

use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Deprecations\Deprecation;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;

Expand All @@ -35,19 +34,6 @@

if (class_exists(Deprecation::class)) {
Deprecation::withoutDeduplication();

if (\PHP_VERSION_ID < 80000) {
// Ignore deprecations about the annotation mapping driver when it's not possible to move to the attribute driver yet
Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issues/10098');
}
}

if (!class_exists(AnnotationRegistry::class, false) && class_exists(AnnotationRegistry::class)) {
if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) {
AnnotationRegistry::registerUniqueLoader('class_exists');
} elseif (method_exists(AnnotationRegistry::class, 'registerLoader')) {
AnnotationRegistry::registerLoader('class_exists');
}
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2131,11 +2131,6 @@ private function registerJsonStreamerConfiguration(array $config, ContainerBuild

$container->setParameter('.json_streamer.stream_writers_dir', '%kernel.cache_dir%/json_streamer/stream_writer');
$container->setParameter('.json_streamer.stream_readers_dir', '%kernel.cache_dir%/json_streamer/stream_reader');
$container->setParameter('.json_streamer.lazy_ghosts_dir', '%kernel.cache_dir%/json_streamer/lazy_ghost');

if (\PHP_VERSION_ID >= 80400) {
$container->removeDefinition('.json_streamer.cache_warmer.lazy_ghost');
}
}

private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
tagged_locator('json_streamer.value_transformer'),
service('json_streamer.read.property_metadata_loader'),
param('.json_streamer.stream_readers_dir'),
param('.json_streamer.lazy_ghosts_dir'),
])
->alias(JsonStreamWriter::class, 'json_streamer.stream_writer')
->alias(JsonStreamReader::class, 'json_streamer.stream_reader')
Expand Down Expand Up @@ -108,12 +107,5 @@
service('logger')->ignoreOnInvalid(),
])
->tag('kernel.cache_warmer')

->set('.json_streamer.cache_warmer.lazy_ghost', LazyGhostCacheWarmer::class)
->args([
abstract_arg('streamable class names'),
param('.json_streamer.lazy_ghosts_dir'),
])
->tag('kernel.cache_warmer')
;
};
22 changes: 7 additions & 15 deletions src/Symfony/Bundle/WebProfilerBundle/Profiler/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,13 @@ public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?stri
// highlight_file could throw warnings
// see https://bugs.php.net/25725
$code = @highlight_file($file, true);
if (\PHP_VERSION_ID >= 80300) {
// remove main pre/code tags
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
// split multiline span tags
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
}, $code);
$content = explode("\n", $code);
} else {
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
// split multiline spans
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<]*+<br \/>)++[^<]*+)</span>#', fn ($m) => "<span $m[1]>".str_replace('<br />', "</span><br /><span $m[1]>", $m[2]).'</span>', $code);
$content = explode('<br />', $code);
}
// remove main pre/code tags
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
// split multiline span tags
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
}, $code);
$content = explode("\n", $code);

$lines = [];
if (0 > $srcContext) {
Expand Down
8 changes: 1 addition & 7 deletions src/Symfony/Component/Clock/Clock.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,8 @@ public function sleep(float|int $seconds): void
*/
public function withTimeZone(\DateTimeZone|string $timezone): static
{
if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) {
if (\is_string($timezone)) {
$timezone = new \DateTimeZone($timezone);
} elseif (\is_string($timezone)) {
try {
$timezone = new \DateTimeZone($timezone);
} catch (\Exception $e) {
throw new \DateInvalidTimeZoneException($e->getMessage(), $e->getCode(), $e);
}
}

$clone = clone $this;
Expand Down
48 changes: 3 additions & 45 deletions src/Symfony/Component/Clock/DatePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ public function __construct(string $datetime = 'now', ?\DateTimeZone $timezone =
$now = static::createFromInterface($now);
}

if (\PHP_VERSION_ID < 80300) {
try {
$builtInDate = new parent($datetime, $timezone ?? $now->getTimezone());
$timezone = $builtInDate->getTimezone();
} catch (\Exception $e) {
throw new \DateMalformedStringException($e->getMessage(), $e->getCode(), $e);
}
} else {
$builtInDate = new parent($datetime, $timezone ?? $now->getTimezone());
$timezone = $builtInDate->getTimezone();
}
$builtInDate = new parent($datetime, $timezone ?? $now->getTimezone());
$timezone = $builtInDate->getTimezone();

$now = $now->setTimezone($timezone)->modify($datetime);

Expand Down Expand Up @@ -74,23 +65,7 @@ public static function createFromMutable(\DateTime $object): static

public static function createFromTimestamp(int|float $timestamp): static
{
if (\PHP_VERSION_ID >= 80400) {
return parent::createFromTimestamp($timestamp);
}

if (\is_int($timestamp) || !$ms = (int) $timestamp - $timestamp) {
return static::createFromFormat('U', (string) $timestamp);
}

if (!is_finite($timestamp) || \PHP_INT_MAX + 1.0 <= $timestamp || \PHP_INT_MIN > $timestamp) {
throw new \DateRangeError(\sprintf('DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between %s and %s.999999, %s given', \PHP_INT_MIN, \PHP_INT_MAX, $timestamp));
}

if ($timestamp < 0) {
$timestamp = (int) $timestamp - 2.0 + $ms;
}

return static::createFromFormat('U.u', \sprintf('%.6F', $timestamp));
return parent::createFromTimestamp($timestamp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we drop the method override entirely now that we don't need to polyfill it ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the decoration remains for the static return type, which is more accurate than the native one

}

public function add(\DateInterval $interval): static
Expand All @@ -108,10 +83,6 @@ public function sub(\DateInterval $interval): static
*/
public function modify(string $modifier): static
{
if (\PHP_VERSION_ID < 80300) {
return @parent::modify($modifier) ?: throw new \DateMalformedStringException(error_get_last()['message'] ?? \sprintf('Invalid modifier: "%s".', $modifier));
}

return parent::modify($modifier);
}

Expand Down Expand Up @@ -151,19 +122,6 @@ public function setMicrosecond(int $microsecond): static
throw new \DateRangeError('DatePoint::setMicrosecond(): Argument #1 ($microsecond) must be between 0 and 999999, '.$microsecond.' given');
}

if (\PHP_VERSION_ID < 80400) {
return $this->setTime(...explode('.', $this->format('H.i.s.'.$microsecond)));
}

return parent::setMicrosecond($microsecond);
}

public function getMicrosecond(): int
{
if (\PHP_VERSION_ID >= 80400) {
return parent::getMicrosecond();
}

return $this->format('u');
}
}
16 changes: 2 additions & 14 deletions src/Symfony/Component/Clock/MockClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ final class MockClock implements ClockInterface
*/
public function __construct(\DateTimeImmutable|string $now = 'now', \DateTimeZone|string|null $timezone = null)
{
if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) {
if (\is_string($timezone)) {
$timezone = new \DateTimeZone($timezone);
} elseif (\is_string($timezone)) {
try {
$timezone = new \DateTimeZone($timezone);
} catch (\Exception $e) {
throw new \DateInvalidTimeZoneException($e->getMessage(), $e->getCode(), $e);
}
}

if (\is_string($now)) {
Expand Down Expand Up @@ -66,12 +60,6 @@ public function sleep(float|int $seconds): void
*/
public function modify(string $modifier): void
{
if (\PHP_VERSION_ID < 80300) {
$this->now = @$this->now->modify($modifier) ?: throw new \DateMalformedStringException(error_get_last()['message'] ?? \sprintf('Invalid modifier: "%s". Could not modify MockClock.', $modifier));

return;
}

$this->now = $this->now->modify($modifier);
}

Expand All @@ -80,7 +68,7 @@ public function modify(string $modifier): void
*/
public function withTimeZone(\DateTimeZone|string $timezone): static
{
if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) {
if (\is_string($timezone)) {
$timezone = new \DateTimeZone($timezone);
} elseif (\is_string($timezone)) {
try {
Expand Down
Loading
Loading