| Total Complexity | 5 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 5 | ||
| Bugs | 0 | Features | 3 |
| 1 | <?php |
||
| 7 | class Forwarding |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @const |
||
| 11 | */ |
||
| 12 | public const CONTAINER_KEY = '_forwarding'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | public string $pendingClass; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Initialize the forwarding. |
||
| 21 | * |
||
| 22 | * @return self |
||
| 23 | */ |
||
| 24 | 15 | public static function enable(): self |
|
| 25 | { |
||
| 26 | 15 | return new self(); |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Define the pending class. |
||
| 31 | * |
||
| 32 | * @param string $class |
||
| 33 | * |
||
| 34 | * @return $this |
||
| 35 | */ |
||
| 36 | 15 | public function from(string $class): static |
|
| 37 | { |
||
| 38 | 15 | $this->pendingClass = $this->resolve($class); |
|
| 39 | |||
| 40 | 15 | return $this; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Define the forwarding for the pending class set previously. |
||
| 45 | * |
||
| 46 | * @param string $destination |
||
| 47 | * |
||
| 48 | * @return $this |
||
| 49 | */ |
||
| 50 | 15 | public function to(string $destination): static |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Extract an implementation from the interface if passed. |
||
| 62 | * |
||
| 63 | * @param string $class |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | 15 | protected function resolve(string $class): string |
|
| 70 | } |
||
| 71 | } |
||
| 72 |