-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Pattern::instanceof(), Pattern::not()
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/muqsit/arithmexp/pattern/matcher/InstanceOfPatternMatcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace muqsit\arithmexp\pattern\matcher; | ||
|
||
use muqsit\arithmexp\expression\token\ExpressionToken; | ||
|
||
final class InstanceOfPatternMatcher implements PatternMatcher{ | ||
|
||
/** | ||
* @param class-string<ExpressionToken> $class | ||
*/ | ||
public function __construct( | ||
private string $class | ||
){} | ||
|
||
public function matches(ExpressionToken|array $entry) : bool{ | ||
if($entry instanceof ExpressionToken){ | ||
return $entry instanceof $this->class; | ||
} | ||
foreach($entry as $token){ | ||
if(!($token instanceof $this->class)){ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/muqsit/arithmexp/pattern/matcher/NotPatternMatcher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace muqsit\arithmexp\pattern\matcher; | ||
|
||
use muqsit\arithmexp\expression\token\ExpressionToken; | ||
|
||
final class NotPatternMatcher implements PatternMatcher{ | ||
|
||
public function __construct( | ||
private PatternMatcher $matcher | ||
){} | ||
|
||
public function matches(ExpressionToken|array $entry) : bool{ | ||
return !$this->matcher->matches($entry); | ||
} | ||
} |