Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ReadsRouteAttribute | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |
100.00% |
1 / 1 |
| getRouteAttribute | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\Concerns; |
| 3 | |
| 4 | use Apie\Core\Attributes\Route; |
| 5 | |
| 6 | trait ReadsRouteAttribute |
| 7 | { |
| 8 | private ?Route $routeAttribute; |
| 9 | |
| 10 | private bool $routeCalculated = false; |
| 11 | |
| 12 | private function getRouteAttribute(): ?Route |
| 13 | { |
| 14 | if (!$this->routeCalculated) { |
| 15 | $this->routeAttribute = null; |
| 16 | $this->routeCalculated = true; |
| 17 | foreach ($this->method->getAttributes(Route::class) as $routeAttribute) { |
| 18 | $route = $routeAttribute->newInstance(); |
| 19 | if (in_array($route->target, [Route::ALL, self::CURRENT_TARGET])) { |
| 20 | if (!$this->routeAttribute || $route->target === self::CURRENT_TARGET) { |
| 21 | $this->routeAttribute = $route; |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | return $this->routeAttribute; |
| 27 | } |
| 28 | } |