Skip to content

Commit ff2d547

Browse files
authored
Merge pull request #5 from KaririCode-Framework/develop
Develop
2 parents 6eb723f + 6394983 commit ff2d547

87 files changed

Lines changed: 1834 additions & 500 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.

devkit.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* KaririCode Devkit project-level overrides.
7+
*
8+
* Exclude test files from cs-fixer to prevent @PHP84Migration from transforming
9+
* `(new Foo())->method()` → `new Foo()->method()` — that PHP 8.4 syntax prevents
10+
* pcov from correctly attributing code-coverage to the tested class.
11+
*/
12+
return [
13+
'cs_fixer_finder_exclude_dirs' => ['tests'],
14+
];

src/Attribute/Transform.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
/** @var list<string|array{0: string, 1: array<string, mixed>}> */
1818
public array $rules;
1919

20+
/**
21+
* @param string|array{0: string, 1: array<string, mixed>} ...$rules
22+
*/
2023
public function __construct(string|array ...$rules)
2124
{
2225
$this->rules = array_values($rules);

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/AttributeTransformer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ public function transform(object $object): TransformationResult
3737
/** @var TransformAttributeHandler $handler */
3838
$handler = $this->inspector->inspect($object, $handler);
3939

40+
/** @var array<string, list<string|array{0: string, 1: array<string, mixed>}>> $fieldRules */
41+
$fieldRules = $handler->getFieldRules();
42+
4043
$result = $this->engine->transform(
4144
$handler->getProcessedPropertyValues(),
42-
$handler->getFieldRules(),
45+
$fieldRules,
4346
);
4447

4548
$handler->setProcessedValues($result->getTransformedData());

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: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,61 @@
1515
*/
1616
final readonly class TransformationContextImpl implements TransformationContext
1717
{
18-
/** @param array<string, mixed> $rootData @param array<string, mixed> $parameters */
18+
/**
19+
* @param array<string, mixed> $rootData
20+
* @param array<string, mixed> $parameters
21+
*/
1922
private function __construct(
2023
private string $fieldName,
2124
private array $rootData,
2225
private array $parameters,
23-
) {}
26+
) {
27+
}
2428

29+
/**
30+
* @param array<string, mixed> $rootData
31+
*/
2532
public static function create(array $rootData): self
2633
{
2734
return new self('', $rootData, []);
2835
}
2936

30-
public function getFieldName(): string { return $this->fieldName; }
31-
public function getRootData(): array { return $this->rootData; }
32-
public function getParameter(string $key, mixed $default = null): mixed { return $this->parameters[$key] ?? $default; }
33-
public function getParameters(): array { return $this->parameters; }
37+
#[\Override]
38+
public function getFieldName(): string
39+
{
40+
return $this->fieldName;
41+
}
42+
43+
/** @return array<string, mixed> */
44+
#[\Override]
45+
public function getRootData(): array
46+
{
47+
return $this->rootData;
48+
}
49+
50+
#[\Override]
51+
public function getParameter(string $key, mixed $default = null): mixed
52+
{
53+
return $this->parameters[$key] ?? $default;
54+
}
55+
56+
/** @return array<string, mixed> */
57+
#[\Override]
58+
public function getParameters(): array
59+
{
60+
return $this->parameters;
61+
}
3462

63+
#[\Override]
3564
public function withField(string $field): static
3665
{
3766
return new self($field, $this->rootData, $this->parameters);
3867
}
3968

69+
/**
70+
* @param array<string, mixed> $parameters
71+
*/
72+
#[\Override]
4073
public function withParameters(array $parameters): static
4174
{
4275
return new self($this->fieldName, $this->rootData, [...$this->parameters, ...$parameters]);

src/Core/TransformerEngine.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
* @author Walmir Silva <walmir.silva@kariricode.org>
2121
* @since 3.1.0 ARFA 1.3
2222
*/
23-
final class TransformerEngine
23+
final readonly class TransformerEngine
2424
{
2525
public function __construct(
26-
private readonly RuleRegistry $registry,
27-
private readonly ?TransformerConfiguration $configuration = null,
28-
) {}
26+
private RuleRegistry $registry,
27+
private ?TransformerConfiguration $configuration = null,
28+
) {
29+
}
2930

3031
/**
3132
* @param array<string, mixed> $data
@@ -59,34 +60,40 @@ public function transform(array $data, array $fieldRules): TransformationResult
5960
return $result;
6061
}
6162

63+
/** @param array<string, mixed> $data */
6264
private function resolveValue(array $data, string $field): mixed
6365
{
64-
if (array_key_exists($field, $data)) {
66+
if (\array_key_exists($field, $data)) {
6567
return $data[$field];
6668
}
6769
$segments = explode('.', $field);
6870
$current = $data;
6971
foreach ($segments as $segment) {
70-
if (!is_array($current) || !array_key_exists($segment, $current)) {
72+
if (! \is_array($current) || ! \array_key_exists($segment, $current)) {
7173
return null;
7274
}
7375
$current = $current[$segment];
7476
}
77+
7578
return $current;
7679
}
7780

78-
/** @return array{0: TransformationRule, 1: array<string, mixed>} */
81+
/**
82+
* @param string|array{0: string|TransformationRule, 1: array<string, mixed>}|TransformationRule $definition
83+
* @return array{0: TransformationRule, 1: array<string, mixed>}
84+
*/
7985
private function resolveRule(string|array|TransformationRule $definition): array
8086
{
8187
if ($definition instanceof TransformationRule) {
8288
return [$definition, []];
8389
}
84-
if (is_string($definition)) {
90+
if (\is_string($definition)) {
8591
return [$this->registry->resolve($definition), []];
8692
}
8793
$ruleRef = $definition[0];
8894
$params = $definition[1] ?? [];
8995
$rule = $ruleRef instanceof TransformationRule ? $ruleRef : $this->registry->resolve($ruleRef);
96+
9097
return [$rule, $params];
9198
}
9299
}

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
}

0 commit comments

Comments
 (0)