Passed
Pull Request — master (#95)
by Fèvre
16:45 queued 09:59
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
declare(strict_types=1);
4
5
namespace Xetaravel\Models\Presenters;
6
7
use Illuminate\Database\Eloquent\Casts\Attribute;
8
9
trait RolePresenter
10
{
11
    /**
12
     * The default color used for role without color.
13
     *
14
     * @var string
15
     */
16
    protected string $defaultColor = '';
17
18
    /**
19
     * Get the color of the role.
20
     *
21
     * @return Attribute
22
     */
23
    protected function formattedColor(): Attribute
24
    {
25
        return Attribute::make(
26
            get: function () {
27
                $color = $this->color ?: $this->defaultColor;
28
29
                return 'color:' . $color . ';';
30
            }
31
        );
32
    }
33
}
34