Passed
Pull Request — master (#19)
by mahdi
03:07
created

HasDetail   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
dl 0
loc 45
rs 10
c 2
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDetails() 0 3 1
A detail() 0 9 3
A getDetail() 0 3 1
1
<?php
2
3
namespace Shetabit\Payment\Traits;
4
5
trait HasDetail
6
{
7
    /**
8
     * details
9
     *
10
     * @var array
11
     */
12
    protected $details = [];
13
14
    /**
15
     * Set a piece of data to the details.
16
     *
17
     * @param $key
18
     * @param $value |null
0 ignored issues
show
Documentation Bug introduced by
The doc comment |null at position 0 could not be parsed: Unknown type name '|' at position 0 in |null.
Loading history...
19
     *
20
     * @return $this
21
     */
22
    public function detail($key, $value = null)
23
    {
24
        $key = is_array($key) ? $key : [$key => $value];
25
26
        foreach ($key as $k => $v) {
27
            $this->details[$k] = $v;
28
        }
29
30
        return $this;
31
    }
32
33
    /**
34
     * Retrieve detail using its name
35
     *
36
     * @param $name
37
     * @return string|null
38
     */
39
    public function getDetail($name)
40
    {
41
        return (string) $this->details[$name] ?? null;
42
    }
43
44
    /**
45
     * Get the value of details
46
     */
47
    public function getDetails() : array
48
    {
49
        return $this->details;
50
    }
51
}
52