Skip to content
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

Remove constraint for PHP < 8 #41295

Merged
merged 1 commit into from May 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions phpunit
Expand Up @@ -8,13 +8,9 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
exit(1);
}
if (!getenv('SYMFONY_PHPUNIT_VERSION')) {
if (\PHP_VERSION_ID < 70300) {
putenv('SYMFONY_PHPUNIT_VERSION=8.5');
} else {
putenv('SYMFONY_PHPUNIT_VERSION=9.5');
}
putenv('SYMFONY_PHPUNIT_VERSION=9.5');
}
if (!getenv('SYMFONY_PATCH_TYPE_DECLARATIONS') && \PHP_VERSION_ID >= 70300) {
if (!getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) {
putenv('SYMFONY_PATCH_TYPE_DECLARATIONS=deprecations=1');
}
if (getcwd() === realpath(__DIR__.'/src/Symfony/Bridge/PhpUnit')) {
Expand Down
Expand Up @@ -16,9 +16,6 @@
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;

/**
* @requires PHP 8
*/
class UniqueEntityTest extends TestCase
{
public function testAttributeWithDefaultProperty()
Expand Down
Expand Up @@ -193,9 +193,7 @@ public function provideUniquenessConstraints(): iterable
'em' => self::EM_NAME,
])];

if (\PHP_VERSION_ID >= 80000) {
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo");')];
}
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name'], em: 'foo')];
}

/**
Expand Down Expand Up @@ -229,9 +227,7 @@ public function provideConstraintsWithCustomErrorPath(): iterable
'errorPath' => 'bar',
])];

if (\PHP_VERSION_ID >= 80000) {
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", errorPath: "bar");')];
}
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name'], em: 'foo', errorPath: 'bar')];
}

/**
Expand Down Expand Up @@ -290,9 +286,7 @@ public function provideConstraintsWithIgnoreNullDisabled(): iterable
'ignoreNull' => false,
])];

if (\PHP_VERSION_ID >= 80000) {
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: false);')];
}
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name', 'name2'], em: 'foo', ignoreNull: false)];
}

/**
Expand Down Expand Up @@ -339,9 +333,7 @@ public function provideConstraintsWithIgnoreNullEnabled(): iterable
'ignoreNull' => true,
])];

if (\PHP_VERSION_ID >= 80000) {
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name", "name2"], em: "foo", ignoreNull: true);')];
}
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name', 'name2'], em: 'foo', ignoreNull: true)];
}

public function testValidateUniquenessWithValidCustomErrorPath()
Expand Down Expand Up @@ -440,9 +432,7 @@ public function provideConstraintsWithCustomRepositoryMethod(): iterable
'repositoryMethod' => 'findByCustom',
])];

if (\PHP_VERSION_ID >= 80000) {
yield 'Named arguments' => [eval('return new \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity(message: "myMessage", fields: ["name"], em: "foo", repositoryMethod: "findByCustom");')];
}
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name'], em: 'foo', repositoryMethod: 'findByCustom')];
}

/**
Expand Down
Expand Up @@ -1016,10 +1016,6 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
->replaceArgument(0, $config['default_uri']);
}

if (\PHP_VERSION_ID < 80000 && !$this->annotationsConfigEnabled) {
return;
}

$container->register('routing.loader.annotation', AnnotatedRouteControllerLoader::class)
->setPublic(false)
->addTag('routing.loader', ['priority' => -10])
Expand Down
Expand Up @@ -140,7 +140,7 @@ protected function doDeleteYieldTags(array $ids): iterable
continue;
}

if ((\PHP_VERSION_ID >= 70300 || '\\' !== \DIRECTORY_SEPARATOR) && !@unlink($file)) {
if (!@unlink($file)) {
fclose($h);
continue;
}
Expand All @@ -165,10 +165,6 @@ protected function doDeleteYieldTags(array $ids): iterable
}

fclose($h);

if (\PHP_VERSION_ID < 70300 && '\\' === \DIRECTORY_SEPARATOR) {
@unlink($file);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php
Expand Up @@ -25,9 +25,9 @@ class DefaultMarshaller implements MarshallerInterface
public function __construct(bool $useIgbinarySerialize = null)
{
if (null === $useIgbinarySerialize) {
$useIgbinarySerialize = \extension_loaded('igbinary') && (\PHP_VERSION_ID < 70400 || version_compare('3.1.6', phpversion('igbinary'), '<='));
} elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || (\PHP_VERSION_ID >= 70400 && version_compare('3.1.6', phpversion('igbinary'), '>')))) {
throw new CacheException(\extension_loaded('igbinary') && \PHP_VERSION_ID >= 70400 ? 'Please upgrade the "igbinary" PHP extension to v3.1.6 or higher.' : 'The "igbinary" PHP extension is not loaded.');
$useIgbinarySerialize = \extension_loaded('igbinary') && version_compare('3.1.6', phpversion('igbinary'), '<=');
} elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || version_compare('3.1.6', phpversion('igbinary'), '>'))) {
throw new CacheException(\extension_loaded('igbinary') ? 'Please upgrade the "igbinary" PHP extension to v3.1.6 or higher.' : 'The "igbinary" PHP extension is not loaded.');
}
$this->useIgbinarySerialize = $useIgbinarySerialize;
}
Expand Down
Expand Up @@ -72,13 +72,8 @@ public function testOptions()
*/
public function testBadOptions($name, $value)
{
if (\PHP_VERSION_ID < 80000) {
$this->expectException(\ErrorException::class);
$this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::');
} else {
$this->expectException(\Error::class);
$this->expectExceptionMessage('Undefined constant Memcached::');
}
$this->expectException(\Error::class);
$this->expectExceptionMessage('Undefined constant Memcached::');

MemcachedAdapter::createConnection([], [$name => $value]);
}
Expand Down
Expand Up @@ -24,7 +24,7 @@ public function testSerialize()
'b' => function () {},
];

