Passed
Push — main ( 7a1b02...93f154 )
by Roman
10:47 queued 08:24
created

HasUserSidebarFields   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A getUserAvatarAttribute() 0 4 2
A getNameAttribute() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KielD01\LaravelMaterialDashboardPro\Traits;
6
7
/**
8
 * Trait HasSidebarFields
9
 * @package KielD01\LaravelMaterialDashboardPro\Traits
10
 * @property array attributes
11
 * @property array appends
12
 */
13
trait HasUserSidebarFields
14
{
15
	protected $nameFields = [];
16
	protected $avatarField = 'avatar';
17
18
	public function initialize(): void
19
	{
20
		$this->appends = array_merge(
21
			$this->appends,
22
			['name', 'userAvatar']
23
		);
24
	}
25
26
	public function getNameAttribute(): string
27
	{
28
		$name = [];
29
30
		foreach ($this->nameFields as $field) {
31
			if (array_key_exists($field, $this->attributes)) {
32
				$name[] = $field;
33
			}
34
		}
35
36
		return implode(' ', $name);
37
	}
38
39
	public function getUserAvatarAttribute()
40
	{
41
		if (!array_key_exists($this->avatarField, $this->attributes)) {
42
			return;
43
		}
44
	}
45
}
46