HasDetail::getDetail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Shetabit\Multipay\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
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 $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