Skip to content

Commit

Permalink
chore: cs (#140)
Browse files Browse the repository at this point in the history
* chore: cs

* satisfy phpstan
  • Loading branch information
priyadi authored Sep 4, 2024
1 parent 51da198 commit 9ab08d3
Show file tree
Hide file tree
Showing 50 changed files with 104 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="php-cs-fixer" version="^3.59.3" installed="3.59.3" location="./tools/php-cs-fixer" copy="false"/>
<phar name="php-cs-fixer" version="^3.64.0" installed="3.64.0" location="./tools/php-cs-fixer" copy="false"/>
</phive>
51 changes: 22 additions & 29 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,36 @@
->in(__DIR__ . '/packages')
->in(__DIR__ . '/tests/bin')
->in(__DIR__ . '/tests/config')
->in(__DIR__ . '/tests/src')
;
->in(__DIR__ . '/tests/src');

$config = new PhpCsFixer\Config();
return $config->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],

// imports
'fully_qualified_strict_types' => true,
'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],
'no_leading_import_slash' => true,
'no_unneeded_import_alias' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['const', 'class', 'function']
],
'single_line_after_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'declare_strict_types' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'header_comment' => [
'header' => <<<EOF
'@PER-CS2.0' => true,
'@PER-CS2.0:risky' => true,
'fully_qualified_strict_types' => true,
'global_namespace_import' => [
'import_classes' => false,
'import_constants' => false,
'import_functions' => false,
],
'no_unneeded_import_alias' => true,
'no_unused_imports' => true,
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => ['class', 'function', 'const']
],
'declare_strict_types' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'header_comment' => [
'header' => <<<EOF
This file is part of rekalogika/collections package.
(c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
For the full copyright and license information, please view the LICENSE file
that was distributed with this source code.
EOF,
]
])
]
])
->setFinder($finder)
;
;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"doctrine/doctrine-fixtures-bundle": "^3.6",
"doctrine/persistence": "^3.1",
"ekino/phpstan-banned-code": "^1.0 || ^2.0",
"phpstan/phpstan": "^1.10.66 || ^1.11",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.4",
"phpunit/phpunit": "^10.1",
Expand Down
4 changes: 1 addition & 3 deletions packages/collections-common/src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

final class Configuration
{
private function __construct()
{
}
private function __construct() {}

/**
* If the collection has more than this number of items, a deprecation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class PrecountingStrategy implements CountStrategy
/**
* @param ?int<0,max> $count
*/
public function __construct(private ?int &$count)
{
}
public function __construct(private ?int &$count) {}

#[\Override]
public function getCount(?\Countable $underlyingObject): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function __construct(
private readonly ?int $softLimit = null,
private readonly ?int $hardLimit = null,
private readonly ?float $durationThreshold = null,
) {
}
) {}

#[\Override]
public function getCount(?\Countable $underlyingObject): int
Expand All @@ -42,11 +41,11 @@ public function getCount(?\Countable $underlyingObject): int
$duration = microtime(true) - $start;

if ($result > $hardLimit) {
throw new GettingCountUnsupportedException(sprintf('The count exceeds the threshold of %d. You should refactor and use other counting strategy. Count duration: %d s', $hardLimit, $duration));
throw new GettingCountUnsupportedException(\sprintf('The count exceeds the threshold of %d. You should refactor and use other counting strategy. Count duration: %d s', $hardLimit, $duration));
} elseif ($result > $softLimit) {
@trigger_error(sprintf('The count exceeds the warning threshold of %d. As it might impact performance, you should refactor and use other counting strategy. Count duration: %d s.', $softLimit, $duration), \E_USER_DEPRECATED);
@trigger_error(\sprintf('The count exceeds the warning threshold of %d. As it might impact performance, you should refactor and use other counting strategy. Count duration: %d s.', $softLimit, $duration), \E_USER_DEPRECATED);
} elseif ($duration > $durationThreshold) {
@trigger_error(sprintf('The count duration is %d s. You should consider refactoring and using other counting strategy.', $duration), \E_USER_DEPRECATED);
@trigger_error(\sprintf('The count duration is %d s. You should consider refactoring and using other counting strategy.', $duration), \E_USER_DEPRECATED);
}

