HasUserSidebarFields::getUserAvatarAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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