Skip to content

Commit

Permalink
Get rid of lots of useless conditions (#41198)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot committed Feb 23, 2022
1 parent a8c3b35 commit 91c60ea
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
11 changes: 5 additions & 6 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Expand Up @@ -288,7 +288,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
$attributes[$key] = $attributes[$key]->format(explode(':', $value, 2)[1]);
}

if ($attributes[$key] && $attributes[$key] instanceof DateTimeInterface &&
if ($attributes[$key] instanceof DateTimeInterface &&
$this->isClassCastable($key)) {
$attributes[$key] = $this->serializeDate($attributes[$key]);
}
Expand Down Expand Up @@ -581,7 +581,7 @@ public function hasAttributeMutator($key)

$returnType = (new ReflectionMethod($this, $method))->getReturnType();

return static::$attributeMutatorCache[get_class($this)][$key] = $returnType &&
return static::$attributeMutatorCache[get_class($this)][$key] =
$returnType instanceof ReflectionNamedType &&
$returnType->getName() === Attribute::class;
}
Expand Down Expand Up @@ -979,7 +979,7 @@ public function hasAttributeSetMutator($key)

$returnType = (new ReflectionMethod($this, $method))->getReturnType();

return static::$setAttributeMutatorCache[$class][$key] = $returnType &&
return static::$setAttributeMutatorCache[$class][$key] =
$returnType instanceof ReflectionNamedType &&
$returnType->getName() === Attribute::class &&
is_callable($this->{$method}()->set);
Expand Down Expand Up @@ -1942,7 +1942,7 @@ public function originalIsEquivalent($key)
return $this->castAttribute($key, $attribute) ==
$this->castAttribute($key, $original);
} elseif ($this->hasCast($key, ['real', 'float', 'double'])) {
if (($attribute === null && $original !== null) || ($attribute !== null && $original === null)) {
if ($original === null) {
return false;
}

Expand Down Expand Up @@ -2096,8 +2096,7 @@ protected static function getAttributeMarkedMutatorMethods($class)
return collect((new ReflectionClass($instance))->getMethods())->filter(function ($method) use ($instance) {
$returnType = $method->getReturnType();

if ($returnType &&
$returnType instanceof ReflectionNamedType &&
if ($returnType instanceof ReflectionNamedType &&
$returnType->getName() === Attribute::class) {
$method->setAccessible(true);

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Expand Up @@ -1150,7 +1150,7 @@ protected function modifyComment(Blueprint $blueprint, Fluent $column)
*/
protected function modifySrid(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->srid) && is_int($column->srid) && $column->srid > 0) {
if (is_int($column->srid) && $column->srid > 0) {
return ' srid '.$column->srid;
}
}
Expand Down
Expand Up @@ -40,7 +40,7 @@ public function handle($request, Closure $next)
*/
protected function transform($key, $value)
{
return is_string($value) && $value === '' ? null : $value;
return $value === '' ? null : $value;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Http/Request.php
Expand Up @@ -407,9 +407,7 @@ public static function createFrom(self $from, $to = null)
{
$request = $to ?: new static;

$files = $from->files->all();

$files = is_array($files) ? array_filter($files) : $files;
$files = array_filter($from->files->all());

$request->initialize(
$from->query->all(),
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Pagination/Cursor.php
Expand Up @@ -113,7 +113,7 @@ public function encode()
*/
public static function fromEncoded($encodedString)
{
if (is_null($encodedString) || ! is_string($encodedString)) {
if (! is_string($encodedString)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Session/Store.php
Expand Up @@ -110,7 +110,7 @@ protected function readFromHandler()
$data = @unserialize($this->prepareForUnserialize($data));
}

if ($data !== false && ! is_null($data) && is_array($data)) {
if ($data !== false && is_array($data)) {
return $data;
}
}
Expand Down
Expand Up @@ -185,7 +185,7 @@ protected function compileAware($expression)
*/
public static function sanitizeComponentAttribute($value)
{
if (is_object($value) && $value instanceof CanBeEscapedWhenCastToString) {
if ($value instanceof CanBeEscapedWhenCastToString) {
return $value->escapeWhenCastingToString();
}

Expand Down

0 comments on commit 91c60ea

Please sign in to comment.