Skip to content

Commit

Permalink
Replaced ternaries with null coalescing operators
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed May 4, 2021
1 parent dfc450e commit b680fbc
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion scripts/patchCollectionProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function patchFile($filepath)
"#(?<=\n)(?:(/[*]+\n(?:[*](?! @method).*\n)*?)(?:[*]\n)*(?:[*] @method.*\n)*[*]/\n)?class#",
function ($m) use ($methods)
{
$doc = (isset($m[1])) ? $m[1] : "\n/**\n";
$doc = $m[1] ?? "\n/**\n";

foreach ($methods as $text)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/Helpers/ElementInspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ protected static function getBitfield(DOMElement $element, $name)
*/
protected static function getProperties(DOMElement $element)
{
return (isset(self::$htmlElements[$element->nodeName])) ? self::$htmlElements[$element->nodeName] : self::$htmlElements['span'];
return self::$htmlElements[$element->nodeName] ?? self::$htmlElements['span'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/Helpers/RegexpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static function getCaptureNames($regexp)
{
if ($tok['type'] === 'capturingSubpatternStart')
{
$map[] = (isset($tok['name'])) ? $tok['name'] : '';
$map[] = $tok['name'] ?? '';
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/JavaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getParser(array $config = null)
$this->xsl = $xslt->getXSL($this->configurator->rendering);

// Prepare the parser's config
$this->config = (isset($config)) ? $config : $this->configurator->asConfig();
$this->config = $config ?? $this->configurator->asConfig();
$this->config = ConfigHelper::filterConfig($this->config, 'JS');
$this->config = $this->callbackGenerator->replaceCallbacks($this->config);

Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/RendererGenerators/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PHP implements RendererGenerator
*/
public function __construct($cacheDir = null)
{
$this->cacheDir = (isset($cacheDir)) ? $cacheDir : sys_get_temp_dir();
$this->cacheDir = $cacheDir ?? sys_get_temp_dir();
if (extension_loaded('tokenizer'))
{
$this->controlStructuresOptimizer = new ControlStructuresOptimizer;
Expand Down
2 changes: 1 addition & 1 deletion src/Configurator/RulesGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function getTagInspectors(TagCollection $tags)
foreach ($tags as $tagName => $tag)
{
// Use the tag's template if applicable or XSLT's implicit default otherwise
$template = (isset($tag->template)) ? $tag->template : '<xsl:apply-templates/>';
$template = $tag->template ?? '<xsl:apply-templates/>';
$tagInspectors[$tagName] = new TemplateInspector($template);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/AttributeFilters/UrlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected static function parseUrl($url)
$tokens = ['scheme', 'user', 'pass', 'host', 'port', 'path', 'query', 'fragment'];
foreach ($tokens as $i => $name)
{
$parts[$name] = (isset($m[$i + 1])) ? $m[$i + 1] : '';
$parts[$name] = $m[$i + 1] ?? '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/FilterProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected static function executeFilter(array $filter, array $vars)
{
foreach ($filter['params'] as $k => $v)
{
$args[] = (isset($vars[$k])) ? $vars[$k] : $v;
$args[] = $vars[$k] ?? $v;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Censor/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function parse($text, array $matches)
{
$tagName = $this->config['tagName'];
$attrName = $this->config['attrName'];
$replacements = (isset($this->config['replacements'])) ? $this->config['replacements'] : [];
$replacements = $this->config['replacements'] ?? [];
foreach ($matches as $m)
{
if ($this->isAllowed($m[0][0]))
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/MediaEmbed/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected static function interpolateVars($str, array $vars)
'(\\{@(\\w+)\\})',
function ($m) use ($vars)
{
return (isset($vars[$m[1]])) ? $vars[$m[1]] : '';
return $vars[$m[1]] ?? '';
},
$str
);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/Preg/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ protected function parseRegexp($regexp)
}
$this->captures[] = [
'pos' => $token['pos'],
'name' => (isset($token['name'])) ? $token['name'] : null,
'name' => $token['name'] ?? null,
'expr' => $token['content']
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ abstract protected function renderRichText($xml);
*/
public function getParameter($paramName)
{
return (isset($this->params[$paramName])) ? $this->params[$paramName] : '';
return $this->params[$paramName] ?? '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function getClient()
public static function getCachingClient($cacheDir = null)
{
$client = new Cached(self::getClient());
$client->cacheDir = (isset($cacheDir)) ? $cacheDir : sys_get_temp_dir();
$client->cacheDir = $cacheDir ?? sys_get_temp_dir();

return $client;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Configurator/Helpers/RegexpBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ protected function fromListTestCase($k)

$expected = $data[$k][0];
$words = $data[$k][1];
$options = (isset($data[$k][2])) ? $data[$k][2] : [];
$options = $data[$k][2] ?? [];

$this->assertSame($expected, RegexpBuilder::fromList($words, $options));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugins/Litedown/Parser/Passes/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected static function fixTests($tests)
$test[2] = [];
}

$callback = (isset($test[3])) ? $test[3] : null;
$callback = $test[3] ?? null;
$test[3] = function ($configurator) use ($callback)
{
if (isset($callback))
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugins/Litedown/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected static function fixTests($tests)
$test[2] = [];
}

$callback = (isset($test[3])) ? $test[3] : null;
$callback = $test[3] ?? null;
$test[3] = function ($configurator) use ($callback)
{
if (isset($callback))
Expand Down

0 comments on commit b680fbc

Please sign in to comment.