Skip to content

Commit 91c60ea

Browse files
authored
Get rid of lots of useless conditions (#41198)
1 parent a8c3b35 commit 91c60ea

File tree

7 files changed

+11
-14
lines changed

7 files changed

+11
-14
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
288288
$attributes[$key] = $attributes[$key]->format(explode(':', $value, 2)[1]);
289289
}
290290

291-
if ($attributes[$key] && $attributes[$key] instanceof DateTimeInterface &&
291+
if ($attributes[$key] instanceof DateTimeInterface &&
292292
$this->isClassCastable($key)) {
293293
$attributes[$key] = $this->serializeDate($attributes[$key]);
294294
}
@@ -581,7 +581,7 @@ public function hasAttributeMutator($key)
581581

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

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

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

982-
return static::$setAttributeMutatorCache[$class][$key] = $returnType &&
982+
return static::$setAttributeMutatorCache[$class][$key] =
983983
$returnType instanceof ReflectionNamedType &&
984984
$returnType->getName() === Attribute::class &&
985985
is_callable($this->{$method}()->set);
@@ -1942,7 +1942,7 @@ public function originalIsEquivalent($key)
19421942
return $this->castAttribute($key, $attribute) ==
19431943
$this->castAttribute($key, $original);
19441944
} elseif ($this->hasCast($key, ['real', 'float', 'double'])) {
1945-
if (($attribute === null && $original !== null) || ($attribute !== null && $original === null)) {
1945+
if ($original === null) {
19461946
return false;
19471947
}
19481948

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

2099-
if ($returnType &&
2100-
$returnType instanceof ReflectionNamedType &&
2099+
if ($returnType instanceof ReflectionNamedType &&
21012100
$returnType->getName() === Attribute::class) {
21022101
$method->setAccessible(true);
21032102

src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ protected function modifyComment(Blueprint $blueprint, Fluent $column)
11501150
*/
11511151
protected function modifySrid(Blueprint $blueprint, Fluent $column)
11521152
{
1153-
if (! is_null($column->srid) && is_int($column->srid) && $column->srid > 0) {
1153+
if (is_int($column->srid) && $column->srid > 0) {
11541154
return ' srid '.$column->srid;
11551155
}
11561156
}

src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function handle($request, Closure $next)
4040
*/
4141
protected function transform($key, $value)
4242
{
43-
return is_string($value) && $value === '' ? null : $value;
43+
return $value === '' ? null : $value;
4444
}
4545

4646
/**

src/Illuminate/Http/Request.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,7 @@ public static function createFrom(self $from, $to = null)
407407
{
408408
$request = $to ?: new static;
409409

410-
$files = $from->files->all();
411-
412-
$files = is_array($files) ? array_filter($files) : $files;
410+
$files = array_filter($from->files->all());
413411

414412
$request->initialize(
415413
$from->query->all(),

src/Illuminate/Pagination/Cursor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function encode()
113113
*/
114114
public static function fromEncoded($encodedString)
115115
{
116-
if (is_null($encodedString) || ! is_string($encodedString)) {
116+
if (! is_string($encodedString)) {
117117
return null;
118118
}
119119

src/Illuminate/Session/Store.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function readFromHandler()
110110
$data = @unserialize($this->prepareForUnserialize($data));
111111
}
112112

113-
if ($data !== false && ! is_null($data) && is_array($data)) {
113+
if ($data !== false && is_array($data)) {
114114
return $data;
115115
}
116116
}

src/Illuminate/View/Compilers/Concerns/CompilesComponents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected function compileAware($expression)
185185
*/
186186
public static function sanitizeComponentAttribute($value)
187187
{
188-
if (is_object($value) && $value instanceof CanBeEscapedWhenCastToString) {
188+
if ($value instanceof CanBeEscapedWhenCastToString) {
189189
return $value->escapeWhenCastingToString();
190190
}
191191

0 commit comments

Comments
 (0)