Skip to content

Commit

Permalink
Avoid yoda-style comparisons within the codebase. (#41175)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored Feb 22, 2022
1 parent 97d67e1 commit e6c510d
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ public function onSuccess(Closure $callback)
}

return $this->then(function (Container $container) use ($callback) {
if (0 === $this->exitCode) {
if ($this->exitCode === 0) {
$container->call($callback);
}
});
Expand Down Expand Up @@ -815,7 +815,7 @@ public function onFailure(Closure $callback)
}

return $this->then(function (Container $container) use ($callback) {
if (0 !== $this->exitCode) {
if ($this->exitCode !== 0) {
$container->call($callback);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ public function toJson($options = 0)
{
$json = json_encode($this->jsonSerialize(), $options);

if (JSON_ERROR_NONE !== json_last_error()) {
if (json_last_error() !== JSON_ERROR_NONE) {
throw JsonEncodingException::forModel($this, json_last_error_msg());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Resources/Json/JsonResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function toJson($options = 0)
{
$json = json_encode($this->jsonSerialize(), $options);

if (JSON_ERROR_NONE !== json_last_error()) {
if (json_last_error() !== JSON_ERROR_NONE) {
throw JsonEncodingException::forResource($this, json_last_error_msg());
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function createPayload($job, $queue, $data = '')

$payload = json_encode($this->createPayloadArray($job, $queue, $data), \JSON_UNESCAPED_UNICODE);

if (JSON_ERROR_NONE !== json_last_error()) {
if (json_last_error() !== JSON_ERROR_NONE) {
throw new InvalidPayloadException(
'Unable to JSON encode payload. Error code: '.json_last_error()
);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function jsonEncode($data, $flags = 0, $depth = 512)
*/
protected function convertJsonToJavaScriptExpression($json, $flags = 0)
{
if ('[]' === $json || '{}' === $json) {
if ($json === '[]' || $json === '{}') {
return $json;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Support/ProcessUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public static function escapeArgument($argument)
// @see https://bugs.php.net/bug.php?id=43784
// @see https://bugs.php.net/bug.php?id=49446
if ('\\' === DIRECTORY_SEPARATOR) {
if ('' === $argument) {
if ($argument === '') {
return '""';
}

$escapedArgument = '';
$quote = false;

foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
if ($part === '"') {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
// Avoid environment variable expansion
Expand Down Expand Up @@ -64,6 +64,6 @@ public static function escapeArgument($argument)
*/
protected static function isSurroundedBy($arg, $char)
{
return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
return strlen($arg) > 2 && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
}
}
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public function assertCookieExpired($cookieName)
$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime());

PHPUnit::assertTrue(
0 !== $cookie->getExpiresTime() && $expiresAt->lessThan(Carbon::now()),
$cookie->getExpiresTime() !== 0 && $expiresAt->lessThan(Carbon::now()),
"Cookie [{$cookieName}] is not expired, it expires at [{$expiresAt}]."
);

Expand All @@ -530,7 +530,7 @@ public function assertCookieNotExpired($cookieName)
$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime());

PHPUnit::assertTrue(
0 === $cookie->getExpiresTime() || $expiresAt->greaterThan(Carbon::now()),
$cookie->getExpiresTime() === 0 || $expiresAt->greaterThan(Carbon::now()),
"Cookie [{$cookieName}] is expired, it expired at [{$expiresAt}]."
);

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected static function summarize($validator)
$message = array_shift($messages);

if ($additional = count($messages)) {
$pluralized = 1 === $additional ? 'error' : 'errors';
$pluralized = $additional === 1 ? 'error' : 'errors';

$message .= " (and {$additional} more {$pluralized})";
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Cache/CacheEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected function assertEventMatches($eventClass, $properties = [])
}

foreach ($properties as $name => $value) {
if ($event->$name != $value) {
if ($value != $event->$name) {
return false;
}
}
Expand Down

0 comments on commit e6c510d

Please sign in to comment.