We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 25 | 21 | final class Contains implements Rule |
|
| 26 | { |
||
| 27 | 21 | /** |
|
| 28 | 11 | * @var mixed |
|
| 29 | */ |
||
| 30 | private $expectedValue; |
||
| 31 | 10 | ||
| 32 | /** |
||
| 33 | * @var bool |
||
| 34 | 10 | */ |
|
| 35 | private $identical; |
||
| 36 | 10 | ||
| 37 | 4 | /** |
|
| 38 | * Initializes the rule. |
||
| 39 | * |
||
| 40 | 6 | * @param mixed $expectedValue |
|
| 41 | * @param bool $identical |
||
| 42 | */ |
||
| 43 | 11 | public function __construct($expectedValue, bool $identical = false) |
|
| 48 | |||
| 49 | 6 | /** |
|
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | public function apply($input): Result |
||
| 53 | { |
||
| 54 | if (is_array($input)) { |
||
| 55 | return new Result(in_array($this->expectedValue, $input, $this->identical), $input, $this); |
||
| 56 | } |
||
| 57 | |||
| 58 | $stringValResult = (new StringVal())->apply($input); |
||
| 59 | if (!$stringValResult->isValid()) { |
||
| 60 | return new Result(false, $input, $this, [], $stringValResult); |
||
| 61 | } |
||
| 62 | |||
| 63 | $encoding = mb_detect_encoding($input); |
||
| 64 | if ($this->identical) { |
||
| 65 | return new Result($this->isIdenticalToExpectedValue($input, $encoding), $input, $this); |
||
| 66 | } |
||
| 67 | |||
| 68 | return new Result($this->isEqualToExpectedValue($input, $encoding), $input, $this); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Verifies if the input is equal to the expected value. |
||
| 73 | * |
||
| 74 | * @param string $input |
||
| 75 | * @param string $encoding |
||
| 76 | * |
||
| 77 | * @return bool |
||
| 78 | */ |
||
| 79 | private function isEqualToExpectedValue(string $input, string $encoding): bool |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Verifies if the input is identical to the expected value. |
||
| 86 | * |
||
| 87 | * @param string $input |
||
| 88 | * @param string $encoding |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | private function isIdenticalToExpectedValue(string $input, string $encoding): bool |
||
| 96 | } |
||
| 97 |