Skip to content

Commit b0453d5

Browse files
nicolas-grekasfabpot
authored andcommitted
Bump minimum version of PHP to 8.1
1 parent 58fd362 commit b0453d5

35 files changed

+33
-217
lines changed

Argument/RewindableGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class RewindableGenerator implements \IteratorAggregate, \Countable
2121

2222
public function __construct(callable $generator, int|callable $count)
2323
{
24-
$this->generator = $generator instanceof \Closure ? $generator : \Closure::fromCallable($generator);
25-
$this->count = \is_callable($count) && !$count instanceof \Closure ? \Closure::fromCallable($count) : $count;
24+
$this->generator = $generator(...);
25+
$this->count = \is_int($count) ? $count : $count(...);
2626
}
2727

2828
public function getIterator(): \Traversable
@@ -34,7 +34,7 @@ public function getIterator(): \Traversable
3434

3535
public function count(): int
3636
{
37-
if (\is_callable($count = $this->count)) {
37+
if (!\is_int($count = $this->count)) {
3838
$this->count = $count();
3939
}
4040

Compiler/AttributeAutoconfigurationPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function process(ContainerBuilder $container): void
3434
}
3535

3636
foreach ($container->getAutoconfiguredAttributes() as $attributeName => $callable) {
37-
$callableReflector = new \ReflectionFunction(\Closure::fromCallable($callable));
37+
$callableReflector = new \ReflectionFunction($callable(...));
3838
if ($callableReflector->getNumberOfParameters() <= 2) {
3939
$this->classAttributeConfigurators[$attributeName] = $callable;
4040
continue;

Compiler/AutowirePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot,
205205
continue;
206206
}
207207

208-
if (\PHP_VERSION_ID >= 80100 && (\is_array($value->value) ? $value->value : \is_object($value->value))) {
208+
if (\is_array($value->value) ? $value->value : \is_object($value->value)) {
209209
unset($arguments[$j]);
210210
$namedArguments = $value->names;
211211
} else {

Compiler/Compiler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function compile(ContainerBuilder $container)
8181

8282
if ($msg !== $resolvedMsg = $container->resolveEnvPlaceholders($msg, null, $usedEnvs)) {
8383
$r = new \ReflectionProperty($prev, 'message');
84-
$r->setAccessible(true);
8584
$r->setValue($prev, $resolvedMsg);
8685
}
8786
} while ($prev = $prev->getPrevious());

Compiler/RegisterAutoconfigureAttributesPass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ private static function registerForAutoconfiguration(ContainerBuilder $container
5757
}
5858

5959
$parseDefinitions = new \ReflectionMethod(YamlFileLoader::class, 'parseDefinitions');
60-
$parseDefinitions->setAccessible(true);
6160
$yamlLoader = $parseDefinitions->getDeclaringClass()->newInstanceWithoutConstructor();
6261

6362
self::$registerForAutoconfiguration = static function (ContainerBuilder $container, \ReflectionClass $class, \ReflectionAttribute $attribute) use ($parseDefinitions, $yamlLoader) {

Compiler/ResolveChildDefinitionsPass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ private function resolveDefinition(ChildDefinition $definition): Definition
6363
throw $e;
6464
} catch (ExceptionInterface $e) {
6565
$r = new \ReflectionProperty($e, 'message');
66-
$r->setAccessible(true);
6766
$r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage()));
6867

6968
throw $e;

Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALI
194194
{
195195
return $this->services[$id]
196196
?? $this->services[$id = $this->aliases[$id] ?? $id]
197-
?? ('service_container' === $id ? $this : ($this->factories[$id] ?? [$this, 'make'])($id, $invalidBehavior));
197+
?? ('service_container' === $id ? $this : ($this->factories[$id] ?? $this->make(...))($id, $invalidBehavior));
198198
}
199199

200200
/**
@@ -345,7 +345,7 @@ protected function getEnv(string $name): mixed
345345
if (!$this->has($id = 'container.env_var_processors_locator')) {
346346
$this->set($id, new ServiceLocator([]));
347347
}
348-
$this->getEnv ??= \Closure::fromCallable([$this, 'getEnv']);
348+
$this->getEnv ??= $this->getEnv(...);
349349
$processors = $this->get($id);
350350

351351
if (false !== $i = strpos($name, ':')) {

ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ private function doResolveServices(mixed $value, array &$inlineServices = [], bo
11541154
$types[$k] = $v instanceof TypedReference ? $v->getType() : '?';
11551155
}
11561156
}
1157-
$value = new ServiceLocator(\Closure::fromCallable([$this, 'resolveServices']), $refs, $types);
1157+
$value = new ServiceLocator($this->resolveServices(...), $refs, $types);
11581158
} elseif ($value instanceof Reference) {
11591159
$value = $this->doGet((string) $value, $value->getInvalidBehavior(), $inlineServices, $isConstructorArgument);
11601160
} elseif ($value instanceof Definition) {
@@ -1586,7 +1586,7 @@ private function getExpressionLanguage(): ExpressionLanguage
15861586
if (!class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
15871587
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
15881588
}
1589-
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders, null, \Closure::fromCallable([$this, 'getEnv']));
1589+
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders, null, $this->getEnv(...));
15901590
}
15911591

15921592
return $this->expressionLanguage;

Dumper/PhpDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function dump(array $options = []): string|array
226226
if ($this->addGetService) {
227227
$code = preg_replace(
228228
"/(\r?\n\r?\n public function __construct.+?\\{\r?\n)/s",
229-
"\n protected \$getService;$1 \$this->getService = \\Closure::fromCallable([\$this, 'getService']);\n",
229+
"\n protected \Closure \$getService;$1 \$this->getService = \$this->getService(...);\n",
230230
$code,
231231
1
232232
);
@@ -334,7 +334,7 @@ class %s extends {$options['class']}
334334
if (!$class || str_contains($class, '$') || \in_array($class, ['int', 'float', 'string', 'bool', 'resource', 'object', 'array', 'null', 'callable', 'iterable', 'mixed', 'void'], true)) {
335335
continue;
336336
}
337-
if (!(class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false)) || ((new \ReflectionClass($class))->isUserDefined() && !\in_array($class, ['Attribute', 'JsonException', 'ReturnTypeWillChange', 'Stringable', 'UnhandledMatchError', 'ValueError'], true))) {
337+
if (!(class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false)) || (new \ReflectionClass($class))->isUserDefined()) {
338338
$code[$options['class'].'.preload.php'] .= sprintf("\$classes[] = '%s';\n", $class);
339339
}
340340
}
@@ -891,7 +891,7 @@ protected function {$methodName}($lazyInitialization)
891891
$code .= " return self::do(\$container);\n";
892892
$code .= " };\n\n";
893893
} else {
894-
$code .= sprintf("\\Closure::fromCallable([\$this, '%s']);\n\n", $methodName);
894+
$code .= sprintf("\$this->%s(...);\n\n", $methodName);
895895
}
896896
}
897897

ExpressionLanguageProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
3232

3333
public function __construct(callable $serviceCompiler = null, \Closure $getEnv = null)
3434
{
35-
$this->serviceCompiler = null !== $serviceCompiler && !$serviceCompiler instanceof \Closure ? \Closure::fromCallable($serviceCompiler) : $serviceCompiler;
35+
$this->serviceCompiler = null === $serviceCompiler ? null : $serviceCompiler(...);
3636
$this->getEnv = $getEnv;
3737
}
3838

0 commit comments

Comments
 (0)