| Total Complexity | 5 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 88.24% |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | final class Generator |
||
| 12 | { |
||
| 13 | /** @var Rule */ |
||
| 14 | private $rule; |
||
| 15 | |||
| 16 | /** @var int */ |
||
| 17 | private $length; |
||
| 18 | |||
| 19 | 1 | public function __construct(Rule $rule, int $length = 12) |
|
| 20 | { |
||
| 21 | 1 | $this->rule = $rule; |
|
| 22 | 1 | $this->length = $length; |
|
| 23 | 1 | } |
|
| 24 | |||
| 25 | 1 | public function __invoke() : string |
|
| 26 | { |
||
| 27 | try { |
||
| 28 | 1 | $password = $this->generate(); |
|
| 29 | |||
| 30 | 1 | $this->rule->__invoke($password); |
|
| 31 | |||
| 32 | 1 | return $password; |
|
| 33 | } catch (InvalidPassword $e) { |
||
| 34 | return $this->__invoke(); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | 1 | public function generate() : string |
|
| 50 | } |
||
| 51 | } |
||
| 52 |