Skip to content

Commit

Permalink
Code Style
Browse files Browse the repository at this point in the history
  • Loading branch information
wjzijderveld committed Mar 8, 2024
1 parent d632aff commit 0f4df45
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 43 deletions.
3 changes: 2 additions & 1 deletion lib/Qandidate/Toggle/Operator/GreaterThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

/**
* @template T
* @template-extends EqualityOperator<T>
*
* @template-extends EqualityOperator<T>
*/
class GreaterThan extends EqualityOperator
{
Expand Down
3 changes: 2 additions & 1 deletion lib/Qandidate/Toggle/Operator/GreaterThanEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

/**
* @template T
* @template-extends EqualityOperator<T>
*
* @template-extends EqualityOperator<T>
*/
class GreaterThanEqual extends EqualityOperator
{
Expand Down
6 changes: 2 additions & 4 deletions lib/Qandidate/Toggle/Operator/HasIntersection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

namespace Qandidate\Toggle\Operator;

use InvalidArgumentException;


/**
* @template T
*
* @template-extends EqualityOperator<T>
*/
class HasIntersection extends EqualityOperator
Expand All @@ -32,7 +30,7 @@ public function __construct(private readonly array $values)
public function appliesTo(mixed $argument): bool
{
if (!is_array($argument)) {
throw new InvalidArgumentException('HasIntersection can only be compared against array values');
throw new \InvalidArgumentException('HasIntersection can only be compared against array values');
}

return null !== $argument
Expand Down
3 changes: 2 additions & 1 deletion lib/Qandidate/Toggle/Operator/LessThan.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

/**
* @template T
* @template-extends EqualityOperator<T>
*
* @template-extends EqualityOperator<T>
*/
class LessThan extends EqualityOperator
{
Expand Down
3 changes: 2 additions & 1 deletion lib/Qandidate/Toggle/Operator/LessThanEqual.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

/**
* @template T
* @template-extends EqualityOperator<T>
*
* @template-extends EqualityOperator<T>
*/
class LessThanEqual extends EqualityOperator
{
Expand Down
7 changes: 2 additions & 5 deletions lib/Qandidate/Toggle/Operator/MatchesRegex.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@

namespace Qandidate\Toggle\Operator;

use InvalidArgumentException;


/**
* @template-extends EqualityOperator<string>
* @template-extends EqualityOperator<string>
*/
class MatchesRegex extends EqualityOperator
{
public function appliesTo(mixed $argument): bool
{
if (!is_string($argument)) {
throw new InvalidArgumentException('MatchesRegex can only be matched against strings');
throw new \InvalidArgumentException('MatchesRegex can only be matched against strings');
}

return (bool) preg_match($this->value, $argument);
Expand Down
1 change: 1 addition & 0 deletions lib/Qandidate/Toggle/Operator/NotInSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/**
* @template T
*
* @extends InSet<T>
*/
class NotInSet extends InSet
Expand Down
3 changes: 1 addition & 2 deletions lib/Qandidate/Toggle/Operator/Percentage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Qandidate\Toggle\Operator;

use InvalidArgumentException;
use Qandidate\Toggle\Operator;

class Percentage implements Operator
Expand All @@ -25,7 +24,7 @@ public function __construct(private readonly int $percentage, private readonly i
public function appliesTo(mixed $argument): bool
{
if (!is_int($argument)) {
throw new InvalidArgumentException('Percentage only accepts integers');
throw new \InvalidArgumentException('Percentage only accepts integers');
}

$asPercentage = (int) $argument % 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Qandidate\Toggle\Serializer;

use RuntimeException;
use Qandidate\Toggle\OperatorCondition;

/**
Expand Down Expand Up @@ -41,7 +40,7 @@ public function deserialize(array $condition): OperatorCondition
$this->assertHasKey('operator', $condition);

if ('operator-condition' !== $condition['name']) {
throw new RuntimeException(sprintf('Unable to deserialize operator with name "%s".', $condition['name']));
throw new \RuntimeException(sprintf('Unable to deserialize operator with name "%s".', $condition['name']));
}

$operator = $this->operatorSerializer->deserialize($condition['operator']);
Expand All @@ -52,7 +51,7 @@ public function deserialize(array $condition): OperatorCondition
private function assertHasKey(string $key, array $data): void
{
if (!array_key_exists($key, $data)) {
throw new RuntimeException(sprintf('Missing key "%s" in data.', $key));
throw new \RuntimeException(sprintf('Missing key "%s" in data.', $key));
}
}
}
7 changes: 3 additions & 4 deletions lib/Qandidate/Toggle/Serializer/OperatorSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Qandidate\Toggle\Serializer;

use RuntimeException;
use Qandidate\Toggle\Operator;
use Qandidate\Toggle\Operator\EqualTo;
use Qandidate\Toggle\Operator\GreaterThan;
Expand Down Expand Up @@ -55,7 +54,7 @@ public function serialize(Operator $operator): array
case MatchesRegex::class:
return ['name' => 'matches-regex', 'value' => $operator->getValue()];
default:
throw new RuntimeException(sprintf('Unknown operator %s.', $operator::class));
throw new \RuntimeException(sprintf('Unknown operator %s.', $operator::class));
}
}

Expand Down Expand Up @@ -107,14 +106,14 @@ public function deserialize(array $operator): Operator

return new MatchesRegex($operator['value']);
default:
throw new RuntimeException(sprintf('Unknown operator with name "%s".', $operator['name']));
throw new \RuntimeException(sprintf('Unknown operator with name "%s".', $operator['name']));
}
}

private function assertHasKey(string $key, array $data): void
{
if (!array_key_exists($key, $data)) {
throw new RuntimeException(sprintf('Missing key "%s" in data.', $key));
throw new \RuntimeException(sprintf('Missing key "%s" in data.', $key));
}
}
}
16 changes: 7 additions & 9 deletions lib/Qandidate/Toggle/Serializer/ToggleSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Qandidate\Toggle\Serializer;

use RuntimeException;
use InvalidArgumentException;
use Qandidate\Toggle\OperatorCondition;
use Qandidate\Toggle\Toggle;

Expand Down Expand Up @@ -43,7 +41,7 @@ public function deserialize(array $data): Toggle
$this->assertHasKey('conditions', $data);

if (!is_array($data['conditions'])) {
throw new RuntimeException('Key "conditions" should be an array.');
throw new \RuntimeException('Key "conditions" should be an array.');
}

$toggle = new Toggle(
Expand All @@ -65,7 +63,7 @@ private function serializeConditions(array $conditions): array

foreach ($conditions as $condition) {
if (!$condition instanceof OperatorCondition) {
throw new RuntimeException(sprintf('Unable to serialize %s.', $condition::class));
throw new \RuntimeException(sprintf('Unable to serialize %s.', $condition::class));
}

$serialized[] = $this->operatorConditionSerializer->serialize($condition);
Expand All @@ -91,7 +89,7 @@ private function serializeStatus(Toggle $toggle): string
Toggle::ALWAYS_ACTIVE => 'always-active',
Toggle::INACTIVE => 'inactive',
Toggle::CONDITIONALLY_ACTIVE => 'conditionally-active',
default => throw new InvalidArgumentException('unsupported status'),
default => throw new \InvalidArgumentException('unsupported status'),
};
}

Expand All @@ -112,7 +110,7 @@ private function deserializeStatus(Toggle $toggle, string $status): void
return;
}

throw new RuntimeException(sprintf('Unknown toggle status "%s".', $status));
throw new \RuntimeException(sprintf('Unknown toggle status "%s".', $status));
}

private function serializeStrategy(Toggle $toggle): string
Expand All @@ -121,7 +119,7 @@ private function serializeStrategy(Toggle $toggle): string
Toggle::STRATEGY_AFFIRMATIVE => 'affirmative',
Toggle::STRATEGY_MAJORITY => 'majority',
Toggle::STRATEGY_UNANIMOUS => 'unanimous',
default => throw new InvalidArgumentException('unsupported strategy'),
default => throw new \InvalidArgumentException('unsupported strategy'),
};
}

Expand All @@ -131,14 +129,14 @@ private function deserializeStrategy(string $strategy): int
'affirmative' => Toggle::STRATEGY_AFFIRMATIVE,
'majority' => Toggle::STRATEGY_MAJORITY,
'unanimous' => Toggle::STRATEGY_UNANIMOUS,
default => throw new RuntimeException(sprintf('Unknown toggle strategy "%s".', $strategy)),
default => throw new \RuntimeException(sprintf('Unknown toggle strategy "%s".', $strategy)),
};
}

private function assertHasKey(string $key, array $data): void
{
if (!array_key_exists($key, $data)) {
throw new RuntimeException(sprintf('Missing key "%s" in data.', $key));
throw new \RuntimeException(sprintf('Missing key "%s" in data.', $key));
}
}
}
5 changes: 2 additions & 3 deletions lib/Qandidate/Toggle/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Qandidate\Toggle;

use InvalidArgumentException;
/**
* Representation of a feature toggle.
*
Expand Down Expand Up @@ -110,7 +109,7 @@ public function getStrategy(): int
private function assertValidActiveStatus(int $status): void
{
if (self::ALWAYS_ACTIVE !== $status && self::CONDITIONALLY_ACTIVE !== $status) {
throw new InvalidArgumentException('No "active" status was provided.');
throw new \InvalidArgumentException('No "active" status was provided.');
}
}

Expand All @@ -121,7 +120,7 @@ private function assertValidStrategy(int $strategy): void
self::STRATEGY_MAJORITY,
self::STRATEGY_UNANIMOUS,
])) {
throw new InvalidArgumentException('No supported strategy was provided.');
throw new \InvalidArgumentException('No supported strategy was provided.');
}
}

Expand Down
12 changes: 5 additions & 7 deletions lib/Qandidate/Toggle/ToggleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Qandidate\Toggle;

use RuntimeException;
use InvalidArgumentException;
/**
* Manages the toggles of an application.
*/
Expand Down Expand Up @@ -63,18 +61,18 @@ public function update(Toggle $toggle): void
/**
* Rename the toggle.
*
* @throws RuntimeException
* @throws \RuntimeException
*/
public function rename(string $oldName, string $newName): void
{
if ($this->collection->get($newName) instanceof Toggle) {
throw new RuntimeException(sprintf('Could not rename toggle %1$s to %2$s, a toggle with name %2$s already exists', $oldName, $newName));
throw new \RuntimeException(sprintf('Could not rename toggle %1$s to %2$s, a toggle with name %2$s already exists', $oldName, $newName));
}

$currentToggle = $this->collection->get($oldName);

if (!$currentToggle instanceof Toggle) {
throw new RuntimeException(sprintf('Could not rename toggle %1$s to %2$s, toggle with name %1$s does not exists', $oldName, $newName));
throw new \RuntimeException(sprintf('Could not rename toggle %1$s to %2$s, toggle with name %1$s does not exists', $oldName, $newName));
}

$currentToggle->rename($newName);
Expand All @@ -94,13 +92,13 @@ public function all(): array
/**
* @return Toggle toggle from manager that has given name
*
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function get(string $name): Toggle
{
$toggle = $this->collection->get($name);
if (!$toggle instanceof Toggle) {
throw new InvalidArgumentException("Cannot find Toggle with name $name");
throw new \InvalidArgumentException("Cannot find Toggle with name $name");
}

return $toggle;
Expand Down
1 change: 1 addition & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
]);

$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
Expand Down
2 changes: 1 addition & 1 deletion test/Qandidate/Toggle/ExpressionConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Qandidate\Toggle;

use Symfony\Component\ExpressionLanguage\SyntaxError;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\SyntaxError;

class ExpressionConditionTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function tearDown(): void
}
}

public function createCollection()
public function createCollection(): PredisCollection
{
return $this->collection;
}
Expand Down

0 comments on commit 0f4df45

Please sign in to comment.