Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public function assemble(MatchingRuleSetAssembler $assembler): ?CompositeMatchin
{
$rules = new ArrayIterator();

$parentRule = $assembler->getParentRule();
Assert::notNull($parentRule);
$ownerRule = $assembler->getOwnerRule();
Assert::notNull($ownerRule);

$ruleSet = new CompositeMatchingRule($parentRule, $rules);
$ruleSet = new CompositeMatchingRule($ownerRule, $rules);

foreach ($this->assemblers as $a) {
$innerRuleSet = $a->assemble($assembler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
/** @internal */
interface MatchingRuleSetAssembler
{
public function getParentRule(): ?MatchingRule;
public function getOwnerRule(): ?MatchingRule;
}
14 changes: 7 additions & 7 deletions src/ExceptionalMatcher/Rule/CompositeMatchingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
final class CompositeMatchingRule implements MatchingRule
{
public function __construct(
private readonly MatchingRule $parent,
private readonly MatchingRule $owner,
/** @var iterable<MatchingRule> $rules */
private readonly iterable $rules,
) {
Expand All @@ -28,28 +28,28 @@ public function process(ExceptionReciprocal $reciprocal): bool
return false;
}

public function getParent(): MatchingRule
public function getOwner(): MatchingRule
{
return $this->parent;
return $this->owner;
}

public function getPropertyPath(): PropertyPath
{
return $this->parent->getPropertyPath();
return $this->owner->getPropertyPath();
}

public function getEnclosingObject(): object
{
return $this->parent->getEnclosingObject();
return $this->owner->getEnclosingObject();
}

public function getRootObject(): object
{
return $this->parent->getRootObject();
return $this->owner->getRootObject();
}

public function getValue(): mixed
{
return $this->parent->getValue();
return $this->owner->getValue();
}
}
12 changes: 6 additions & 6 deletions src/ExceptionalMatcher/Rule/ItemOfIterableMatchingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ItemOfIterableMatchingRule implements MatchingRule
{
public function __construct(
private readonly int|string $key,
private readonly MatchingRule $parent,
private readonly MatchingRule $owner,
private readonly MatchingRule $objectRuleSet,
) {
}
Expand All @@ -25,24 +25,24 @@ public function process(ExceptionReciprocal $reciprocal): bool
return $this->objectRuleSet->process($reciprocal);
}

public function getParent(): MatchingRule
public function getOwner(): MatchingRule
{
return $this->parent;
return $this->owner;
}

public function getPropertyPath(): PropertyPath
{
return $this->parent->getPropertyPath()->at($this->key);
return $this->owner->getPropertyPath()->at($this->key);
}

public function getEnclosingObject(): object
{
return $this->parent->getEnclosingObject();
return $this->owner->getEnclosingObject();
}

public function getRootObject(): object
{
return $this->parent->getRootObject();
return $this->owner->getRootObject();
}

public function getValue(): object
Expand Down
4 changes: 2 additions & 2 deletions src/ExceptionalMatcher/Rule/LazyMatchingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function process(ExceptionReciprocal $reciprocal): bool
return $this->innerRule()->process($reciprocal);
}

public function getParent(): ?MatchingRule
public function getOwner(): ?MatchingRule
{
return $this->innerRule()->getParent();
return $this->innerRule()->getOwner();
}

public function getPropertyPath(): PropertyPath
Expand Down
2 changes: 1 addition & 1 deletion src/ExceptionalMatcher/Rule/MatchingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface MatchingRule
/** Returns TRUE if all exceptions were matched; FALSE otherwise */
public function process(ExceptionReciprocal $reciprocal): bool;

public function getParent(): ?self;
public function getOwner(): ?self;

public function getPropertyPath(): PropertyPath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ObjectMatchingRuleSetAssembler implements MatchingRuleSetAssembler

public function __construct(
private readonly object $message,
private readonly ?MatchingRule $parentRule = null,
private readonly ?MatchingRule $ownerRule = null,
) {
$this->reflectionClass = new ReflectionClass($this->message::class);
}
Expand All @@ -38,7 +38,7 @@ public function assemble(ObjectMatchingRuleSetAssemblerService $service): ?Match
function (LazyMatchingRule $lazyWrappedRuleSet) use ($service): CompositeMatchingRule {
$objectRuleSet = new ObjectMatchingRuleSet(
$this->message,
$this->parentRule,
$this->ownerRule,
$lazyWrappedRuleSet,
);

Expand All @@ -49,12 +49,12 @@ function (LazyMatchingRule $lazyWrappedRuleSet) use ($service): CompositeMatchin
},
);

return $wrappedRuleSet->build()?->getParent();
return $wrappedRuleSet->build()?->getOwner();
}

