| Total Complexity | 10 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class Patron |
||
| 10 | { |
||
| 11 | /** @var string */ |
||
| 12 | private $origen; |
||
| 13 | |||
| 14 | /** @var string */ |
||
| 15 | private $expresion; |
||
| 16 | |||
| 17 | /** @var string */ |
||
| 18 | private $alEstarVacio; |
||
| 19 | |||
| 20 | public const VACIO_PERMITE_NADA = 'NADA'; |
||
| 21 | |||
| 22 | public const VACIO_PERMITE_TODO = 'TODO'; |
||
| 23 | |||
| 24 | 59 | public function __construct(string $origen, string $alEstarVacio = self::VACIO_PERMITE_TODO) |
|
| 25 | { |
||
| 26 | 59 | if ('' === $origen && self::VACIO_PERMITE_TODO === $alEstarVacio) { |
|
| 27 | // cualquier caracter no espaciado vertical, de 0 a N veces |
||
| 28 | 11 | $expresion = '\V*'; |
|
| 29 | } else { |
||
| 30 | 54 | $expresion = $origen; |
|
| 31 | } |
||
| 32 | 59 | $expresion = '/^' . $expresion . '$/u'; |
|
| 33 | 59 | if (! $this->expresionEsValida($expresion)) { |
|
| 34 | 5 | throw new PatronException($expresion); |
|
| 35 | } |
||
| 36 | |||
| 37 | 56 | $this->origen = $origen; |
|
| 38 | 56 | $this->expresion = $expresion; |
|
| 39 | 56 | $this->alEstarVacio = $alEstarVacio; |
|
| 40 | } |
||
| 41 | |||
| 42 | 23 | public function origen(): string |
|
| 43 | { |
||
| 44 | 23 | return $this->origen; |
|
| 45 | } |
||
| 46 | |||
| 47 | 4 | public function expresion(): string |
|
| 50 | } |
||
| 51 | |||
| 52 | 11 | public function alEstarVacio(): string |
|
| 55 | } |
||
| 56 | |||
| 57 | 4 | public function evalua(string $texto): bool |
|
| 61 | } |
||
| 62 | |||
| 63 | 59 | public function expresionEsValida(string $expresion): bool |
|
| 67 | } |
||
| 68 | |||
| 69 | 1 | public function __toString(): string |
|
| 74 |