Skip to content

Commit eefb4e8

Browse files
Use ??= more
1 parent 9e14f55 commit eefb4e8

File tree

5 files changed

+6
-20
lines changed

5 files changed

+6
-20
lines changed

Caster/ExceptionCaster.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,7 @@ private static function extractSource(string $srcLines, int $line, int $srcConte
352352
$pad = null;
353353
for ($i = $srcContext << 1; $i >= 0; --$i) {
354354
if (isset($src[$i][$ltrim]) && "\r" !== ($c = $src[$i][$ltrim]) && "\n" !== $c) {
355-
if (null === $pad) {
356-
$pad = $c;
357-
}
355+
$pad ??= $c;
358356
if ((' ' !== $c && "\t" !== $c) || $pad !== $c) {
359357
break;
360358
}

Caster/LinkStub.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ public function __construct(string $label, int $line = 0, string $href = null)
2727
{
2828
$this->value = $label;
2929

30-
if (null === $href) {
31-
$href = $label;
32-
}
33-
if (!\is_string($href)) {
30+
if (!\is_string($href ??= $label)) {
3431
return;
3532
}
3633
if (str_starts_with($href, 'file://')) {

Caster/SymfonyCaster.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ public static function castRequest(Request $request, array $a, Stub $stub, bool
3737
foreach (self::REQUEST_GETTERS as $prop => $getter) {
3838
$key = Caster::PREFIX_PROTECTED.$prop;
3939
if (\array_key_exists($key, $a) && null === $a[$key]) {
40-
if (null === $clone) {
41-
$clone = clone $request;
42-
}
40+
$clone ??= clone $request;
4341
$a[Caster::PREFIX_VIRTUAL.$prop] = $clone->{$getter}();
4442
}
4543
}

Cloner/AbstractCloner.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ abstract class AbstractCloner implements ClonerInterface
216216
*/
217217
public function __construct(array $casters = null)
218218
{
219-
if (null === $casters) {
220-
$casters = static::$defaultCasters;
221-
}
222-
$this->addCasters($casters);
219+
$this->addCasters($casters ?? static::$defaultCasters);
223220
}
224221

225222
/**

Dumper/CliDumper.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
261261

262262
public function enterHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild)
263263
{
264-
if (null === $this->colors) {
265-
$this->colors = $this->supportsColors();
266-
}
264+
$this->colors ??= $this->supportsColors();
267265

268266
$this->dumpKey($cursor);
269267
$attr = $cursor->attr;
@@ -417,9 +415,7 @@ protected function dumpKey(Cursor $cursor)
417415
*/
418416
protected function style(string $style, string $value, array $attr = []): string
419417
{
420-
if (null === $this->colors) {
421-
$this->colors = $this->supportsColors();
422-
}
418+
$this->colors ??= $this->supportsColors();
423419

424420
$this->handlesHrefGracefully ??= 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
425421
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);

0 commit comments

Comments
 (0)