Skip to content

Commit

Permalink
Convert Ternary to Elvis or Null Coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Oct 8, 2023
1 parent e4005e3 commit dafc3af
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ function twig_slice(Environment $env, $item, $start, $length = null, $preserveKe

if ($start >= 0 && $length >= 0 && $item instanceof \Iterator) {
try {
return iterator_to_array(new \LimitIterator($item, $start, null === $length ? -1 : $length), $preserveKeys);
return iterator_to_array(new \LimitIterator($item, $start, $length ?? -1), $preserveKeys);
} catch (\OutOfBoundsException $e) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class FilesystemLoader implements LoaderInterface
*/
public function __construct($paths = [], string $rootPath = null)
{
$this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR;
$this->rootPath = ($rootPath ?? getcwd()).\DIRECTORY_SEPARATOR;
if (null !== $rootPath && false !== ($realPath = realpath($rootPath))) {
$this->rootPath = $realPath.\DIRECTORY_SEPARATOR;
}
Expand Down
4 changes: 2 additions & 2 deletions src/NodeVisitor/EscaperNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function enterNode(Node $node, Environment $env): Node
} elseif ($node instanceof AutoEscapeNode) {
$this->statusStack[] = $node->getAttribute('value');
} elseif ($node instanceof BlockNode) {
$this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env);
$this->statusStack[] = $this->blocks[$node->getAttribute('name')] ?? $this->needEscaping($env);
} elseif ($node instanceof ImportNode) {
$this->safeVars[] = $node->getNode('var')->getAttribute('name');
}
Expand Down Expand Up @@ -189,7 +189,7 @@ private function needEscaping(Environment $env)
return $this->statusStack[\count($this->statusStack) - 1];
}

return $this->defaultStrategy ? $this->defaultStrategy : false;
return $this->defaultStrategy ?: false;
}

private function getEscaperFilter(string $type, Node $node): FilterExpression
Expand Down
2 changes: 1 addition & 1 deletion src/Profiler/Dumper/HtmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function formatTemplate(Profile $profile, $prefix): string

protected function formatNonTemplate(Profile $profile, $prefix): string
{
return sprintf('%s└ %s::%s(<span style="background-color: %s">%s</span>)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName());
return sprintf('%s└ %s::%s(<span style="background-color: %s">%s</span>)', $prefix, $profile->getTemplate(), $profile->getType(), self::$colors[$profile->getType()] ?? 'auto', $profile->getName());
}

protected function formatTime(Profile $profile, $percent): string
Expand Down
2 changes: 1 addition & 1 deletion src/Test/NodeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function assertNodeCompilation($source, Node $node, Environment $environm

protected function getCompiler(Environment $environment = null)
{
return new Compiler(null === $environment ? $this->getEnvironment() : $environment);
return new Compiler($environment ?? $this->getEnvironment());
}

protected function getEnvironment()
Expand Down

0 comments on commit dafc3af

Please sign in to comment.