return $result;
Expand Down
4 changes: 1 addition & 3 deletions packages/collections-common/src/Count/ZeroCountStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ public function getCount(?\Countable $underlyingObject): int
}

#[\Override]
public function setCount(?\Countable $underlyingObject, int $count): void
{
}
public function setCount(?\Countable $underlyingObject, int $count): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use Rekalogika\Contracts\Collections\Exception\BadMethodCallException;

class GettingCountUnsupportedException extends BadMethodCallException
{
}
class GettingCountUnsupportedException extends BadMethodCallException {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use Rekalogika\Contracts\Collections\Exception\UnexpectedValueException;

class InvalidCountException extends UnexpectedValueException
{
}
class InvalidCountException extends UnexpectedValueException {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@

use Rekalogika\Contracts\Collections\Exception\BadMethodCallException;

class SettingCountUnsupportedException extends BadMethodCallException
{
}
class SettingCountUnsupportedException extends BadMethodCallException {}
12 changes: 5 additions & 7 deletions packages/collections-common/src/Internal/ParameterUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,35 @@
*/
final class ParameterUtil
{
private function __construct()
{
}
private function __construct() {}

public static function getDefaultCountStrategyForFullClasses(): CountStrategy
{
$closure = Configuration::$defaultCountStrategyForFullClasses
?? fn (): CountStrategy => new SafeDelegatedCountStrategy();
?? fn(): CountStrategy => new SafeDelegatedCountStrategy();

return $closure();
}

public static function getDefaultCountStrategyForMinimalClasses(): CountStrategy
{
$closure = Configuration::$defaultCountStrategyForMinimalClasses
?? fn (): CountStrategy => new DisabledCountStrategy();
?? fn(): CountStrategy => new DisabledCountStrategy();

return $closure();
}

public static function getDefaultKeyTransformer(): KeyTransformer
{
$closure = Configuration::$defaultKeyTransformer
?? fn (): KeyTransformer => DefaultKeyTransformer::create();
?? fn(): KeyTransformer => DefaultKeyTransformer::create();

return $closure();
}

public static function transformInputToKey(
?KeyTransformer $keyTransformer,
mixed $input
mixed $input,
): int|string {
$keyTransformer ??= self::getDefaultKeyTransformer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public static function create(): self
return self::$instance ??= new self();
}

private function __construct()
{
}
private function __construct() {}

#[\Override]
public function transformToKey(mixed $key): int|string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public static function create(): self
return self::$instance ??= new self();
}

private function __construct()
{
}
private function __construct() {}

#[\Override]
public function transformToKey(mixed $key): int|string
Expand Down
2 changes: 1 addition & 1 deletion packages/collections-common/src/Trait/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ final public function partition(\Closure $p): array
{
$result = $this->getSafeCollection()->partition($p);

if (!\is_array($result) || \count($result) !== 2 || !$result[0] instanceof Collection || !$result[1] instanceof Collection) {
if (!\is_array($result) || \count($result) !== 2) {
throw new \RuntimeException('Unexpected return type from partition');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface
{
}
class BadMethodCallException extends \BadMethodCallException implements ExceptionInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

interface ExceptionInterface extends \Throwable
{
}
interface ExceptionInterface extends \Throwable {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

class LogicException extends \LogicException implements ExceptionInterface
{
}
class LogicException extends \LogicException implements ExceptionInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NotFoundException extends RuntimeException
public function __construct(
string $message = 'Not found',
int $code = 0,
\Throwable $previous = null
\Throwable $previous = null,
) {
parent::__construct($message, $code, $previous);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

class OverflowException extends \OverflowException implements ExceptionInterface
{
}
class OverflowException extends \OverflowException implements ExceptionInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
class RuntimeException extends \RuntimeException implements ExceptionInterface {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@

namespace Rekalogika\Contracts\Collections\Exception;

class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface
{
}
class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface {}
4 changes: 1 addition & 3 deletions packages/collections-contracts/src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@
* @extends ReadableRepository<TKey,T>
* @extends Recollection<TKey,T>
*/
interface Repository extends ReadableRepository, Recollection
{
}
interface Repository extends ReadableRepository, Recollection {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Doctrine\Common\Collections\Expr\Comparison;
use Doctrine\Common\Collections\Expr\CompositeExpression;

use Doctrine\Common\Collections\Expr\ExpressionVisitor;
use Doctrine\Common\Collections\Expr\Value;
use Rekalogika\Contracts\Collections\Exception\UnexpectedValueException;
Expand Down Expand Up @@ -69,7 +68,7 @@ public static function getObjectFieldValue(object|array $object, string $field)
public static function sortByField(string $name, int $orientation = 1, \Closure|null $next = null)
{
if ($next === null) {
$next = static fn (): int => 0;
$next = static fn(): int => 0;
}

return static function ($a, $b) use ($name, $next, $orientation): int {
Expand All @@ -95,12 +94,12 @@ public function walkComparison(Comparison $comparison)
$value = $comparison->getValue()->getValue();

return match ($comparison->getOperator()) {
Comparison::EQ => static fn ($object): bool => static::getObjectFieldValue($object, $field) === $value,
Comparison::NEQ => static fn ($object): bool => static::getObjectFieldValue($object, $field) !== $value,
Comparison::LT => static fn ($object): bool => static::getObjectFieldValue($object, $field) < $value,
Comparison::LTE => static fn ($object): bool => static::getObjectFieldValue($object, $field) <= $value,
Comparison::GT => static fn ($object): bool => static::getObjectFieldValue($object, $field) > $value,
Comparison::GTE => static fn ($object): bool => static::getObjectFieldValue($object, $field) >= $value,
Comparison::EQ => static fn($object): bool => static::getObjectFieldValue($object, $field) === $value,
Comparison::NEQ => static fn($object): bool => static::getObjectFieldValue($object, $field) !== $value,
Comparison::LT => static fn($object): bool => static::getObjectFieldValue($object, $field) < $value,
Comparison::LTE => static fn($object): bool => static::getObjectFieldValue($object, $field) <= $value,
Comparison::GT => static fn($object): bool => static::getObjectFieldValue($object, $field) > $value,
Comparison::GTE => static fn($object): bool => static::getObjectFieldValue($object, $field) >= $value,
Comparison::IN => static function ($object) use ($field, $value): bool {
$fieldValue = static::getObjectFieldValue($object, $field);

Expand All @@ -111,7 +110,7 @@ public function walkComparison(Comparison $comparison)

return !\in_array($fieldValue, $value, \is_scalar($fieldValue));
},
Comparison::CONTAINS => static fn ($object): bool => str_contains((string) static::getObjectFieldValue($object, $field), (string) $value),
Comparison::CONTAINS => static fn($object): bool => str_contains((string) static::getObjectFieldValue($object, $field), (string) $value),
Comparison::MEMBER_OF => static function ($object) use ($field, $value): bool {
$fieldValues = static::getObjectFieldValue($object, $field);

Expand All @@ -121,8 +120,8 @@ public function walkComparison(Comparison $comparison)

return \in_array($value, $fieldValues, true);
},
Comparison::STARTS_WITH => static fn ($object): bool => str_starts_with((string) static::getObjectFieldValue($object, $field), (string) $value),
Comparison::ENDS_WITH => static fn ($object): bool => str_ends_with((string) static::getObjectFieldValue($object, $field), (string) $value),
Comparison::STARTS_WITH => static fn($object): bool => str_starts_with((string) static::getObjectFieldValue($object, $field), (string) $value),
Comparison::ENDS_WITH => static fn($object): bool => str_ends_with((string) static::getObjectFieldValue($object, $field), (string) $value),
default => throw new \RuntimeException('Unknown comparison operator: ' . $comparison->getOperator()),
};
}
Expand Down Expand Up @@ -187,6 +186,6 @@ private function orExpressions(array $expressions): \Closure
/** @param callable[] $expressions */
private function notExpression(array $expressions): \Closure
{
return static fn ($object): bool => !$expressions[0]($object);
return static fn($object): bool => !$expressions[0]($object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
*/
final class ExtraLazyDetector
{
private function __construct()
{
}
private function __construct() {}

/**
* @template TKey of array-key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final private function __construct(

$this->orderBy = ParameterUtil::normalizeOrderBy(
orderBy: $orderBy,
defaultOrderBy: $this->getDefaultOrderBy()
defaultOrderBy: $this->getDefaultOrderBy(),
);

$this->criteria = Criteria::create()->orderBy($this->orderBy);
Expand Down
Loading

0 comments on commit 9ab08d3

Please sign in to comment.