Skip to content

Commit 575b4aa

Browse files
committed
FieldContext: Replace redundant Type lazy getter with one from the CallContext
1 parent 8b6561c commit 575b4aa

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3434
- `castEmptyString` option trims empty characters from start and end of the string
3535
- `StringRule`
3636
- `notEmpty` detects more empty values
37+
- `FieldContext`
38+
- Replace redundant `Type` lazy getter with one from the `CallContext`
3739

3840
### Fixed
3941

src/Callbacks/Context/FieldContext.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace Orisai\ObjectMapper\Callbacks\Context;
44

5-
use Closure;
5+
use Orisai\ObjectMapper\MappedObject;
66
use Orisai\ObjectMapper\Processing\Context\DynamicContext;
7+
use Orisai\ObjectMapper\Processing\Context\ProcessorCallContext;
78
use Orisai\ObjectMapper\Processing\Context\PropertyContext;
89
use Orisai\ObjectMapper\Processing\Context\ServicesContext;
910
use Orisai\ObjectMapper\Types\Type;
@@ -13,36 +14,27 @@ final class FieldContext extends CallbackBaseContext
1314

1415
private PropertyContext $property;
1516

16-
/** @var Closure(): Type */
17-
private Closure $typeCreator;
18-
19-
private ?Type $type = null;
17+
/** @var ProcessorCallContext<MappedObject> */
18+
private ProcessorCallContext $call;
2019

2120
/**
22-
* @param Closure(): Type $typeCreator
21+
* @param ProcessorCallContext<MappedObject> $call
2322
*/
2423
public function __construct(
2524
ServicesContext $services,
2625
DynamicContext $dynamic,
2726
PropertyContext $property,
28-
Closure $typeCreator
27+
ProcessorCallContext $call
2928
)
3029
{
3130
parent::__construct($services, $dynamic);
3231
$this->property = $property;
33-
$this->typeCreator = $typeCreator;
32+
$this->call = $call;
3433
}
3534

3635
public function getType(): Type
3736
{
38-
if ($this->type !== null) {
39-
return $this->type;
40-
}
41-
42-
$type = ($this->typeCreator)();
43-
unset($this->typeCreator);
44-
45-
return $this->type = $type;
37+
return $this->call->getType()->getField($this->property->getFieldName());
4638
}
4739

4840
public function getPropertyName(): string

src/Processing/DefaultProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private function processProperty(
422422
$this->services,
423423
$dynamic,
424424
$property,
425-
static fn (): Type => $call->getType()->getField($property->getFieldName()),
425+
$call,
426426
);
427427

428428
$value = $this->applyCallbacks($value, $callbackContext, $call, $meta, BeforeCallback::class);

0 commit comments

Comments
 (0)