|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NonEmptyStringStrContains; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +class Foo { |
| 8 | + /** |
| 9 | + * @param non-empty-string $nonES |
| 10 | + * @param numeric-string $numS |
| 11 | + * @param literal-string $literalS |
| 12 | + * @param non-empty-string&numeric-string $nonEAndNumericS |
| 13 | + */ |
| 14 | + public function strContains(string $s, string $s2, $nonES, $numS, $literalS, $nonEAndNumericS, int $i): void |
| 15 | + { |
| 16 | + if (str_contains($s, ':')) { |
| 17 | + assertType('non-empty-string', $s); |
| 18 | + } |
| 19 | + assertType('string', $s); |
| 20 | + |
| 21 | + if (str_contains($s, $s2)) { |
| 22 | + assertType('string', $s); |
| 23 | + } |
| 24 | + |
| 25 | + if (str_contains($s, $nonES)) { |
| 26 | + assertType('non-empty-string', $s); |
| 27 | + } |
| 28 | + if (str_contains($s, $numS)) { |
| 29 | + assertType('non-empty-string', $s); |
| 30 | + } |
| 31 | + if (str_contains($s, $literalS)) { |
| 32 | + assertType('string', $s); |
| 33 | + } |
| 34 | + |
| 35 | + if (str_contains($s, $nonEAndNumericS)) { |
| 36 | + assertType('non-empty-string', $s); |
| 37 | + } |
| 38 | + if (str_contains($numS, $nonEAndNumericS)) { |
| 39 | + assertType('non-empty-string&numeric-string', $numS); |
| 40 | + } |
| 41 | + |
| 42 | + if (str_contains($nonES, $s)) { |
| 43 | + assertType('non-empty-string', $nonES); |
| 44 | + } |
| 45 | + if (str_contains($nonEAndNumericS, $s)) { |
| 46 | + assertType('non-empty-string&numeric-string', $nonEAndNumericS); |
| 47 | + } |
| 48 | + |
| 49 | + if (str_contains($i, $s2)) { |
| 50 | + assertType('int', $i); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public function variants(string $s) { |
| 55 | + if (fnmatch("*gr[ae]y", $s)) { |
| 56 | + assertType('non-empty-string', $s); |
| 57 | + } |
| 58 | + assertType('string', $s); |
| 59 | + |
| 60 | + if (str_starts_with($s, ':')) { |
| 61 | + assertType('non-empty-string', $s); |
| 62 | + } |
| 63 | + assertType('string', $s); |
| 64 | + |
| 65 | + if (str_ends_with($s, ':')) { |
| 66 | + assertType('non-empty-string', $s); |
| 67 | + } |
| 68 | + assertType('string', $s); |
| 69 | + |
| 70 | + if (strpos($s, ':') !== false) { |
| 71 | + assertType('non-empty-string', $s); |
| 72 | + } |
| 73 | + assertType('string', $s); |
| 74 | + if (strpos($s, ':') === false) { |
| 75 | + assertType('string', $s); |
| 76 | + } |
| 77 | + assertType('string', $s); |
| 78 | + |
| 79 | + if (strpos($s, ':') === 5) { |
| 80 | + assertType('string', $s); // could be non-empty-string |
| 81 | + } |
| 82 | + assertType('string', $s); |
| 83 | + if (strpos($s, ':') !== 5) { |
| 84 | + assertType('string', $s); |
| 85 | + } |
| 86 | + assertType('string', $s); |
| 87 | + |
| 88 | + if (strrpos($s, ':') !== false) { |
| 89 | + assertType('non-empty-string', $s); |
| 90 | + } |
| 91 | + assertType('string', $s); |
| 92 | + |
| 93 | + if (stripos($s, ':') !== false) { |
| 94 | + assertType('non-empty-string', $s); |
| 95 | + } |
| 96 | + assertType('string', $s); |
| 97 | + |
| 98 | + if (strripos($s, ':') !== false) { |
| 99 | + assertType('non-empty-string', $s); |
| 100 | + } |
| 101 | + assertType('string', $s); |
| 102 | + |
| 103 | + if (strstr($s, ':') === 'hallo') { |
| 104 | + assertType('string', $s); // could be non-empty-string |
| 105 | + } |
| 106 | + assertType('string', $s); |
| 107 | + if (strstr($s, ':', true) === 'hallo') { |
| 108 | + assertType('string', $s); // could be non-empty-string |
| 109 | + } |
| 110 | + assertType('string', $s); |
| 111 | + if (strstr($s, ':', true) !== false) { |
| 112 | + assertType('non-empty-string', $s); |
| 113 | + } |
| 114 | + assertType('string', $s); |
| 115 | + if (strstr($s, ':', true) === false) { |
| 116 | + assertType('string', $s); |
| 117 | + } else { |
| 118 | + assertType('non-empty-string', $s); |
| 119 | + } |
| 120 | + assertType('string', $s); |
| 121 | + } |
| 122 | + |
| 123 | +} |
0 commit comments