public function getParentRule(): ?MatchingRule
public function getOwnerRule(): ?MatchingRule
{
return $this->parentRule;
return $this->ownerRule;
}

private function isMarkedWithAnAttribute(): bool
Expand Down
10 changes: 5 additions & 5 deletions src/ExceptionalMatcher/Rule/Object/ObjectMatchingRuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class ObjectMatchingRuleSet implements MatchingRule
{
public function __construct(
private readonly object $object,
private readonly ?MatchingRule $parent,
private readonly ?MatchingRule $owner,
private readonly MatchingRule $ruleSet,
) {
}
Expand All @@ -23,14 +23,14 @@ public function process(ExceptionReciprocal $reciprocal): bool
return $this->ruleSet->process($reciprocal);
}

public function getParent(): ?MatchingRule
public function getOwner(): ?MatchingRule
{
return $this->parent;
return $this->owner;
}

public function getPropertyPath(): PropertyPath
{
return $this->parent?->getPropertyPath() ?? PropertyPath::empty();
return $this->owner?->getPropertyPath() ?? PropertyPath::empty();
}

public function getEnclosingObject(): object
Expand All @@ -40,7 +40,7 @@ public function getEnclosingObject(): object

public function getRootObject(): object
{
return $this->parent?->getRootObject() ?? $this->object;
return $this->owner?->getRootObject() ?? $this->object;
}

