Skip to content
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
16 changes: 10 additions & 6 deletions .github/workflows/rector.yml → .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Rector + PHP CS Fixer

on:
pull_request_target:
paths-ignore:
Expand All @@ -9,16 +11,18 @@ on:
- 'infection.json.dist'
- 'psalm.xml'

name: rector
permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
os: >-
['ubuntu-latest']
php: >-
['8.5']
php: '8.1'
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ composer.phar
/phpunit.xml
/.phpunit.cache

# PHP CS Fixer
/.php-cs-fixer.cache

# po4a .mo files
*.mo
*.mo
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return (new Config())
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PER-CS3.0' => true,
'no_unused_imports' => true,
'ordered_class_elements' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8.3",
"friendsofphp/php-cs-fixer": "^3.91",
"jetbrains/phpstorm-attributes": "^1.2",
"maglnet/composer-require-checker": "^4.7.1",
"phpbench/phpbench": "^1.4.1",
Expand Down Expand Up @@ -93,6 +94,7 @@
"rector": "vendor/bin/rector process",
"infection": "vendor/bin/infection",
"dry-run": "vendor/bin/rector process --dry-run",
"psalm": "vendor/bin/psalm --config=psalm.xml"
"psalm": "vendor/bin/psalm --config=psalm.xml",
"cs-fix": "php-cs-fixer fix"
}
}
6 changes: 3 additions & 3 deletions src/CountableLimitInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface CountableLimitInterface
*
* @see getLessThanMinMessage() for related error message.
*/
public function getMin(): int|null;
public function getMin(): ?int;

/**
* Returns current maximum limit.
Expand All @@ -29,7 +29,7 @@ public function getMin(): int|null;
*
* @see getGreaterThanMaxMessage() for related error message.
*/
public function getMax(): int|null;
public function getMax(): ?int;

/**
* Returns current "exactly" value meant for strict comparison. It is a shortcut for the case when {@see getMin()}
Expand All @@ -40,7 +40,7 @@ public function getMax(): int|null;
*
* @see getNotExactlyMessage() for related error message
*/
public function getExactly(): int|null;
public function getExactly(): ?int;

/**
* Returns message used when a validated value is less than minimum set in {@see getMin()}.
Expand Down
3 changes: 1 addition & 2 deletions src/DataSet/ArrayDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public function __construct(
* @var array A mapping between property names and their values.
*/
private array $data = [],
) {
}
) {}

/**
* Returns a property value by its name.
Expand Down
8 changes: 4 additions & 4 deletions src/DataSet/ObjectDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,17 @@
* @var object An object containing rules and data.
*/
private readonly object $object,
int $propertyVisibility = ReflectionProperty::IS_PRIVATE |
ReflectionProperty::IS_PROTECTED |
ReflectionProperty::IS_PUBLIC,
int $propertyVisibility = ReflectionProperty::IS_PRIVATE
| ReflectionProperty::IS_PROTECTED
| ReflectionProperty::IS_PUBLIC,
bool $useCache = true,
) {
$this->dataSetProvided = $this->object instanceof DataSetInterface;
$this->rulesProvided = $this->object instanceof RulesProviderInterface;
$this->parser = new ObjectParser(
source: $object,
propertyVisibility: $propertyVisibility,
useCache: $useCache
useCache: $useCache,
);
}

Expand Down Expand Up @@ -237,7 +237,7 @@
}

// Merge rules from `RulesProviderInterface` implementation and parsed from PHP attributes.
$rules = $rules instanceof Traversable ? iterator_to_array($rules) : $rules;

Check warning on line 240 in src/DataSet/ObjectDataSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Ternary": @@ @@ return $rules; } // Merge rules from `RulesProviderInterface` implementation and parsed from PHP attributes. - $rules = $rules instanceof Traversable ? iterator_to_array($rules) : $rules; + $rules = $rules instanceof Traversable ? $rules : iterator_to_array($rules); foreach ($this->parser->getRules() as $key => $value) { if (is_int($key)) { array_unshift($rules, $value);

