Skip to content

Commit b7c20be

Browse files
committed
Runtime meta: replace getters with readonly properties
1 parent 7e9cb4e commit b7c20be

27 files changed

+111
-253
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
- Simplify finding missing fields (performance optimization)
1313
- Reduce calls needed to find field names for "did you mean" error helper
14+
- Runtime meta
15+
- replace getters with readonly properties
1416

1517
### Fixed
1618

src/Meta/MetaResolver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function resolve(ReflectionClass $class, CompileMeta $meta): RuntimeMeta
7474
$this->resolveFieldsMeta($class, $meta),
7575
);
7676

77-
$this->checkObjectCanBeInstantiated($class, $runtimeMeta->getClass());
77+
$this->checkObjectCanBeInstantiated($class, $runtimeMeta->class);
7878

7979
return $runtimeMeta;
8080
}
@@ -177,7 +177,7 @@ private function checkObjectCanBeInstantiated(ReflectionClass $class, ClassRunti
177177
{
178178
$injectors = [];
179179
foreach ($meta->getModifier(RequiresDependenciesModifier::class) as $modifier) {
180-
$injectors[] = $modifier->getArgs()->injector;
180+
$injectors[] = $modifier->args->injector;
181181
}
182182

183183
$this->objectCreator->createInstance($class->getName(), $injectors);
@@ -211,10 +211,10 @@ private function propertyNameToFieldName(FieldRuntimeMeta $fieldMeta)
211211
{
212212
$modifier = $fieldMeta->getModifier(FieldNameModifier::class);
213213
if ($modifier !== null) {
214-
return $modifier->getArgs()->name;
214+
return $modifier->args->name;
215215
}
216216

217-
return $fieldMeta->getProperty()->getName();
217+
return $fieldMeta->property->getName();
218218
}
219219

220220
/**
@@ -314,7 +314,7 @@ private function resolveCallbacksMeta(
314314
$classReflector,
315315
);
316316

317-
$array[$callbackMeta->getType()][$key] = $callbackMeta;
317+
$array[$callbackMeta->type][$key] = $callbackMeta;
318318
}
319319

320320
return $array;

src/Meta/Runtime/CallbackRuntimeMeta.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111
* @phpstan-type T_SERIALIZED array{type: class-string<Callback<T>>, args: T, declaringClass: class-string<MappedObject>}
1212
*
1313
* @template-covariant T of Args
14+
*
15+
* @readonly
1416
*/
1517
final class CallbackRuntimeMeta
1618
{
1719

1820
/** @var class-string<Callback<T>> */
19-
private string $type;
21+
public string $type;
2022

2123
/** @var T */
22-
private Args $args;
24+
public Args $args;
2325

2426
/** @var ReflectionClass<covariant MappedObject> */
25-
private ReflectionClass $declaringClass;
27+
public ReflectionClass $declaringClass;
2628

2729
/**
2830
* @param class-string<Callback<T>> $type
@@ -36,30 +38,6 @@ public function __construct(string $type, Args $args, ReflectionClass $declaring
3638
$this->declaringClass = $declaringClass;
3739
}
3840

39-
/**
40-
* @return class-string<Callback<T>>
41-
*/
42-
public function getType(): string
43-
{
44-
return $this->type;
45-
}
46-
47-
/**
48-
* @return T
49-
*/
50-
public function getArgs(): Args
51-
{
52-
return $this->args;
53-
}
54-
55-
/**
56-
* @return ReflectionClass<covariant MappedObject>
57-
*/
58-
public function getDeclaringClass(): ReflectionClass
59-
{
60-
return $this->declaringClass;
61-
}
62-
6341
/**
6442
* @return T_SERIALIZED
6543
*/

src/Meta/Runtime/ClassRuntimeMeta.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,26 @@ final class ClassRuntimeMeta extends NodeRuntimeMeta
99
{
1010

1111
/** @var array<class-string<Modifier<Args>>, list<ModifierRuntimeMeta<Args>>> */
12-
private array $modifiers;
12+
public array $modifiers;
1313

1414
/**
15-
* @param array<class-string<Modifier<Args>>, list<ModifierRuntimeMeta<Args>>> $modifiers
15+
* @template T_ARGS of Args
16+
* @param array<class-string<Modifier<T_ARGS>>, list<ModifierRuntimeMeta<T_ARGS>>> $modifiers
1617
*/
1718
public function __construct(array $callbacks, array $docs, array $modifiers)
1819
{
1920
parent::__construct($callbacks, $docs);
2021
$this->modifiers = $modifiers;
2122
}
2223

23-
/**
24-
* @return array<class-string<Modifier<Args>>, list<ModifierRuntimeMeta<Args>>>
25-
*/
26-
public function getModifiers(): array
27-
{
28-
return $this->modifiers;
29-
}
30-
3124
/**
3225
* @template T of Args
3326
* @param class-string<Modifier<T>> $type
3427
* @return list<ModifierRuntimeMeta<T>>
3528
*/
3629
public function getModifier(string $type): array
3730
{
38-
return $this->getModifiers()[$type] ?? [];
31+
return $this->modifiers[$type] ?? [];
3932
}
4033

4134
/**

src/Meta/Runtime/FieldRuntimeMeta.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ final class FieldRuntimeMeta extends NodeRuntimeMeta
1111
{
1212

1313
/** @var RuleRuntimeMeta<Args> */
14-
private RuleRuntimeMeta $rule;
14+
public RuleRuntimeMeta $rule;
1515

16-
private DefaultValueMeta $default;
16+
public DefaultValueMeta $default;
1717

18-
private ReflectionProperty $property;
18+
public ReflectionProperty $property;
1919

2020
/** @var array<class-string<Modifier<Args>>, ModifierRuntimeMeta<Args>> */
21-
private array $modifiers;
21+
public array $modifiers;
2222

2323
/**
24-
* @param array<class-string<Modifier<Args>>, ModifierRuntimeMeta<Args>> $modifiers
24+
* @template T_ARGS of Args
25+
* @param array<class-string<Modifier<T_ARGS>>, ModifierRuntimeMeta<T_ARGS>> $modifiers
2526
* @param RuleRuntimeMeta<Args> $rule
2627
*/
2728
public function __construct(
@@ -40,40 +41,14 @@ public function __construct(
4041
$this->modifiers = $modifiers;
4142
}
4243

43-
/**
44-
* @return RuleRuntimeMeta<Args>
45-
*/
46-
public function getRule(): RuleRuntimeMeta
47-
{
48-
return $this->rule;
49-
}
50-
51-
public function getDefault(): DefaultValueMeta
52-
{
53-
return $this->default;
54-
}
55-
56-
public function getProperty(): ReflectionProperty
57-
{
58-
return $this->property;
59-
}
60-
61-
/**
62-
* @return array<class-string<Modifier<Args>>, ModifierRuntimeMeta<Args>>
63-
*/
64-
public function getModifiers(): array
65-
{
66-
return $this->modifiers;
67-
}
68-
6944
/**
7045
* @template T of Args
7146
* @param class-string<Modifier<T>> $type
7247
* @return ModifierRuntimeMeta<T>|null
7348
*/
7449
public function getModifier(string $type): ?ModifierRuntimeMeta
7550
{
76-
return $this->getModifiers()[$type] ?? null;
51+
return $this->modifiers[$type] ?? null;
7752
}
7853

7954
/**

src/Meta/Runtime/ModifierRuntimeMeta.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
/**
99
* @template-covariant T of Args
10+
*
11+
* @readonly
1012
*/
1113
final class ModifierRuntimeMeta
1214
{
1315

1416
/** @var class-string<Modifier<T>> */
15-
private string $type;
17+
public string $type;
1618

1719
/** @var T */
18-
private Args $args;
20+
public Args $args;
1921

2022
/**
2123
* @param class-string<Modifier<T>> $type
@@ -27,22 +29,6 @@ public function __construct(string $type, Args $args)
2729
$this->args = $args;
2830
}
2931

30-
/**
31-
* @return class-string<Modifier<T>>
32-
*/
33-
public function getType(): string
34-
{
35-
return $this->type;
36-
}
37-
38-
/**
39-
* @return T
40-
*/
41-
public function getArgs(): Args
42-
{
43-
return $this->args;
44-
}
45-
4632
/**
4733
* @return array<mixed>
4834
*/

src/Meta/Runtime/NodeRuntimeMeta.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
use Orisai\ObjectMapper\Meta\Shared\DocMeta;
88

99
/**
10+
* @readonly
11+
*
1012
* @internal
1113
*/
1214
abstract class NodeRuntimeMeta
1315
{
1416

1517
/** @var array<class-string<Callback<Args>>, array<int, CallbackRuntimeMeta<Args>>> */
16-
private array $callbacks;
18+
public array $callbacks;
1719

1820
/** @var array<string, DocMeta> */
19-
private array $docs;
21+
public array $docs;
2022

2123
/**
2224
* @template T_ARGS of Args
@@ -29,19 +31,6 @@ public function __construct(array $callbacks, array $docs)
2931
$this->docs = $docs;
3032
}
3133

32-
public function hasAnyCallbacks(): bool
33-
{
34-
return $this->callbacks !== [];
35-
}
36-
37-
/**
38-
* @return array<class-string<Callback<Args>>, array<int, CallbackRuntimeMeta<Args>>>
39-
*/
40-
public function getCallbacks(): array
41-
{
42-
return $this->callbacks;
43-
}
44-
4534
/**
4635
* @return array<int, CallbackRuntimeMeta<Args>>
4736
*/
@@ -50,14 +39,6 @@ public function getCallbacksByType(string $type): array
5039
return $this->callbacks[$type] ?? [];
5140
}
5241

53-
/**
54-
* @return array<string, DocMeta>
55-
*/
56-
public function getDocs(): array
57-
{
58-
return $this->docs;
59-
}
60-
6142
/**
6243
* @return array<mixed>
6344
*/

src/Meta/Runtime/RuleRuntimeMeta.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
/**
99
* @template-covariant T of Args
10+
*
11+
* @readonly
1012
*/
1113
final class RuleRuntimeMeta
1214
{
1315

1416
/** @var class-string<Rule<T>> */
15-
private string $type;
17+
public string $type;
1618

1719
/** @var T */
18-
private Args $args;
20+
public Args $args;
1921

2022
/**
2123
* @param class-string<Rule<T>> $type
@@ -27,22 +29,6 @@ public function __construct(string $type, Args $args)
2729
$this->args = $args;
2830
}
2931

30-
/**
31-
* @return class-string<Rule<T>>
32-
*/
33-
public function getType(): string
34-
{
35-
return $this->type;
36-
}
37-
38-
/**
39-
* @return T
40-
*/
41-
public function getArgs(): Args
42-
{
43-
return $this->args;
44-
}
45-
4632
/**
4733
* @return array<mixed>
4834
*/

src/Meta/Runtime/RuntimeMeta.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
/**
66
* Value object for meta returned from MetaLoader
7+
*
8+
* @readonly
79
*/
810
final class RuntimeMeta
911
{
1012

11-
private ClassRuntimeMeta $class;
13+
public ClassRuntimeMeta $class;
1214

1315
/** @var array<int|string, FieldRuntimeMeta> */
14-
private array $fields;
16+
public array $fields;
1517

1618
/**
1719
* @param array<int|string, FieldRuntimeMeta> $fields
@@ -22,19 +24,6 @@ public function __construct(ClassRuntimeMeta $class, array $fields)
2224
$this->fields = $fields;
2325
}
2426

25-
public function getClass(): ClassRuntimeMeta
26-
{
27-
return $this->class;
28-
}
29-
30-
/**
31-
* @return array<int|string, FieldRuntimeMeta>
32-
*/
33-
public function getFields(): array
34-
{
35-
return $this->fields;
36-
}
37-
3827
/**
3928
* @return array<mixed>
4029
*/

0 commit comments

Comments
 (0)