public function getValue(): object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class PropertyMatchingRuleSetAssembler implements MatchingRuleSetAssembler
{
public function __construct(
private readonly ObjectMatchingRuleSet $parentRule,
private readonly ObjectMatchingRuleSet $ownerRule,
private readonly ReflectionProperty $reflectionProperty,
) {
}
Expand All @@ -26,10 +26,10 @@ public function assemble(PropertyMatchingRuleSetAssemblerService $service): ?Mat
$matchingRuleSet = new LazyMatchingRule(
/** @param LazyMatchingRule<MatchingRule> $lazyMatchingRuleSet */
function (LazyMatchingRule $lazyMatchingRuleSet) use ($service): ?MatchingRule {
$object = $this->parentRule->getValue();
$object = $this->ownerRule->getValue();

$propertyRuleSet = new PropertyMatchingRuleSet(
$this->parentRule,
$this->ownerRule,
$this->getName(),
$this->getPropertyValue($object),
$lazyMatchingRuleSet,
Expand All @@ -41,12 +41,12 @@ function (LazyMatchingRule $lazyMatchingRuleSet) use ($service): ?MatchingRule {
},
);

return $matchingRuleSet->build()?->getParent();
return $matchingRuleSet->build()?->getOwner();
}

public function getParentRule(): ObjectMatchingRuleSet
public function getOwnerRule(): ObjectMatchingRuleSet
{
return $this->parentRule;
return $this->ownerRule;
}

private function getName(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
/** @param PropertyMatchingRulesAssembler $assembler */
public function assemble(MatchingRuleSetAssembler $assembler): ?MatchingRule
{
$propertyRuleSet = $assembler->getParentRule();
$propertyRuleSet = $assembler->getOwnerRule();
$propertyValue = $propertyRuleSet->getValue();

if (!is_iterable($propertyValue)) {
Expand All @@ -52,43 +52,43 @@ public function assemble(MatchingRuleSetAssembler $assembler): ?MatchingRule
}

/** @param iterable<array-key,mixed> $items */
private function createRuleSet(iterable $items, PropertyMatchingRuleSet $parent): CompositeMatchingRule
private function createRuleSet(iterable $items, PropertyMatchingRuleSet $ownerRuleSet): CompositeMatchingRule
{
return new CompositeMatchingRule(
$parent,
$this->getRules($items, $parent),
$ownerRuleSet,
$this->getRules($items, $ownerRuleSet),
);
}

/** @param iterable<array-key,mixed> $items */
private function getRules(iterable $items, PropertyMatchingRuleSet $parentRuleSet): Generator
private function getRules(iterable $items, PropertyMatchingRuleSet $ownerRuleSet): Generator
{
foreach ($items as $key => $item) {
if (!is_object($item)) {
continue;
}

$rule = $this->getIterableItemMatchingRule($parentRuleSet, $key, $item);
$rule = $this->getIterableItemMatchingRule($ownerRuleSet, $key, $item);

if (null !== $rule) {
yield $rule;
}
}
}

private function getIterableItemMatchingRule(PropertyMatchingRuleSet $parentRuleSet, int|string $key, object $object): ?MatchingRule
private function getIterableItemMatchingRule(PropertyMatchingRuleSet $ownerRuleSet, int|string $key, object $object): ?MatchingRule
{
$wrappedObjectRuleSet = new LazyMatchingRule(
/** @param LazyMatchingRule<MatchingRule> $lazyObjectRuleSet */
function (LazyMatchingRule $lazyObjectRuleSet) use ($key, $parentRuleSet, $object): ?MatchingRule {
$itemOfIterableRule = new ItemOfIterableMatchingRule($key, $parentRuleSet, $lazyObjectRuleSet);
function (LazyMatchingRule $lazyObjectRuleSet) use ($key, $ownerRuleSet, $object): ?MatchingRule {
$itemOfIterableRule = new ItemOfIterableMatchingRule($key, $ownerRuleSet, $lazyObjectRuleSet);

return $this->objectRuleSetAssemblerService
->assemble(new ObjectMatchingRuleSetAssembler($object, $itemOfIterableRule))
;
},
);

return $wrappedObjectRuleSet->build()?->getParent();
return $wrappedObjectRuleSet->build()?->getOwner();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
/** @param PropertyMatchingRulesAssembler $assembler */
public function assemble(MatchingRuleSetAssembler $assembler): ?MatchingRule
{
$propertyRuleSet = $assembler->getParentRule();
$propertyRuleSet = $assembler->getOwnerRule();
$propertyValue = $propertyRuleSet->getValue();

if (!is_object($propertyValue)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
final class PropertyMatchingRulesAssembler implements MatchingRuleSetAssembler
{
public function __construct(
private readonly PropertyMatchingRuleSet $parentRule,
private readonly PropertyMatchingRuleSet $ownerRule,
private readonly ReflectionProperty $reflectionProperty,
) {
}

public function assemble(PropertyMatchingRulesAssemblerService $service): ?CompositeMatchingRule
{
$rules = new ArrayIterator();
$ruleSet = new CompositeMatchingRule($this->parentRule, $rules);
$ruleSet = new CompositeMatchingRule($this->ownerRule, $rules);

foreach ($this->getCatchAttributes() as $catchAttribute) {
$condition = $service->matchConditionFactory->getCondition($catchAttribute, $this->parentRule);
$condition = $service->matchConditionFactory->getCondition($catchAttribute, $this->ownerRule);

Assert::notNull($condition);

Expand All @@ -49,9 +49,9 @@ public function assemble(PropertyMatchingRulesAssemblerService $service): ?Compo
return $ruleSet;
}

public function getParentRule(): PropertyMatchingRuleSet
public function getOwnerRule(): PropertyMatchingRuleSet
{
return $this->parentRule;
return $this->ownerRule;
}

/** @return Generator<Catch_<Throwable,Throwable>> */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class ExceptionClassMatchConditionFactory implements MatchConditionFactory
{
public function getCondition(Catch_ $catch, MatchingRule $parent): ExceptionClassMatchCondition
public function getCondition(Catch_ $catch, MatchingRule $owner): ExceptionClassMatchCondition
{
return new ExceptionClassMatchCondition($catch->getExceptionClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
final class SimpleIfClosureMatchConditionFactory implements MatchConditionFactory
{
public function getCondition(Catch_ $catch, MatchingRule $parent): ?MatchCondition
public function getCondition(Catch_ $catch, MatchingRule $owner): ?MatchCondition
{
$if = $catch->getIf();

Expand All @@ -28,7 +28,7 @@ public function getCondition(Catch_ $catch, MatchingRule $parent): ?MatchConditi

Assert::methodExists(...$if);

$object = $parent->getEnclosingObject();
$object = $owner->getEnclosingObject();

if ($if[0] === $object::class) {
$if = [$object, $if[1]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public function __construct(
) {
}

public function getCondition(Catch_ $catch, MatchingRule $parent): ?MatchCondition
public function getCondition(Catch_ $catch, MatchingRule $owner): ?MatchCondition
{
$conditions = [];

foreach ($this->factories as $factory) {
$matchCondition = $factory->getCondition($catch, $parent);
$matchCondition = $factory->getCondition($catch, $owner);

if ($matchCondition instanceof FalseCondition) {
return $matchCondition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
) {
}

public function getCondition(Catch_ $catch, MatchingRule $parent): ?MatchCondition
public function getCondition(Catch_ $catch, MatchingRule $owner): ?MatchCondition
{
$factoryId = $catch->getMatch();

Expand All @@ -46,6 +46,6 @@ public function getCondition(Catch_ $catch, MatchingRule $parent): ?MatchConditi
$matchConditionFactory = $this->matchConditionFactoryRegistry->get($factoryId);

/** @var MatchConditionFactory<Throwable> $matchConditionFactory */
return $matchConditionFactory->getCondition($catch, $parent);
return $matchConditionFactory->getCondition($catch, $owner);
}
}
Loading
Loading