Skip to content

Commit

Permalink
extract pattern resolving from FluentBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Dec 26, 2022
2 parents 9e7f3df + 19092e0 commit 5c89f9d
Show file tree
Hide file tree
Showing 38 changed files with 477 additions and 431 deletions.
417 changes: 42 additions & 375 deletions src/Bundle/FluentBundle.php

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions src/Bundle/ResolutionScope.php

This file was deleted.

6 changes: 6 additions & 0 deletions src/Exceptions/Resolver/TypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

final class TypeException extends ResolverException
{
public function __construct(string $message, mixed $variable)
{
$type = get_debug_type($variable);

parent::__construct(sprintf($message, $type));
}
}
11 changes: 11 additions & 0 deletions src/Node/Syntax/CallArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ public function __construct(
/** @var list<NamedArgument> */
public array $named = [],
) { }

public function getArgument(string $name): ?NamedArgument
{
foreach ($this->named as $argument) {
if ($argument->name->name === $name) {
return $argument;
}
}

return null;
}
}
11 changes: 11 additions & 0 deletions src/Node/Syntax/Entries/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public function __construct(
public array $attributes = [],
public ?Comment $comment = null,
) { }

public function getAttribute(string $name): ?Attribute
{
foreach ($this->attributes as $attribute) {
if ($attribute->id->name === $name) {
return $attribute;
}
}

return null;
}
}
11 changes: 11 additions & 0 deletions src/Node/Syntax/Entries/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public function __construct(
public array $attributes = [],
public ?Comment $comment = null,
) { }

public function getAttribute(string $name): ?Attribute
{
foreach ($this->attributes as $attribute) {
if ($attribute->id->name === $name) {
return $attribute;
}
}

return null;
}
}
12 changes: 12 additions & 0 deletions src/Node/Syntax/Expressions/SelectExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Major\Fluent\Node\Syntax\Expressions;

use Major\Fluent\Exceptions\ShouldNotHappen;
use Major\Fluent\Node\Syntax\Variant;

final class SelectExpression extends Expression
Expand All @@ -11,4 +12,15 @@ public function __construct(
/** @var list<Variant> */
public array $variants,
) { }

public function getDefaultVariant(): Variant
{
foreach ($this->variants as $variant) {
if ($variant->default) {
return $variant;
}
}

throw new ShouldNotHappen();
}
}

0 comments on commit 5c89f9d

Please sign in to comment.