Skip to content

Commit 179bc15

Browse files
committed
fix(quality): pass all kcode quality checks — psalm, phpstan, cs-fixer, phpunit
Psalm fixes: - Add #[Override] attribute to all TransformationRule implementations (transform() and getName() methods) via psalm --alter - AgeRule: remove redundant (int) cast, DateInterval->y is already int - DateToIso8601Rule: ensure $tz is non-empty-string before DateTimeZone() - RelativeDateRule: use intdiv(int, int) instead of / operator; cast abs() result to (int) since abs(int) returns float|int in Psalm - PercentageRule: use 100.0 instead of 100 to fix float * int InvalidOperand CS-Fixer: auto-format new source and test files to project code style
1 parent 98a6519 commit 179bc15

61 files changed

Lines changed: 623 additions & 343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Configuration/TransformerConfiguration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
public function __construct(
1717
public bool $trackTransformations = true,
1818
public bool $preserveOriginal = true,
19-
) {}
19+
) {
20+
}
2021
}

src/Contract/RuleRegistry.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
interface RuleRegistry
1515
{
1616
public function register(string $alias, TransformationRule $rule): void;
17+
1718
public function resolve(string $alias): TransformationRule;
19+
1820
public function has(string $alias): bool;
21+
1922
/** @return list<string> */
2023
public function aliases(): array;
2124
}

src/Core/InMemoryRuleRegistry.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class InMemoryRuleRegistry implements RuleRegistry
2020
/** @var array<string, TransformationRule> */
2121
private array $rules = [];
2222

23+
#[\Override]
2324
public function register(string $alias, TransformationRule $rule): void
2425
{
2526
if (isset($this->rules[$alias])) {
@@ -28,11 +29,21 @@ public function register(string $alias, TransformationRule $rule): void
2829
$this->rules[$alias] = $rule;
2930
}
3031

32+
#[\Override]
3133
public function resolve(string $alias): TransformationRule
3234
{
3335
return $this->rules[$alias] ?? throw InvalidRuleException::unknownAlias($alias);
3436
}
3537

36-
public function has(string $alias): bool { return isset($this->rules[$alias]); }
37-
public function aliases(): array { return array_keys($this->rules); }
38+
#[\Override]
39+
public function has(string $alias): bool
40+
{
41+
return isset($this->rules[$alias]);
42+
}
43+
44+
#[\Override]
45+
public function aliases(): array
46+
{
47+
return array_keys($this->rules);
48+
}
3849
}