Check warning on line 240 in src/DataSet/ObjectDataSet.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "InstanceOf_": @@ @@ return $rules; } // Merge rules from `RulesProviderInterface` implementation and parsed from PHP attributes. - $rules = $rules instanceof Traversable ? iterator_to_array($rules) : $rules; + $rules = !$rules instanceof Traversable ? iterator_to_array($rules) : $rules; foreach ($this->parser->getRules() as $key => $value) { if (is_int($key)) { array_unshift($rules, $value);
foreach ($this->parser->getRules() as $key => $value) {
if (is_int($key)) {
array_unshift($rules, $value);
Expand Down
3 changes: 1 addition & 2 deletions src/DataSet/SingleValueDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public function __construct(
* @var mixed Single value of any (mixed) data type.
*/
private readonly mixed $value,
) {
}
) {}

/**
* Returns a property value by its name. {@see SingleValueDataSet} does not support properties so `null` is always
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/ValidatorCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
return;
}

if ($rules instanceof Traversable) {

Check warning on line 29 in src/Debug/ValidatorCollector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "InstanceOf_": @@ @@ if (!$this->isActive()) { return; } - if ($rules instanceof Traversable) { + if (!$rules instanceof Traversable) { $rules = iterator_to_array($rules); } $this->validations[] = ['value' => $value, 'rules' => $rules, 'result' => $result->isValid(), 'errors' => $result->getErrors()];
$rules = iterator_to_array($rules);
}

Expand All @@ -46,7 +46,7 @@
}

$count = count($this->validations);
$countValid = count(array_filter($this->validations, fn (array $data): bool => (bool)$data['result']));
$countValid = count(array_filter($this->validations, fn(array $data): bool => (bool) $data['result']));

Check warning on line 49 in src/Debug/ValidatorCollector.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "CastBool": @@ @@ return []; } $count = count($this->validations); - $countValid = count(array_filter($this->validations, fn(array $data): bool => (bool) $data['result'])); + $countValid = count(array_filter($this->validations, fn(array $data): bool => $data['result'])); $countInvalid = $count - $countValid; return ['total' => $count, 'valid' => $countValid, 'invalid' => $countInvalid]; }
$countInvalid = $count - $countValid;

return [
Expand Down
5 changes: 2 additions & 3 deletions src/Debug/ValidatorInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ final class ValidatorInterfaceProxy implements ValidatorInterface
public function __construct(
private readonly ValidatorInterface $validator,
private readonly ValidatorCollector $collector,
) {
}
) {}

public function validate(
mixed $data,
callable|iterable|object|string|null $rules = null,
?ValidationContext $context = null
?ValidationContext $context = null,
): Result {
$result = $this->validator->validate($data, $rules, $context);

Expand Down
3 changes: 1 addition & 2 deletions src/EmptyCondition/WhenEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function __construct(
* meaning no trimming is done.
*/
private readonly bool $trimString = false,
) {
}
) {}

/**
* @param mixed $value The validated value.
Expand Down
2 changes: 1 addition & 1 deletion src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getParameters(): array
* @return array A list of keys for nested structures or an empty array otherwise.
* @psalm-return list<int|string>
*/
public function getValuePath(string|null $escape = null): array
public function getValuePath(?string $escape = null): array
{
if ($escape === null) {
return $this->valuePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class_exists($type)
RuleHandlerInterface::class,
),
$code,
$previous
$previous,
);
}
}
2 changes: 1 addition & 1 deletion src/Exception/UnexpectedRuleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
sprintf(
'Expected "%s", but "%s" given.',
implode('", "', (array) $expectedClassName),
$actualObject::class
$actualObject::class,
),
$code,
$previous,
Expand Down
5 changes: 2 additions & 3 deletions src/Helper/MessageProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ public function __construct(
private readonly string $translationCategory,
private readonly MessageFormatterInterface $messageFormatter,
private readonly string $messageFormatterLocale,
) {
}
) {}

