Skip to content

Commit 1fe6ee0

Browse files
committed
fix: apply linter suggestions
1 parent e9842bf commit 1fe6ee0

10 files changed

Lines changed: 105 additions & 151 deletions

File tree

src/Core/Reflect/Introspection/Result.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
readonly class Result
1111
{
12-
1312
public function __construct(
1413
public string $source,
1514
public ?ReflectionType $type = null,

src/Core/Reflect/Resolver/Type/EnumNamedTypeHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44

55
namespace Constructo\Core\Reflect\Resolver\Type;
66

7-
use BackedEnum;
87
use Constructo\Core\Reflect\Resolver\Type\Contract\NamedTypeHandler;
98
use Constructo\Core\Reflect\Resolver\Type\Contract\NamedTypeResolution;
109
use Constructo\Support\Metadata\Schema\Field;
1110
use ReflectionEnum;
1211
use ReflectionEnumBackedCase;
1312
use ReflectionException;
1413
use ReflectionNamedType;
15-
1614
use UnitEnum;
1715

1816
use function enum_exists;

src/Factory/DefaultSpecsFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use Constructo\Support\Metadata\Schema\Registry\Specs;
99
use InvalidArgumentException;
1010

11-
use function assert;
1211
use function Constructo\Cast\arrayify;
1312
use function Constructo\Cast\stringify;
1413
use function gettype;
14+
use function is_array;
15+
use function is_string;
16+
use function sprintf;
1517

1618
readonly class DefaultSpecsFactory implements SpecsFactory
1719
{
@@ -22,7 +24,6 @@ public function __construct(private array $specs = [])
2224
public function make(): Specs
2325
{
2426
$registry = new Specs();
25-
assert($registry instanceof Specs);
2627
foreach ($this->specs as $key => $value) {
2728
$this->validate($key, $value);
2829
$registry->register(stringify($key), arrayify($value));

src/Support/Reflective/AttributeAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract protected function resolveDefineTypeExtended(TypeExtended $type, mixed
2727
abstract protected function resolvePatternFromNamedType(
2828
Pattern $instance,
2929
mixed $value,
30-
ReflectionNamedType $type
30+
ReflectionNamedType $type,
3131
): ?Value;
3232

3333
/**
@@ -67,7 +67,7 @@ protected function resolvePattern(Pattern $instance, mixed $value, ?ReflectionTy
6767
protected function resolvePatternFromUnionType(
6868
Pattern $instance,
6969
mixed $value,
70-
ReflectionUnionType $unionType
70+
ReflectionUnionType $unionType,
7171
): ?Value {
7272
$types = $unionType->getTypes();
7373
$resolved = null;

src/Support/Set.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use function count;
1515
use function is_array;
1616

17-
readonly class Set
17+
final readonly class Set
1818
{
1919
/**
2020
* @var array<string, mixed>
@@ -35,9 +35,9 @@ public function __construct(mixed $data = [])
3535
$this->data = $data;
3636
}
3737

38-
public static function createFrom(mixed $data): static
38+
public static function createFrom(mixed $data): Set
3939
{
40-
return new static($data);
40+
return new Set($data);
4141
}
4242

4343
public function get(string $field, mixed $default = null): mixed
@@ -53,9 +53,9 @@ public function at(string $field): mixed
5353
throw new SchemaException(sprintf("Field '%s' not found.", $field));
5454
}
5555

56-
public function with(string $field, mixed $value): static
56+
public function with(string $field, mixed $value): Set
5757
{
58-
return new static(array_merge($this->toArray(), [$field => $value]));
58+
return new Set(array_merge($this->toArray(), [$field => $value]));
5959
}
6060

6161
/**
@@ -67,9 +67,9 @@ public function toArray(): array
6767
return array_map(fn (mixed $item) => $item instanceof Set ? $item->toArray() : $item, $this->data);
6868
}
6969

70-
public function along(array $values): static
70+
public function along(array $values): Set
7171
{
72-
return new static(array_merge($this->toArray(), $values));
72+
return new Set(array_merge($this->toArray(), $values));
7373
}
7474

7575
public function has(string $field): bool
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Constructo\Testing\Stub;
6+
7+
use Constructo\Core\Serialize\Builder;
8+
use Constructo\Testing\BuilderExtension;
9+
use Constructo\Testing\MakeExtension;
10+
11+
/**
12+
* @internal
13+
*/
14+
class BuilderExtensionWrapper
15+
{
16+
use BuilderExtension;
17+
use MakeExtension;
18+
19+
public function getBuilder(): Builder
20+
{
21+
return $this->builder();
22+
}
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Constructo\Testing\Stub;
6+
7+
use Constructo\Core\Fake\Faker;
8+
use Constructo\Testing\FakerExtension;
9+
use Constructo\Testing\MakeExtension;
10+
use Faker\Generator;
11+
12+
/**
13+
* @internal
14+
*/
15+
class FakerExtensionTestWrapper
16+
{
17+
use FakerExtension;
18+
use MakeExtension;
19+
20+
public function getFaker(): Faker
21+
{
22+
return $this->faker();
23+
}
24+
25+
public function getGenerator(): Generator
26+
{
27+
return $this->generator();
28+
}
29+
}

tests/Support/Metadata/Schema/Field/Formatter/PatternFormatterTest.php

Lines changed: 38 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,173 +10,114 @@
1010

1111
final class PatternFormatterTest extends TestCase
1212
{
13-
private PatternFormatter $formatter;
14-
15-
protected function setUp(): void
13+
public function testFormatWithNonArrayParameter(): void
1614
{
17-
$this->formatter = new PatternFormatter();
15+
$formatter = new PatternFormatter();
16+
$value = ['Hello %s!', 'World'];
17+
$result = $formatter->format($value);
18+
19+
$this->assertSame(['Hello World!'], $result);
1820
}
1921

2022
public function testFormatWithSingleElement(): void
2123
{
24+
$formatter = new PatternFormatter();
2225
$value = ['Hello World'];
23-
$result = $this->formatter->format($value);
26+
$result = $formatter->format($value);
2427

2528
$this->assertSame(['Hello World'], $result);
2629
}
2730

2831
public function testFormatWithSingleElementNumber(): void
2932
{
33+
$formatter = new PatternFormatter();
3034
$value = [123];
31-
$result = $this->formatter->format($value);
35+
$result = $formatter->format($value);
3236

3337
$this->assertSame(['123'], $result);
3438
}
3539

36-
public function testFormatWithSingleElementBoolean(): void
37-
{
38-
$value = [true];
39-
$result = $this->formatter->format($value);
40-
41-
$this->assertSame(['1'], $result);
42-
}
43-
44-
public function testFormatWithSingleElementNull(): void
45-
{
46-
$value = [null];
47-
$result = $this->formatter->format($value);
48-
49-
$this->assertSame([''], $result);
50-
}
51-
52-
public function testFormatWithPatternAndParameters(): void
40+
public function testFormatWithPatternAndArrayParameters(): void
5341
{
42+
$formatter = new PatternFormatter();
5443
$value = ['Hello %s, you are %d years old', ['John', 25]];
55-
$result = $this->formatter->format($value);
44+
$result = $formatter->format($value);
5645

5746
$this->assertSame(['Hello John, you are 25 years old'], $result);
5847
}
5948

60-
public function testFormatWithPatternAndSingleParameter(): void
61-
{
62-
$value = ['Welcome %s!', ['Alice']];
63-
$result = $this->formatter->format($value);
64-
65-
$this->assertSame(['Welcome Alice!'], $result);
66-
}
67-
6849
public function testFormatWithPatternAndNullParameters(): void
6950
{
51+
$formatter = new PatternFormatter();
7052
$value = ['Simple pattern', null];
71-
$result = $this->formatter->format($value);
53+
$result = $formatter->format($value);
7254

7355
$this->assertSame(['Simple pattern'], $result);
7456
}
7557

76-
public function testFormatWithPatternAndEmptyParameters(): void
77-
{
78-
$value = ['No parameters', []];
79-
$result = $this->formatter->format($value);
80-
81-
$this->assertSame(['No parameters'], $result);
82-
}
83-
8458
public function testFormatWithPatternAndClosureParameters(): void
8559
{
60+
$formatter = new PatternFormatter();
8661
$closure = fn() => ['Dynamic', 'Parameters'];
8762
$value = ['%s %s from closure', $closure];
88-
$result = $this->formatter->format($value);
63+
$result = $formatter->format($value);
8964

9065
$this->assertSame(['Dynamic Parameters from closure'], $result);
9166
}
9267

93-
public function testFormatWithPatternAndClosureReturningString(): void
94-
{
95-
$closure = fn() => ['SingleValue'];
96-
$value = ['Value: %s', $closure];
97-
$result = $this->formatter->format($value);
98-
99-
$this->assertSame(['Value: SingleValue'], $result);
100-
}
101-
102-
public function testFormatWithComplexPattern(): void
103-
{
104-
$value = ['User: %s (ID: %d, Active: %s)', ['John Doe', 123, 'Yes']];
105-
$result = $this->formatter->format($value);
106-
107-
$this->assertSame(['User: John Doe (ID: 123, Active: Yes)'], $result);
108-
}
109-
110-
public function testFormatWithNumericPattern(): void
111-
{
112-
$value = ['%.2f%%', [85.678]];
113-
$result = $this->formatter->format($value);
114-
115-
$this->assertSame(['85.68%'], $result);
116-
}
117-
11868
public function testFormatWithNonArrayThrowsException(): void
11969
{
120-
$this->expectException(BadMethodCallException::class);
121-
$this->expectExceptionMessage('PatternFormatter expects an array value.');
70+
$formatter = new PatternFormatter();
12271

123-
$this->formatter->format('not an array');
124-
}
125-
126-
public function testFormatWithNullThrowsException(): void
127-
{
12872
$this->expectException(BadMethodCallException::class);
12973
$this->expectExceptionMessage('PatternFormatter expects an array value.');
13074

131-
$this->formatter->format(null);
75+
$formatter->format('not an array');
13276
}
13377

13478
public function testFormatWithEmptyArrayThrowsException(): void
13579
{
80+
$formatter = new PatternFormatter();
81+
13682
$this->expectException(BadMethodCallException::class);
13783
$this->expectExceptionMessage('PatternFormatter expects an array with one or two elements.');
13884

139-
$this->formatter->format([]);
85+
$formatter->format([]);
14086
}
14187

14288
public function testFormatWithThreeElementsThrowsException(): void
14389
{
144-
$this->expectException(BadMethodCallException::class);
145-
$this->expectExceptionMessage('PatternFormatter expects an array with one or two elements.');
146-
147-
$this->formatter->format(['pattern', ['param1'], 'extra']);
148-
}
90+
$formatter = new PatternFormatter();
14991

150-
public function testFormatWithFourElementsThrowsException(): void
151-
{
15292
$this->expectException(BadMethodCallException::class);
15393
$this->expectExceptionMessage('PatternFormatter expects an array with one or two elements.');
15494

155-
$this->formatter->format(['pattern', ['param1'], 'extra', 'more']);
95+
$formatter->format(['pattern', ['param1'], 'extra']);
15696
}
15797

158-
public function testFormatWithParametersMethod(): void
98+
public function testNormalizeParametersWithNonArrayConvertsToArray(): void
15999
{
160-
$value = ['Hello %s!', ['World']];
161-
$result = $this->formatter->formatWithParameters($value);
100+
$formatter = new PatternFormatter();
101+
$result = $formatter->normalizeParameters('single_value');
162102

163-
$this->assertSame(['Hello World!'], $result);
103+
$this->assertSame(['single_value'], $result);
164104
}
165105

166-
public function testFormatWithParametersMethodAndClosure(): void
106+
public function testNormalizeParametersWithClosure(): void
167107
{
168-
$closure = fn() => ['Closure', 'Test'];
169-
$value = ['%s %s', $closure];
170-
$result = $this->formatter->formatWithParameters($value);
108+
$formatter = new PatternFormatter();
109+
$closure = fn() => ['test', 'values'];
110+
$result = $formatter->normalizeParameters($closure);
171111

172-
$this->assertSame(['Closure Test'], $result);
112+
$this->assertSame(['test', 'values'], $result);
173113
}
174114

175-
public function testFormatWithOption(): void
115+
public function testNormalizeParametersWithMixedTypes(): void
176116
{
177-
$value = ['Test %s', ['value']];
178-
$result = $this->formatter->format($value, 'some_option');
117+
$formatter = new PatternFormatter();
118+
$parameters = [true, 42, 3.14, 'string', new \stdClass(), null];
119+
$result = $formatter->normalizeParameters($parameters);
179120

180-
$this->assertSame(['Test value'], $result);
121+
$this->assertSame([true, 42, 3.14, 'string', null, null], $result);
181122
}
182123
}

0 commit comments

Comments
 (0)