src/Core/TransformAttributeHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ final class TransformAttributeHandler implements PropertyAttributeHandler, Prope
3131
#[\Override]
3232
public function handleAttribute(string $propertyName, object $attribute, mixed $value): mixed
3333
{
34-
if (!$attribute instanceof Transform) {
34+
if (! $attribute instanceof Transform) {
3535
return null;
3636
}
3737

3838
$this->data[$propertyName] = $value;
3939

40-
if (!isset($this->fieldRules[$propertyName])) {
40+
if (! isset($this->fieldRules[$propertyName])) {
4141
$this->fieldRules[$propertyName] = [];
4242
}
4343

@@ -84,7 +84,7 @@ public function applyChanges(object $object): void
8484
{
8585
foreach ($this->processedValues as $property => $value) {
8686
try {
87-
(new PropertyAccessor($object, $property))->setValue($value);
87+
new PropertyAccessor($object, $property)->setValue($value);
8888
} catch (\ReflectionException) {
8989
// Property doesn't exist — skip silently
9090
}

src/Core/TransformationContextImpl.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ private function __construct(
2424
private string $fieldName,
2525
private array $rootData,
2626
private array $parameters,
27-
) {}
27+
) {
28+
}
2829

2930
/**
3031
* @param array<string, mixed> $rootData
@@ -34,19 +35,33 @@ public static function create(array $rootData): self
3435
return new self('', $rootData, []);
3536
}
3637

37-
public function getFieldName(): string { return $this->fieldName; }
38+
#[\Override]
39+
public function getFieldName(): string
40+
{
41+
return $this->fieldName;
42+
}
3843

3944
/** @return array<string, mixed> */
40-
public function getRootData(): array { return $this->rootData; }
45+
#[\Override]
46+
public function getRootData(): array
47+
{
48+
return $this->rootData;
49+
}
4150

51+
#[\Override]
4252
public function getParameter(string $key, mixed $default = null): mixed
4353
{
4454
return $this->parameters[$key] ?? $default;
4555
}
4656

4757
/** @return array<string, mixed> */
48-
public function getParameters(): array { return $this->parameters; }
58+
#[\Override]
59+
public function getParameters(): array
60+
{
61+
return $this->parameters;
62+
}
4963

64+
#[\Override]
5065
public function withField(string $field): static
5166
{
5267
return new self($field, $this->rootData, $this->parameters);
@@ -55,6 +70,7 @@ public function withField(string $field): static
5570
/**
5671
* @param array<string, mixed> $parameters
5772
*/
73+
#[\Override]
5874
public function withParameters(array $parameters): static
5975
{
6076
return new self($this->fieldName, $this->rootData, [...$this->parameters, ...$parameters]);

src/Core/TransformerEngine.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ final class TransformerEngine
2525
public function __construct(
2626
private readonly RuleRegistry $registry,
2727
private readonly ?TransformerConfiguration $configuration = null,
28-
) {}
28+
) {
29+
}
2930

3031
/**
3132
* @param array<string, mixed> $data
@@ -62,17 +63,18 @@ public function transform(array $data, array $fieldRules): TransformationResult
6263
/** @param array<string, mixed> $data */
6364
private function resolveValue(array $data, string $field): mixed
6465
{
65-
if (array_key_exists($field, $data)) {
66+
if (\array_key_exists($field, $data)) {
6667
return $data[$field];
6768
}
6869
$segments = explode('.', $field);
6970
$current = $data;
7071
foreach ($segments as $segment) {
71-
if (!is_array($current) || !array_key_exists($segment, $current)) {
72+
if (! \is_array($current) || ! \array_key_exists($segment, $current)) {
7273
return null;
7374
}
7475
$current = $current[$segment];
7576
}
77+
7678
return $current;
7779
}
7880

@@ -85,12 +87,13 @@ private function resolveRule(string|array|TransformationRule $definition): array
8587
if ($definition instanceof TransformationRule) {
8688
return [$definition, []];
8789
}
88-
if (is_string($definition)) {
90+
if (\is_string($definition)) {
8991
return [$this->registry->resolve($definition), []];
9092
}
9193
$ruleRef = $definition[0];
9294
$params = $definition[1] ?? [];
9395
$rule = $ruleRef instanceof TransformationRule ? $ruleRef : $this->registry->resolve($ruleRef);
96+
9497
return [$rule, $params];
9598
}
9699
}

src/Event/TransformationCompletedEvent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@
1515
*/
1616
final readonly class TransformationCompletedEvent
1717
{
18-
public function __construct(public TransformationResult $result, public float $durationMs, public float $timestamp = 0) {}
18+
public function __construct(public TransformationResult $result, public float $durationMs, public float $timestamp = 0)
19+
{
20+
}
1921
}

src/Event/TransformationStartedEvent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
final readonly class TransformationStartedEvent
1515
{
1616
/** @param list<string> $fields */
17-
public function __construct(public array $fields, public float $timestamp = 0) {}
17+
public function __construct(public array $fields, public float $timestamp = 0)
18+
{
19+
}
1820
}

src/Integration/ProcessorBridge.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
/**
2020
* @param array<string, list<string|array{0: string, 1: array<string, mixed>}>> $fieldRules
2121
*/
22-
public function __construct(private TransformerEngine $engine, private array $fieldRules) {}
22+
public function __construct(private TransformerEngine $engine, private array $fieldRules)
23+
{
24+
}
2325

2426
/**
2527
* @param array<string, mixed> $data
@@ -28,6 +30,7 @@ public function __construct(private TransformerEngine $engine, private array $fi
2830
public function process(array $data): array
2931
{
3032
$result = $this->engine->transform($data, $this->fieldRules);
33+
3134
return ['data' => $result->getTransformedData(), 'result' => $result];
3235
}
3336
}

src/Result/FieldTransformation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public function __construct(
1818
public string $ruleName,
1919
public mixed $before,
2020
public mixed $after,
21-
) {}
21+
) {
22+
}
2223

23-
public function wasTransformed(): bool { return $this->before !== $this->after; }
24+
public function wasTransformed(): bool
25+
{
26+
return $this->before !== $this->after;
27+
}
2428
}

0 commit comments

Comments
 (0)