Passed
Push — 5.0.0 ( 631120...f07a46 )
by Fèvre
16:06
created

RolePresenter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A formattedColor() 0 7 2
1
<?php
2
3
namespace Xetaravel\Models\Presenters;
4
5
use Illuminate\Database\Eloquent\Casts\Attribute;
6
7
trait RolePresenter
8
{
9
    /**
10
     * The default color used for role without color.
11
     *
12
     * @var string
13
     */
14
    protected string $defaultColor = '';
15
16
    /**
17
     * Get the color of the role.
18
     *
19
     * @return Attribute
20
     */
21
    protected function formattedColor(): Attribute
22
    {
23
        return Attribute::make(
24
            get: function () {
25
                $color = $this->color ?: $this->defaultColor;
26
27
                return 'color:' . $color . ';';
28
            }
29
        );
30
    }
31
}
32