Field   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 64
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
parseValue() 0 1 ?
A __construct() 0 5 1
A parseAttributes() 0 13 3
A getValue() 0 4 1
A parseAttributesWithKeys() 0 18 4
1
<?php
2
3
namespace MadWeb\Seoable\Fields;
4
5
abstract class Field
6
{
7
    /** @var \Illuminate\Database\Eloquent\Model */
8
    protected $model;
9
10
    /** @var string|array */
11
    protected $value;
12
13 12
    public function __construct($value, $model)
14
    {
15 12
        $this->model = $model;
16 12
        $this->value = $this->parseValue($value);
17 12
    }
18
19
    /** @param array|string $attributes */
20 12
    protected function parseAttributesWithKeys($attributes): array
21
    {
22 12
        $result = [];
23 12
        if (is_array($attributes)) {
24 3
            foreach ($attributes as $key => $field) {
25 3
                $value = $this->model->getAttribute($field);
26 3
                if (is_numeric($key)) {
27 3
                    $result[$field] = $value;
28
                } else {
29
                    $result[$key] = $value;
30
                }
31
            }
32
        } else {
33 12
            $result[$attributes] = $this->model->getAttribute($attributes);
34
        }
35
36 12
        return $result;
37
    }
38
39
    /**
40
     * @param array|string $attributes
41
     * @return array|string
42
     */
43 9
    protected function parseAttributes($attributes)
44
    {
45 9
        $result = [];
46 9
        if (is_array($attributes)) {
47 6
            foreach ($attributes as $key => $field) {
48 6
                $result[] = $this->model->getAttribute($field);
49
            }
50
        } else {
51 3
            return $this->model->getAttribute($attributes);
52
        }
53
54 6
        return $result;
55
    }
56
57
    /** @return mixed */
58 12
    public function getValue()
59
    {
60 12
        return $this->value;
61
    }
62
63
    /**
64
     * @param array|string $value
65
     * @return mixed
66
     */
67
    abstract protected function parseValue($value);
68
}
69