Skip to content

Commit

Permalink
[5.5] Utilise null coalescing operator since we're bumping minimum to…
Browse files Browse the repository at this point in the history
… PHP 7 (#19898)

* No reason to use Arr::get() when we can use null coalescing operator.

Signed-off-by: crynobone <crynobone@gmail.com>

* No reason to use isset(x) ? x : y when we can use null coalescing operator.

Signed-off-by: crynobone <crynobone@gmail.com>

* Remove unused import.

Signed-off-by: crynobone <crynobone@gmail.com>

* Remove unused import under RedisConnector.

Signed-off-by: crynobone <crynobone@gmail.com>
  • Loading branch information
crynobone authored and taylorotwell committed Jul 5, 2017
1 parent 94f6f5f commit c583c99
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion MiddlewareNameResolver.php
Expand Up @@ -38,7 +38,7 @@ public static function resolve($name, $map, $middlewareGroups)
} else {
list($name, $parameters) = array_pad(explode(':', $name, 2), 2, null);

return (isset($map[$name]) ? $map[$name] : $name).
return ($map[$name] ?? $name).
(! is_null($parameters) ? ':'.$parameters : '');
}
}
Expand Down
10 changes: 5 additions & 5 deletions Route.php
Expand Up @@ -557,7 +557,7 @@ public function getDomain()
*/
public function getPrefix()
{
return isset($this->action['prefix']) ? $this->action['prefix'] : null;
return $this->action['prefix'] ?? null;
}

/**
Expand Down Expand Up @@ -605,7 +605,7 @@ public function setUri($uri)
*/
public function getName()
{
return isset($this->action['as']) ? $this->action['as'] : null;
return $this->action['as'] ?? null;
}

/**
Expand Down Expand Up @@ -682,7 +682,7 @@ protected function addGroupNamespaceToStringUses($action)
*/
public function getActionName()
{
return isset($this->action['controller']) ? $this->action['controller'] : 'Closure';
return $this->action['controller'] ?? 'Closure';
}

/**
Expand Down Expand Up @@ -745,15 +745,15 @@ public function gatherMiddleware()
public function middleware($middleware = null)
{
if (is_null($middleware)) {
return (array) Arr::get($this->action, 'middleware', []);
return (array) ($this->action['middleware'] ?? []);
}

if (is_string($middleware)) {
$middleware = func_get_args();
}

$this->action['middleware'] = array_merge(
(array) Arr::get($this->action, 'middleware', []), $middleware
(array) ($this->action['middleware'] ?? []), $middleware
);

return $this;
Expand Down
4 changes: 2 additions & 2 deletions RouteCollection.php
Expand Up @@ -281,7 +281,7 @@ public function hasNamedRoute($name)
*/
public function getByName($name)
{
return isset($this->nameList[$name]) ? $this->nameList[$name] : null;
return $this->nameList[$name] ?? null;
}

/**
Expand All @@ -292,7 +292,7 @@ public function getByName($name)
*/
public function getByAction($action)
{
return isset($this->actionList[$action]) ? $this->actionList[$action] : null;
return $this->actionList[$action] ?? null;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions RouteGroup.php
Expand Up @@ -45,7 +45,7 @@ protected static function formatNamespace($new, $old)
: trim($new['namespace'], '\\');
}

return isset($old['namespace']) ? $old['namespace'] : null;
return $old['namespace'] ?? null;
}

/**
Expand All @@ -57,7 +57,7 @@ protected static function formatNamespace($new, $old)
*/
protected static function formatPrefix($new, $old)
{
$old = Arr::get($old, 'prefix');
$old = $old['prefix'] ?? null;

return isset($new['prefix']) ? trim($old, '/').'/'.trim($new['prefix'], '/') : $old;
}
Expand All @@ -72,8 +72,8 @@ protected static function formatPrefix($new, $old)
protected static function formatWhere($new, $old)
{
return array_merge(
isset($old['where']) ? $old['where'] : [],
isset($new['where']) ? $new['where'] : []
$old['where'] ?? [],
$new['where'] ?? []
);
}

Expand All @@ -87,7 +87,7 @@ protected static function formatWhere($new, $old)
protected static function formatAs($new, $old)
{
if (isset($old['as'])) {
$new['as'] = $old['as'].Arr::get($new, 'as', '');
$new['as'] = $old['as'].($new['as'] ?? '');
}

return $new;
Expand Down
2 changes: 1 addition & 1 deletion RouteParameterBinder.php
Expand Up @@ -106,7 +106,7 @@ protected function matchToKeys(array $matches)
protected function replaceDefaults(array $parameters)
{
foreach ($parameters as $key => $value) {
$parameters[$key] = isset($value) ? $value : Arr::get($this->route->defaults, $key);
$parameters[$key] = $value ?? Arr::get($this->route->defaults, $key);
}

foreach ($this->route->defaults as $key => $value) {
Expand Down
6 changes: 3 additions & 3 deletions Router.php
Expand Up @@ -378,7 +378,7 @@ public function getLastGroupPrefix()
if (! empty($this->groupStack)) {
$last = end($this->groupStack);

return isset($last['prefix']) ? $last['prefix'] : '';
return $last['prefix'] ?? '';
}

return '';
Expand Down Expand Up @@ -521,7 +521,7 @@ protected function prefix($uri)
protected function addWhereClausesToRoute($route)
{
$route->where(array_merge(
$this->patterns, isset($route->getAction()['where']) ? $route->getAction()['where'] : []
$this->patterns, $route->getAction()['where'] ?? []
));

return $route;
Expand Down Expand Up @@ -1027,7 +1027,7 @@ public function currentRouteAction()

$action = $this->current()->getAction();

return isset($action['controller']) ? $action['controller'] : null;
return $action['controller'] ?? null;
}

/**
Expand Down

0 comments on commit c583c99

Please sign in to comment.