Skip to content

Commit

Permalink
utilization of operator ??
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 16, 2017
1 parent fd13d9f commit 496a5dc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Utils/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function unwrap(\Closure $closure): callable
$r = new \ReflectionFunction($closure);
if (substr($r->getName(), -1) === '}') {
$vars = $r->getStaticVariables();
return isset($vars['_callable_']) ? $vars['_callable_'] : $closure;
return $vars['_callable_'] ?? $closure;

} elseif ($obj = $r->getClosureThis()) {
return [$obj, $r->getName()];
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function el(string $name = NULL, $attrs = NULL): self

if (isset($parts[1])) {
foreach (Strings::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\\2|\s))?#i') as $m) {
$el->attrs[$m[1]] = isset($m[3]) ? $m[3] : TRUE;
$el->attrs[$m[1]] = $m[3] ?? TRUE;
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ public function setAttribute(string $name, $value)
*/
public function getAttribute(string $name)
{
return isset($this->attrs[$name]) ? $this->attrs[$name] : NULL;
return $this->attrs[$name] ?? NULL;
}


Expand Down Expand Up @@ -251,7 +251,7 @@ public function __call(string $m, array $args)
$m = substr($m, 3);
$m[0] = $m[0] | "\x20";
if ($p === 'get') {
return isset($this->attrs[$m]) ? $this->attrs[$m] : NULL;
return $this->attrs[$m] ?? NULL;

} elseif ($p === 'add') {
$args[] = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public static function pcre(string $func, array $args)
if (($code = preg_last_error()) // run-time error, but preg_last_error & return code are liars
&& ($res === NULL || !in_array($func, ['preg_filter', 'preg_replace_callback', 'preg_replace']))
) {
throw new RegexpException((isset($messages[$code]) ? $messages[$code] : 'Unknown error')
throw new RegexpException(($messages[$code] ?? 'Unknown error')
. ' (pattern: ' . implode(' or ', (array) $args[0]) . ')', $code);
}
return $res;
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function is($value, string $expected): bool
continue;
}
} elseif ($type === 'pattern') {
if (preg_match('|^' . (isset($item[1]) ? $item[1] : '') . '\z|', $value)) {
if (preg_match('|^' . ($item[1] ?? '') . '\z|', $value)) {
return TRUE;
}
continue;
Expand Down

0 comments on commit 496a5dc

Please sign in to comment.