Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Get rid of lots of useless conditions #41198

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
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)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$attribute has already been evaluated some lines before.

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$from->files->all() always return an array.


$request->initialize(
$from->query->all(),
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Pagination/Cursor.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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