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

RolePresenter::formattedColor()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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