public function process(Error $error): string
{
return match ($error->getMessageProcessing()) {
Error::MESSAGE_TRANSLATE => $this->translator->translate(
$error->getMessage(),
$error->getParameters(),
$this->translationCategory
$this->translationCategory,
),
Error::MESSAGE_FORMAT => $this->messageFormatter->format(
$error->getMessage(),
Expand Down
10 changes: 5 additions & 5 deletions src/Helper/ObjectParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
/**
* @var string|null A cache key. Dynamically generated on instantiation.
*/
private string|null $cacheKey = null;
private ?string $cacheKey = null;

/**
* @throws InvalidArgumentException If a class name string provided in {@see $source} refers to a non-existing
Expand All @@ -163,9 +163,9 @@
*
* @psalm-var int-mask-of<ReflectionProperty::IS_*>
*/
private readonly int $propertyVisibility = ReflectionProperty::IS_PRIVATE |
ReflectionProperty::IS_PROTECTED |
ReflectionProperty::IS_PUBLIC,
private readonly int $propertyVisibility = ReflectionProperty::IS_PRIVATE
| ReflectionProperty::IS_PROTECTED
| ReflectionProperty::IS_PUBLIC,
/**
* @var bool Whether the properties with "static" modifier must be skipped.
*/
Expand All @@ -179,7 +179,7 @@
/** @var object|string $source */
if (is_string($source) && !class_exists($source)) {
throw new InvalidArgumentException(
sprintf('Class "%s" not found.', $source)
sprintf('Class "%s" not found.', $source),
);
}

Expand Down Expand Up @@ -320,7 +320,7 @@
$data = [];
foreach ($this->getReflectionProperties() as $name => $property) {
if (!$property->isInitialized($this->source)) {
continue;

Check warning on line 323 in src/Helper/ObjectParser.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Continue_": @@ @@ $data = []; foreach ($this->getReflectionProperties() as $name => $property) { if (!$property->isInitialized($this->source)) { - continue; + break; } /** @var mixed */ $data[$name] = $property->getValue($this->source);
}
/** @var mixed */
$data[$name] = $property->getValue($this->source);
Expand Down Expand Up @@ -381,7 +381,7 @@
{
if ($this->hasCacheItem('reflectionSource')) {
/** @var ReflectionClass|ReflectionObject */
return $this->getCacheItem('reflectionSource');

Check warning on line 384 in src/Helper/ObjectParser.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ private function getReflectionSource(): ReflectionObject|ReflectionClass { if ($this->hasCacheItem('reflectionSource')) { - /** @var ReflectionClass|ReflectionObject */ - return $this->getCacheItem('reflectionSource'); + } $reflectionSource = is_object($this->source) ? new ReflectionObject($this->source) : new ReflectionClass($this->source); $this->setCacheItem('reflectionSource', $reflectionSource);
}

$reflectionSource = is_object($this->source)
Expand Down Expand Up @@ -451,7 +451,7 @@
string $name,
): bool {
if (!$this->useCache()) {
return false;

Check warning on line 454 in src/Helper/ObjectParser.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ ): bool { if (!$this->useCache()) { - return false; + } if (!array_key_exists($this->cacheKey, self::$cache)) { return false;
}

if (!array_key_exists($this->cacheKey, self::$cache)) {
Expand Down Expand Up @@ -488,7 +488,7 @@
mixed $value,
): void {
if (!$this->useCache()) {
return;

Check warning on line 491 in src/Helper/ObjectParser.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ ): void { if (!$this->useCache()) { - return; + } /** @psalm-suppress PossiblyNullArrayOffset, MixedAssignment */ self::$cache[$this->cacheKey][$name] = $value;
}

/** @psalm-suppress PossiblyNullArrayOffset, MixedAssignment */
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/RulesNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function normalize(
sprintf(
'A property can only have an integer or a string type. %s given.',
get_debug_type($property),
)
),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Helper/RulesNormalizerIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ private static function normalizeRule(mixed $rule, ?callable $defaultSkipOnEmpty
sprintf(
'Rule must be either an instance of %s or a callable, %s given.',
RuleInterface::class,
get_debug_type($rule)
)
get_debug_type($rule),
),
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class Label
{
public function __construct(
private readonly string $label,
) {
}
) {}

public function getLabel(): string
{
Expand Down
3 changes: 1 addition & 2 deletions src/PropertyTranslator/ArrayPropertyTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class ArrayPropertyTranslator implements PropertyTranslatorInterface
*/
public function __construct(
private array $translations,
) {
}
) {}

public function translate(string $property): string
{
Expand Down
3 changes: 1 addition & 2 deletions src/PropertyTranslator/TranslatorPropertyTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ final class TranslatorPropertyTranslator implements PropertyTranslatorInterface
*/
public function __construct(
private readonly TranslatorInterface $translator,
) {
}
) {}

public function translate(string $property): string
{
Expand Down
Loading
Loading