$expected = ['a' => \extension_loaded('igbinary') && (\PHP_VERSION_ID < 70400 || version_compare('3.1.6', phpversion('igbinary'), '<=')) ? igbinary_serialize(123) : serialize(123)];
$expected = ['a' => \extension_loaded('igbinary') && (version_compare('3.1.6', phpversion('igbinary'), '<=')) ? igbinary_serialize(123) : serialize(123)];
$this->assertSame($expected, $marshaller->marshall($values, $failed));
$this->assertSame(['b'], $failed);
}
Expand All @@ -43,7 +43,7 @@ public function testNativeUnserialize()
*/
public function testIgbinaryUnserialize()
{
if (\PHP_VERSION_ID >= 70400 && version_compare('3.1.6', phpversion('igbinary'), '>')) {
if (version_compare('3.1.6', phpversion('igbinary'), '>')) {
$this->markTestSkipped('igbinary is not compatible with PHP 7.4.');
}

Expand All @@ -67,7 +67,7 @@ public function testNativeUnserializeNotFoundClass()
*/
public function testIgbinaryUnserializeNotFoundClass()
{
if (\PHP_VERSION_ID >= 70400 && version_compare('3.1.6', phpversion('igbinary'), '>')) {
if (version_compare('3.1.6', phpversion('igbinary'), '>')) {
$this->markTestSkipped('igbinary is not compatible with PHP 7.4.');
}

Expand Down Expand Up @@ -95,7 +95,7 @@ public function testNativeUnserializeInvalid()
*/
public function testIgbinaryUnserializeInvalid()
{
if (\PHP_VERSION_ID >= 70400 && version_compare('3.1.6', phpversion('igbinary'), '>')) {
if (version_compare('3.1.6', phpversion('igbinary'), '>')) {
$this->markTestSkipped('igbinary is not compatible with PHP 7.4.');
}

Expand Down
Expand Up @@ -190,7 +190,7 @@ public static function throwOnRequiredClass(string $class, \Exception $previous
'args' => [$class],
];

if (\PHP_VERSION_ID >= 80000 && isset($trace[1])) {
if (isset($trace[1])) {
$callerFrame = $trace[1];
$i = 2;
} elseif (false !== $i = array_search($autoloadFrame, $trace, true)) {
Expand Down
Expand Up @@ -143,13 +143,11 @@ public function provideHashedSignature(): iterable
yield [0, 14, '/** priv docblock */'];
yield [0, 15, ''];

if (\PHP_VERSION_ID >= 70400) {
// PHP7.4 typed properties without default value are
// undefined, make sure this doesn't throw an error
yield [1, 5, 'public array $pub;'];
yield [0, 7, 'protected int $prot;'];
yield [0, 9, 'private string $priv;'];
}
// PHP7.4 typed properties without default value are
// undefined, make sure this doesn't throw an error
yield [1, 5, 'public array $pub;'];
yield [0, 7, 'protected int $prot;'];
yield [0, 9, 'private string $priv;'];

yield [1, 17, 'public function ccc($bar = 187) {}'];
yield [1, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}'];
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -67,7 +67,7 @@ public static function getDefaultName()
{
$class = static::class;

if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
return $attribute[0]->newInstance()->name;
}

Expand All @@ -83,7 +83,7 @@ public static function getDefaultDescription(): ?string
{
$class = static::class;

if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
return $attribute[0]->newInstance()->description;
}

Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Expand Up @@ -406,9 +406,6 @@ public function testSetCodeWithStaticAnonymousFunction()
$this->assertEquals('interact called'.\PHP_EOL.'not bound'.\PHP_EOL, $tester->getDisplay());
}

/**
* @requires PHP 8
*/
public function testCommandAttribute()
{
$this->assertSame('|foo|f', Php8Command::getDefaultName());
Expand Down
Expand Up @@ -33,7 +33,7 @@ public function __construct(string $name)

public static function parseName(\ReflectionParameter $parameter): string
{
if (80000 > \PHP_VERSION_ID || !$target = $parameter->getAttributes(self::class)[0] ?? null) {
if (!$target = $parameter->getAttributes(self::class)[0] ?? null) {
return $parameter->name;
}

Expand Down
Expand Up @@ -22,7 +22,7 @@ final class AttributeAutoconfigurationPass extends AbstractRecursivePass
{
public function process(ContainerBuilder $container): void
{
if (80000 > \PHP_VERSION_ID || !$container->getAutoconfiguredAttributes()) {
if (!$container->getAutoconfiguredAttributes()) {
return;
}

Expand Down
Expand Up @@ -129,7 +129,7 @@ private function doProcessValue($value, bool $isRoot = false)
array_unshift($this->methodCalls, [$constructor, $value->getArguments()]);
}

$checkAttributes = 80000 <= \PHP_VERSION_ID && !$value->hasTag('container.ignore_attributes');
$checkAttributes = !$value->hasTag('container.ignore_attributes');
$this->methodCalls = $this->autowireCalls($reflectionClass, $isRoot, $checkAttributes);

if ($constructor) {
Expand Down
Expand Up @@ -50,7 +50,7 @@ protected function processValue($value, bool $isRoot = false)
}

while (true) {
if (\PHP_VERSION_ID >= 80000 && $r->getAttributes(Required::class)) {
if ($r->getAttributes(Required::class)) {
if ($this->isWither($r, $r->getDocComment() ?: '')) {
$withers[] = [$r->name, [], true];
} else {
Expand Down
Expand Up @@ -29,9 +29,6 @@ class AutowireRequiredPropertiesPass extends AbstractRecursivePass
*/
protected function processValue($value, bool $isRoot = false)
{
if (\PHP_VERSION_ID < 70400) {
return $value;
}
$value = parent::processValue($value, $isRoot);

if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
Expand All @@ -46,7 +43,7 @@ protected function processValue($value, bool $isRoot = false)
if (!($type = $reflectionProperty->getType()) instanceof \ReflectionNamedType) {
continue;
}
if ((\PHP_VERSION_ID < 80000 || !$reflectionProperty->getAttributes(Required::class))
if (!$reflectionProperty->getAttributes(Required::class)
&& ((false === $doc = $reflectionProperty->getDocComment()) || false === stripos($doc, '@required') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc))
) {
continue;
Expand Down
Expand Up @@ -60,7 +60,7 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
$definition = $container->getDefinition($serviceId);
$class = $definition->getClass();
$class = $container->getParameterBag()->resolveValue($class) ?: null;
$checkTaggedItem = !$definition->hasTag(80000 <= \PHP_VERSION_ID && $definition->isAutoconfigured() ? 'container.ignore_attributes' : $tagName);
$checkTaggedItem = !$definition->hasTag($definition->isAutoconfigured() ? 'container.ignore_attributes' : $tagName);

foreach ($attributes as $attribute) {
$index = $priority = null;
Expand Down
Expand Up @@ -31,10 +31,6 @@ final class RegisterAutoconfigureAttributesPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (80000 > \PHP_VERSION_ID) {
return;
}

foreach ($container->getDefinitions() as $id => $definition) {
if ($this->accept($definition) && null !== $class = $container->getReflectionClass($definition->getClass())) {
$this->processClass($container, $class);
Expand All @@ -44,7 +40,7 @@ public function process(ContainerBuilder $container)

public function accept(Definition $definition): bool
{
return 80000 <= \PHP_VERSION_ID && $definition->isAutoconfigured() && !$definition->hasTag('container.ignore_attributes');
return $definition->isAutoconfigured() && !$definition->hasTag('container.ignore_attributes');
}

public function processClass(ContainerBuilder $container, \ReflectionClass $class)
Expand Down
Expand Up @@ -85,10 +85,8 @@ private static function doPreload(string $class, array &$preloaded): void
$r->getConstants();
$r->getDefaultProperties();

if (\PHP_VERSION_ID >= 70400) {
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
self::preloadType($p->getType(), $preloaded);
}
foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
self::preloadType($p->getType(), $preloaded);
}

foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Expand Up @@ -192,7 +192,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv)
return (string) $env;
}

if (in_array($prefix, ['bool', 'not'], true)) {
if (\in_array($prefix, ['bool', 'not'], true)) {
$env = (bool) (filter_var($env, \FILTER_VALIDATE_BOOLEAN) ?: filter_var($env, \FILTER_VALIDATE_INT) ?: filter_var($env, \FILTER_VALIDATE_FLOAT));

return 'not' === $prefix ? !$env : $env;
Expand Down Expand Up @@ -288,7 +288,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv)
}

if ('csv' === $prefix) {
return str_getcsv($env, ',', '"', \PHP_VERSION_ID >= 70400 ? '' : '\\');
return str_getcsv($env, ',', '"', '');
}

if ('trim' === $prefix) {
Expand Down
18 changes: 8 additions & 10 deletions src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php
Expand Up @@ -101,18 +101,16 @@ private function executeCallback(callable $callback, ContainerConfigurator $cont
$configBuilders = [];
$r = new \ReflectionFunction($callback);

if (\PHP_VERSION_ID >= 80000) {
$attribute = null;
foreach ($r->getAttributes(When::class) as $attribute) {
if ($this->env === $attribute->newInstance()->env) {
$attribute = null;
break;
}
}
if (null !== $attribute) {
return;
$attribute = null;
foreach ($r->getAttributes(When::class) as $attribute) {
if ($this->env === $attribute->newInstance()->env) {
$attribute = null;
break;
}
}
if (null !== $attribute) {
return;
}

foreach ($r->getParameters() as $parameter) {
$reflectionType = $parameter->getType();
Expand Down
Expand Up @@ -669,11 +669,6 @@ public function validateSchema(\DOMDocument $dom)

private function shouldEnableEntityLoader(): bool
{
// Version prior to 8.0 can be enabled without deprecation
if (\PHP_VERSION_ID < 80000) {
return true;
}

static $dom, $schema;
if (null === $dom) {
$dom = new \DOMDocument();
Expand Down
Expand Up @@ -16,9 +16,6 @@
use Symfony\Component\DependencyInjection\Compiler\AttributeAutoconfigurationPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @requires PHP 8
*/
class AttributeAutoconfigurationPassTest extends TestCase
{
public function testProcessAddsNoEmptyInstanceofConditionals()
Expand Down