Skip to content

Commit

Permalink
fix: Added processUse to all mapper strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykbaszak committed Jul 25, 2024
1 parent 039374d commit a1da495
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Mapper/Application/Service/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ protected function getMapper(

foreach ($blueprints as $processUse => $blueprint) {
do {
$hasExtended = $this->extender->extend($blueprint, $processType, $context);
$hasExtended = $this->extender->extend($blueprint, $processType, $context, $processUse);
$hasModified = $this->modificator->modify($blueprint, $processType, $context, $processUse);
} while ($hasExtended || $hasModified);

$this->checker->check($blueprint, $processType, $context);
$this->checker->check($blueprint, $processType, $context, $processUse);
}

$this->matcher->matchBlueprints($context, $processType, ...$blueprints);
Expand Down
4 changes: 2 additions & 2 deletions src/Mapper/Domain/Modules/Checker/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public function __construct(
) {
}

public function check(Blueprint $blueprint, Process $process, Context $context): void
public function check(Blueprint $blueprint, Process $process, Context $context, string $processUse): void
{
foreach ($this->strategies as $strategy) {
$strategy->check($blueprint, $process, $context);
$strategy->check($blueprint, $process, $context, $processUse);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ interface CheckerInterface
*
* @throws CheckerException if the blueprint is invalid
*/
public function check(Blueprint $blueprint, Process $process, Context $context): void;
public function check(Blueprint $blueprint, Process $process, Context $context, string $processUse): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ interface CheckerStrategyInterface
*
* @throws CheckerException if the blueprint is invalid
*/
public function check(Blueprint $blueprint, Process $process, Context $context): void;
public function check(Blueprint $blueprint, Process $process, Context $context, string $processUse): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RecursiveLoopChecker implements CheckerStrategyInterface
{
private Blueprint $blueprint;

public function check(Blueprint $blueprint, Process $process, Context $context): void
public function check(Blueprint $blueprint, Process $process, Context $context, string $processUse): void
{
$this->blueprint = $blueprint;
foreach ($blueprint->blueprints as $index => $classBlueprint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ interface ExtenderInterface
*
* @throws ExtenderException if there was any problem with extending the blueprint
*/
public function extend(Blueprint $blueprint, Process $process, Context $context): bool;
public function extend(Blueprint $blueprint, Process $process, Context $context, string $processUse): bool;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ interface ExtenderStrategyInterface
*
* @return bool `true` if the blueprint was extended, `false` otherwise
*/
public function extend(Blueprint $blueprint, Process $process, Context $context): bool;
public function extend(Blueprint $blueprint, Process $process, Context $context, string $processUse): bool;
}
6 changes: 3 additions & 3 deletions src/Mapper/Domain/Modules/Extender/Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ public function __construct(
$this->recursionLevel = 0;
}

public function extend(Blueprint $blueprint, Process $process, Context $context): bool
public function extend(Blueprint $blueprint, Process $process, Context $context, string $processUse): bool
{
$extended = false;

foreach ($this->strategies as $strategy) {
$extended = $strategy->extend($blueprint, $process, $context) || $extended;
$extended = $strategy->extend($blueprint, $process, $context, $processUse) || $extended;
}

if ($extended) {
++$this->recursionLevel;
$this->extend($blueprint, $process, $context);
$this->extend($blueprint, $process, $context, $processUse);

if ($this->recursionLevel > $this->maxRecursionLevel) {
throw new Exception\ExtenderException(sprintf('Max recursion level of %d reached', $this->maxRecursionLevel), 'Extender recursion level can be increased by setting the maxRecursionLevel property in the constructor of the Extender class. The default value is 100. If you are sure that the recursion level is not a problem, you can increase the value. If you are not sure, you should check the blueprint and the strategies to see if there is a problem with the blueprint or the strategies.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DiscriminatorExtender implements ExtenderStrategyInterface
private Blueprint $blueprint;
private bool $extended;

public function extend(Blueprint $blueprint, Process $process, Context $context): bool
public function extend(Blueprint $blueprint, Process $process, Context $context, string $processUse): bool
{
$this->extended = false;
$this->blueprint = $blueprint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function shouldThrowExceptionOnLoopDetected(): void
(new RecursiveLoopChecker())->check(
Blueprint::create(get_class($class)),
new Process([Process::DENORMALIZATION_PROCESS]),
new Context()
new Context(),
'origin'
);
}

Expand All @@ -46,7 +47,8 @@ public function shouldThrowExceptionOnLoopDetectedInTheGroupContext(): void
(new RecursiveLoopChecker())->check(
Blueprint::create(get_class($class)),
new Process([Process::DENORMALIZATION_PROCESS]),
new Context(['test'])
new Context(['test']),
'origin'
);
}

Expand All @@ -61,7 +63,8 @@ public function shouldNotThrowExceptionBecauseOfIgnoreAttribute(): void
(new RecursiveLoopChecker())->check(
Blueprint::create(get_class($class)),
new Process([Process::DENORMALIZATION_PROCESS]),
new Context()
new Context(),
'origin'
);

$this->expectNotToPerformAssertions();
Expand All @@ -78,7 +81,8 @@ public function shouldNotThrowExceptionBecauseOfMaxDepthAttribute(): void
(new RecursiveLoopChecker())->check(
Blueprint::create(get_class($class)),
new Process([Process::DENORMALIZATION_PROCESS]),
new Context()
new Context(),
'origin'
);

$this->expectNotToPerformAssertions();
Expand Down

0 comments on commit a1da495

Please sign in to comment.