We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php | ||
| 25 | final class Contains implements Rule | ||
| 26 | { | ||
| 27 | /** | ||
| 28 | * @var mixed | ||
| 29 | */ | ||
| 30 | private $expectedValue; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * @var bool | ||
| 34 | */ | ||
| 35 | private $identical; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Initializes the rule. | ||
| 39 | * | ||
| 40 | * @param mixed $expectedValue | ||
| 41 | * @param bool $identical | ||
| 42 | */ | ||
| 43 | 1 | public function __construct($expectedValue, bool $identical = false) | |
| 48 | |||
| 49 | /** | ||
| 50 |      * {@inheritdoc} | ||
| 51 | */ | ||
| 52 | 81 | public function apply($input): Result | |
| 53 |     { | ||
| 54 | 81 |         if (is_array($input)) { | |
| 55 | 36 | return new Result(in_array($this->expectedValue, $input, $this->identical), $input, $this); | |
| 56 | } | ||
| 57 | |||
| 58 | 45 | $stringValResult = (new StringVal())->apply($input); | |
| 59 | 45 |         if (!$stringValResult->isValid()) { | |
| 60 | 1 | return new Result(false, $input, $this, [], $stringValResult); | |
| 61 | } | ||
| 62 | |||
| 63 | 44 | $encoding = mb_detect_encoding($input); | |
| 64 | 44 |         if ($this->identical) { | |
| 65 | 24 | return new Result($this->isIdenticalToExpectedValue($input, $encoding), $input, $this); | |
| 66 | } | ||
| 67 | |||
| 68 | 20 | 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 | 20 | 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 | 24 | private function isIdenticalToExpectedValue(string $input, string $encoding): bool | |
| 96 | } | ||
| 97 |