Skip to content

Commit e825a1f

Browse files
Add more nullsafe operators
1 parent be14d82 commit e825a1f

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

Generator/UrlGenerator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ public function isStrictRequirements(): ?bool
128128
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string
129129
{
130130
$route = null;
131-
$locale = $parameters['_locale']
132-
?? $this->context->getParameter('_locale')
133-
?: $this->defaultLocale;
131+
$locale = $parameters['_locale'] ?? $this->context->getParameter('_locale') ?: $this->defaultLocale;
134132

135133
if (null !== $locale) {
136134
do {
@@ -140,7 +138,7 @@ public function generate(string $name, array $parameters = [], int $referenceTyp
140138
} while (false !== $locale = strstr($locale, '_', true));
141139
}
142140

143-
if (null === $route = $route ?? $this->routes->get($name)) {
141+
if (null === $route ??= $this->routes->get($name)) {
144142
throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
145143
}
146144

Matcher/Dumper/CompiledUrlMatcherDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ private function compileRoute(Route $route, string $name, string|array|null $var
427427

428428
if ($condition = $route->getCondition()) {
429429
$condition = $this->getExpressionLanguage()->compile($condition, ['context', 'request']);
430-
$condition = $conditions[$condition] ?? $conditions[$condition] = (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
430+
$condition = $conditions[$condition] ??= (str_contains($condition, '$request') ? 1 : -1) * \count($conditions);
431431
} else {
432432
$condition = null;
433433
}

Matcher/Dumper/CompiledUrlMatcherTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
9292
$supportsRedirections = 'GET' === $canonicalMethod && $this instanceof RedirectableUrlMatcherInterface;
9393

9494
foreach ($this->staticRoutes[$trimmedPathinfo] ?? [] as [$ret, $requiredHost, $requiredMethods, $requiredSchemes, $hasTrailingSlash, , $condition]) {
95-
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ?? $request = $this->request ?: $this->createRequest($pathinfo) : null)) {
95+
if ($condition && !($this->checkCondition)($condition, $context, 0 < $condition ? $request ??= $this->request ?: $this->createRequest($pathinfo) : null)) {
9696
continue;
9797
}
9898

@@ -136,7 +136,7 @@ private function doMatch(string $pathinfo, array &$allow = [], array &$allowSche
136136
if (0 === $condition) { // marks the last route in the regexp
137137
continue 3;
138138
}
139-
if (!($this->checkCondition)($condition, $context, 0 < $condition ? $request ?? $request = $this->request ?: $this->createRequest($pathinfo) : null)) {
139+
if (!($this->checkCondition)($condition, $context, 0 < $condition ? $request ??= $this->request ?: $this->createRequest($pathinfo) : null)) {
140140
continue;
141141
}
142142
}

Matcher/Dumper/StaticPrefixCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private function getCommonPrefix(string $prefix, string $anotherPrefix): array
152152
try {
153153
for ($i = $baseLength; $i < $end && $prefix[$i] === $anotherPrefix[$i]; ++$i) {
154154
if ('(' === $prefix[$i]) {
155-
$staticLength = $staticLength ?? $i;
155+
$staticLength ??= $i;
156156
for ($j = 1 + $i, $n = 1; $j < $end && 0 < $n; ++$j) {
157157
if ($prefix[$j] !== $anotherPrefix[$j]) {
158158
break 2;

0 commit comments

Comments
 (0)