Skip to content

Commit 7a57c7a

Browse files
Add more nullsafe operators
1 parent a2b1568 commit 7a57c7a

8 files changed

+11
-11
lines changed

Argument/ServiceLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public function get(string $id): mixed
4545
*/
4646
public function getProvidedServices(): array
4747
{
48-
return $this->serviceTypes ?? $this->serviceTypes = array_map(function () { return '?'; }, $this->serviceMap);
48+
return $this->serviceTypes ??= array_map(function () { return '?'; }, $this->serviceMap);
4949
}
5050
}

Compiler/AnalyzeServiceReferencesPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
9898
$targetId,
9999
$targetDefinition,
100100
$value,
101-
$this->lazy || ($this->hasProxyDumper && $targetDefinition && $targetDefinition->isLazy()),
101+
$this->lazy || ($this->hasProxyDumper && $targetDefinition?->isLazy()),
102102
ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior(),
103103
$this->byConstructor
104104
);
@@ -110,7 +110,7 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
110110
$targetId,
111111
$targetDefinition,
112112
$value,
113-
$this->lazy || ($targetDefinition && $targetDefinition->isLazy()),
113+
$this->lazy || $targetDefinition?->isLazy(),
114114
true
115115
);
116116
}

Compiler/CheckTypeDeclarationsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
160160
*/
161161
private function checkType(Definition $checkedDefinition, mixed $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, \ReflectionType $reflectionType = null): void
162162
{
163-
$reflectionType = $reflectionType ?? $parameter->getType();
163+
$reflectionType ??= $parameter->getType();
164164

165165
if ($reflectionType instanceof \ReflectionUnionType) {
166166
foreach ($reflectionType->getTypes() as $t) {

Compiler/DecoratorServicePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function process(ContainerBuilder $container)
8080
throw new ServiceNotFoundException($inner, $id);
8181
}
8282

83-
if ($decoratedDefinition && $decoratedDefinition->isSynthetic()) {
83+
if ($decoratedDefinition?->isSynthetic()) {
8484
throw new InvalidArgumentException(sprintf('A synthetic service cannot be decorated: service "%s" cannot decorate "%s".', $id, $inner));
8585
}
8686

Compiler/PriorityTaggedServiceTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
6868
} elseif (null === $defaultPriority && $defaultPriorityMethod && $class) {
6969
$defaultPriority = PriorityTaggedServiceUtil::getDefault($container, $serviceId, $class, $defaultPriorityMethod, $tagName, 'priority', $checkTaggedItem);
7070
}
71-
$priority = $priority ?? $defaultPriority ?? $defaultPriority = 0;
71+
$priority ??= $defaultPriority ??= 0;
7272

7373
if (null === $indexAttribute && !$defaultIndexMethod && !$needsIndexes) {
7474
$services[] = [$priority, ++$i, null, $serviceId, null];
@@ -80,7 +80,7 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
8080
} elseif (null === $defaultIndex && $defaultPriorityMethod && $class) {
8181
$defaultIndex = PriorityTaggedServiceUtil::getDefault($container, $serviceId, $class, $defaultIndexMethod ?? 'getDefaultName', $tagName, $indexAttribute, $checkTaggedItem);
8282
}
83-
$index = $index ?? $defaultIndex ?? $defaultIndex = $serviceId;
83+
$index ??= $defaultIndex ??= $serviceId;
8484

8585
$services[] = [$priority, ++$i, $index, $serviceId, $class];
8686
}

Compiler/ResolveInstanceofConditionalsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
7373
$parent = $definition instanceof ChildDefinition ? $definition->getParent() : null;
7474

7575
foreach ($conditionals as $interface => $instanceofDefs) {
76-
if ($interface !== $class && !($reflectionClass ?? $reflectionClass = $container->getReflectionClass($class, false) ?: false)) {
76+
if ($interface !== $class && !($reflectionClass ??= $container->getReflectionClass($class, false) ?: false)) {
7777
continue;
7878
}
7979

Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ final protected function getService(string|false $registry, string $id, ?string
380380
return false !== $registry ? $this->{$registry}[$id] ?? null : null;
381381
}
382382
if (false !== $registry) {
383-
return $this->{$registry}[$id] ?? $this->{$registry}[$id] = $load ? $this->load($method) : $this->{$method}();
383+
return $this->{$registry}[$id] ??= $load ? $this->load($method) : $this->{$method}();
384384
}
385385
if (!$load) {
386386
return $this->{$method}();

Dumper/PhpDumper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function dump(array $options = []): string|array
221221
$this->addDefaultParametersMethod()
222222
;
223223

224-
$proxyClasses = $proxyClasses ?? $this->generateProxyClasses();
224+
$proxyClasses ??= $this->generateProxyClasses();
225225

226226
if ($this->addGetService) {
227227
$code = preg_replace(
@@ -1802,7 +1802,7 @@ private function dumpValue(mixed $value, bool $interpolate = true): string
18021802
if ($value->hasErrors() && $e = $value->getErrors()) {
18031803
return sprintf('throw new RuntimeException(%s)', $this->export(reset($e)));
18041804
}
1805-
if (null !== $this->definitionVariables && $this->definitionVariables->contains($value)) {
1805+
if ($this->definitionVariables?->contains($value)) {
18061806
return $this->dumpValue($this->definitionVariables[$value], $interpolate);
18071807
}
18081808
if ($value->getMethodCalls()) {

0 commit comments

Comments
 (0)