| Total Complexity | 7 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Link implements LinkGenerator |
||
| 9 | { |
||
| 10 | protected $model; |
||
| 11 | |||
| 12 | protected $attributes; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Instantiate the generator with the linkable model |
||
| 16 | * |
||
| 17 | * @param Linkable $model |
||
| 18 | * @param array $attributes |
||
| 19 | */ |
||
| 20 | 18 | public function __construct(Linkable $model, array $attributes = []) |
|
| 21 | { |
||
| 22 | 18 | $this->model = $model; |
|
| 23 | 18 | $this->setAttributes($attributes); |
|
| 24 | 18 | } |
|
| 25 | |||
| 26 | /** |
||
| 27 | * Get the link href for a given model |
||
| 28 | * |
||
| 29 | * @param $model |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | 15 | public function href() : string |
|
| 33 | { |
||
| 34 | 15 | return (string) url($this->model->slug ?? '/'); |
|
|
|
|||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get the link text for a given model |
||
| 39 | * |
||
| 40 | * @param $model |
||
| 41 | * @param array $options |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | 15 | public function label() : string |
|
| 45 | { |
||
| 46 | 15 | return (string) $this->model->name; |
|
| 47 | } |
||
| 48 | |||
| 49 | 3 | public function getAttributes() : HtmlAttributes |
|
| 50 | { |
||
| 51 | 3 | return $this->attributes; |
|
| 52 | } |
||
| 53 | |||
| 54 | 18 | public function setAttributes(array $attributes) |
|
| 55 | { |
||
| 56 | 18 | $this->attributes = HtmlAttributes::make($attributes); |
|
| 57 | 18 | return $this; |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Generate an HTML link for the model |
||
| 62 | * |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | 12 | public function toHtml() |
|
| 69 | HTML; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Cast the generator to a string |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | 6 | public function __toString() : string |
|
| 80 | } |
||
| 81 | } |
||
| 82 |