LaravelFreelancerNL /
fluentaql
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace LaravelFreelancerNL\FluentAQL\Traits; |
||
| 6 | |||
| 7 | trait ValidatesReferences |
||
| 8 | { |
||
| 9 | 7 | public function isBind(mixed $value): bool |
|
| 10 | { |
||
| 11 | 7 | if (is_string($value)) { |
|
| 12 | 6 | return true; |
|
| 13 | } |
||
| 14 | 1 | if (is_object($value)) { |
|
| 15 | return true; |
||
| 16 | } |
||
| 17 | |||
| 18 | 1 | return false; |
|
| 19 | } |
||
| 20 | |||
| 21 | 1 | public function isCollectionBind(mixed $value): bool |
|
| 22 | { |
||
| 23 | 1 | if (is_string($value)) { |
|
| 24 | 1 | return true; |
|
| 25 | } |
||
| 26 | |||
| 27 | return false; |
||
| 28 | } |
||
| 29 | |||
| 30 | 30 | public function isVariable(mixed $value): bool |
|
| 31 | { |
||
| 32 | 30 | if (is_string($value) && preg_match('/^\$?[a-zA-Z_][a-zA-Z0-9_]*+$/', $value)) { |
|
| 33 | 30 | return true; |
|
| 34 | } |
||
| 35 | |||
| 36 | 5 | return false; |
|
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param array<array-key, mixed> $registeredVariables |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 41 | */ |
||
| 42 | 1 | public function isRegisteredVariable( |
|
| 43 | int|string $value, |
||
| 44 | array $registeredVariables = [] |
||
| 45 | ): bool { |
||
| 46 | 1 | return isset($registeredVariables[$value]); |
|
| 47 | } |
||
| 48 | |||
| 49 | 1 | public function isAttribute(mixed $value): bool |
|
| 50 | { |
||
| 51 | 1 | $pattern = '/^(@?[\d\w_]+|`@?[\d\w_]+`)(\[\`.+\`\]|\[[\d\w\*]*\])*' |
|
| 52 | . '(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/'; |
||
| 53 | if ( |
||
| 54 | 1 | is_string($value) && |
|
| 55 | 1 | preg_match($pattern, $value) |
|
| 56 | ) { |
||
| 57 | 1 | return true; |
|
| 58 | } |
||
| 59 | |||
| 60 | 1 | return false; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param array<array-key, null|object|scalar> $registeredVariables |
||
|
0 ignored issues
–
show
|
|||
| 65 | */ |
||
| 66 | 27 | public function isReference( |
|
| 67 | mixed $value, |
||
| 68 | array $registeredVariables = [] |
||
| 69 | ): bool { |
||
| 70 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
| 71 | 27 | $variables = implode('|', $registeredVariables); |
|
| 72 | |||
| 73 | 27 | if (! is_string($value) || empty($value)) { |
|
| 74 | 2 | return false; |
|
| 75 | } |
||
| 76 | |||
| 77 | 27 | return (bool) preg_match( |
|
| 78 | 27 | '/^(' |
|
| 79 | . $variables |
||
| 80 | . '|CURRENT|NEW|OLD)(\[\`.+\`\]|\[[\d\w\*]*\])*(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/', |
||
| 81 | $value |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | } |
||
| 85 |