schmittjoh /
php-option
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * Copyright 2012 Johannes M. Schmitt <[email protected]> |
||
| 5 | * |
||
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
| 7 | * you may not use this file except in compliance with the License. |
||
| 8 | * You may obtain a copy of the License at |
||
| 9 | * |
||
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
| 11 | * |
||
| 12 | * Unless required by applicable law or agreed to in writing, software |
||
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
| 15 | * See the License for the specific language governing permissions and |
||
| 16 | * limitations under the License. |
||
| 17 | */ |
||
| 18 | |||
| 19 | namespace PhpOption; |
||
| 20 | |||
| 21 | use ArrayIterator; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @template T |
||
| 25 | * |
||
| 26 | * @extends Option<T> |
||
| 27 | */ |
||
| 28 | final class Some extends Option |
||
| 29 | { |
||
| 30 | /** @var T */ |
||
| 31 | private $value; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param T $value |
||
| 35 | */ |
||
| 36 | public function __construct($value) |
||
| 37 | { |
||
| 38 | $this->value = $value; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @template U |
||
| 43 | * |
||
| 44 | * @param U $value |
||
|
0 ignored issues
–
show
|
|||
| 45 | * |
||
| 46 | * @return Some<U> |
||
| 47 | */ |
||
| 48 | public static function create($value) |
||
| 49 | { |
||
| 50 | return new self($value); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function isDefined() |
||
| 54 | { |
||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function isEmpty() |
||
| 59 | { |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function get() |
||
| 64 | { |
||
| 65 | return $this->value; |
||
| 66 | } |
||
| 67 | |||
| 68 | public function getOrElse($default) |
||
| 69 | { |
||
| 70 | return $this->value; |
||
| 71 | } |
||
| 72 | |||
| 73 | public function getOrCall($callable) |
||
| 74 | { |
||
| 75 | return $this->value; |
||
| 76 | } |
||
| 77 | |||
| 78 | public function getOrThrow(\Exception $ex) |
||
| 79 | { |
||
| 80 | return $this->value; |
||
| 81 | } |
||
| 82 | |||
| 83 | public function orElse(Option $else) |
||
| 84 | { |
||
| 85 | return $this; |
||
| 86 | } |
||
| 87 | |||
| 88 | public function ifDefined($callable) |
||
| 89 | { |
||
| 90 | $this->forAll($callable); |
||
| 91 | } |
||
| 92 | |||
| 93 | public function forAll($callable) |
||
| 94 | { |
||
| 95 | $callable($this->value); |
||
| 96 | |||
| 97 | return $this; |
||
| 98 | } |
||
| 99 | |||
| 100 | public function map($callable) |
||
| 101 | { |
||
| 102 | return new self($callable($this->value)); |
||
| 103 | } |
||
| 104 | |||
| 105 | public function flatMap($callable) |
||
| 106 | { |
||
| 107 | /** @var mixed */ |
||
| 108 | $rs = $callable($this->value); |
||
| 109 | if (!$rs instanceof Option) { |
||
| 110 | throw new \RuntimeException('Callables passed to flatMap() must return an Option. Maybe you should use map() instead?'); |
||
| 111 | } |
||
| 112 | |||
| 113 | return $rs; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function filter($callable) |
||
| 117 | { |
||
| 118 | if (true === $callable($this->value)) { |
||
| 119 | return $this; |
||
| 120 | } |
||
| 121 | |||
| 122 | return None::create(); |
||
| 123 | } |
||
| 124 | |||
| 125 | public function filterNot($callable) |
||
| 126 | { |
||
| 127 | if (false === $callable($this->value)) { |
||
| 128 | return $this; |
||
| 129 | } |
||
| 130 | |||
| 131 | return None::create(); |
||
| 132 | } |
||
| 133 | |||
| 134 | public function select($value) |
||
| 135 | { |
||
| 136 | if ($this->value === $value) { |
||
| 137 | return $this; |
||
| 138 | } |
||
| 139 | |||
| 140 | return None::create(); |
||
| 141 | } |
||
| 142 | |||
| 143 | public function reject($value) |
||
| 144 | { |
||
| 145 | if ($this->value === $value) { |
||
| 146 | return None::create(); |
||
| 147 | } |
||
| 148 | |||
| 149 | return $this; |
||
| 150 | } |
||
| 151 | |||
| 152 | public function getIterator() |
||
| 153 | { |
||
| 154 | return new ArrayIterator([$this->value]); |
||
| 155 | } |
||
| 156 | |||
| 157 | public function foldLeft($initialValue, $callable) |
||
| 158 | { |
||
| 159 | return $callable($initialValue, $this->value); |
||
| 160 | } |
||
| 161 | |||
| 162 | public function foldRight($initialValue, $callable) |
||
| 163 | { |
||
| 164 | return $callable($this->value, $initialValue); |
||
| 165 | } |
||
| 166 | } |
||
| 167 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths