From 2aca0fc5a641cd8a67656d42363aa4e0a19afd22 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 12 Jun 2024 14:47:21 +0200 Subject: [PATCH] Fix yoda style --- .php-cs-fixer.dist.php | 7 ++++++- src/Entity/Accounting.php | 2 +- src/Entity/SystemVariable.php | 4 ++-- src/Entity/User.php | 2 +- src/Library/Benzina/Pump/Trait/ArrayPumpTrait.php | 2 +- src/Library/Benzina/Pump/Trait/ProgressivePumpTrait.php | 2 +- src/Library/Benzina/Stream/Stream.php | 6 +++--- src/Security/Hasher/LegacyPasswordHasher.php | 2 +- src/Validator/GatewayNameValidator.php | 2 +- 9 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 02d631f..b8c750c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,6 +7,11 @@ $finder = (new PhpCsFixer\Finder()) return (new PhpCsFixer\Config()) ->setRules([ '@Symfony' => true, - 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'] + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + 'yoda_style' => [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false + ] ]) ->setFinder($finder); diff --git a/src/Entity/Accounting.php b/src/Entity/Accounting.php index 9ec2ced..3accca3 100644 --- a/src/Entity/Accounting.php +++ b/src/Entity/Accounting.php @@ -116,7 +116,7 @@ class Accounting { // ensure ownership does not change if ( - null !== $this->ownerClass + $this->ownerClass !== null && $this->ownerClass !== $ownerClass ) { throw new \Exception('Are you trying to commit fraud? Cannot change ownership of an Accounting.'); diff --git a/src/Entity/SystemVariable.php b/src/Entity/SystemVariable.php index fde103b..b9a5ae6 100644 --- a/src/Entity/SystemVariable.php +++ b/src/Entity/SystemVariable.php @@ -50,11 +50,11 @@ class SystemVariable return "int:$value"; } - if (\is_bool($value) && true === $value) { + if (\is_bool($value) && $value === true) { return 'bool:true'; } - if (\is_bool($value) && false === $value) { + if (\is_bool($value) && $value === false) { return 'bool:false'; } diff --git a/src/Entity/User.php b/src/Entity/User.php index 81aa128..58fdbe7 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -193,7 +193,7 @@ class User implements UserInterface, UserOwnedInterface, PasswordAuthenticatedUs public function hasRoles(array $roles): bool { - return 0 < count(array_intersect($this->getRoles(), $roles)); + return count(array_intersect($this->getRoles(), $roles)) > 0; } /** diff --git a/src/Library/Benzina/Pump/Trait/ArrayPumpTrait.php b/src/Library/Benzina/Pump/Trait/ArrayPumpTrait.php index db28404..287bd62 100644 --- a/src/Library/Benzina/Pump/Trait/ArrayPumpTrait.php +++ b/src/Library/Benzina/Pump/Trait/ArrayPumpTrait.php @@ -12,7 +12,7 @@ trait ArrayPumpTrait */ public function hasAllKeys(array $data, array $keys): bool { - if (0 === count(\array_diff($keys, \array_keys($data)))) { + if (count(\array_diff($keys, \array_keys($data))) === 0) { return true; } diff --git a/src/Library/Benzina/Pump/Trait/ProgressivePumpTrait.php b/src/Library/Benzina/Pump/Trait/ProgressivePumpTrait.php index b3e0fcd..183c35d 100644 --- a/src/Library/Benzina/Pump/Trait/ProgressivePumpTrait.php +++ b/src/Library/Benzina/Pump/Trait/ProgressivePumpTrait.php @@ -63,7 +63,7 @@ trait ProgressivePumpTrait { if ( \array_key_exists('progress', $this->config) - && false === $this->config['progress'] + && $this->config['progress'] === false ) { return false; } diff --git a/src/Library/Benzina/Stream/Stream.php b/src/Library/Benzina/Stream/Stream.php index 555ca74..39f3623 100644 --- a/src/Library/Benzina/Stream/Stream.php +++ b/src/Library/Benzina/Stream/Stream.php @@ -43,7 +43,7 @@ class Stream implements StreamInterface throw new \RuntimeException('Length parameter cannot be negative'); } - if (0 === $size) { + if ($size === 0) { return ''; } @@ -53,7 +53,7 @@ class Stream implements StreamInterface throw new \RuntimeException(self::MESSAGE_ERROR_UNABLE_TO_READ, 0, $e); } - if (false === $string) { + if ($string === false) { throw new \RuntimeException(self::MESSAGE_ERROR_UNABLE_TO_READ); } @@ -66,7 +66,7 @@ class Stream implements StreamInterface throw new \RuntimeException(self::MESSAGE_ERROR_DETACHED); } - return ftell($this->stream); + return \ftell($this->stream); } public function size(): int diff --git a/src/Security/Hasher/LegacyPasswordHasher.php b/src/Security/Hasher/LegacyPasswordHasher.php index f0a0b49..0b8074a 100644 --- a/src/Security/Hasher/LegacyPasswordHasher.php +++ b/src/Security/Hasher/LegacyPasswordHasher.php @@ -48,6 +48,6 @@ class LegacyPasswordHasher implements PasswordHasherInterface private function isOldBcrypt(string $str): bool { - return 0 === strpos($str, '$1$'); + return strpos($str, '$1$') === 0; } } diff --git a/src/Validator/GatewayNameValidator.php b/src/Validator/GatewayNameValidator.php index ff828e1..caec861 100644 --- a/src/Validator/GatewayNameValidator.php +++ b/src/Validator/GatewayNameValidator.php @@ -18,7 +18,7 @@ class GatewayNameValidator extends ChoiceValidator { /* @var App\Validator\GatewayName $constraint */ - if (null === $value || '' === $value) { + if ($value === null || $value === '') { return; }