PermissionParameter::withCustomID()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace EmilMoe\Guardian\Http;
4
5
class PermissionParameter
6
{
7
    /**
8
     * Name of ID column, will default to 'id'.
9
     *
10
     * @var string
11
     */
12
    private $column;
13
14
    /**
15
     * Name of the permission.
16
     *
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * Create a new PermissionParameter instance.
23
     *
24
     * PermissionParameter constructor.
25
     * @param $input
26
     */
27
    public function __construct($input)
28
    {
29
        strpos($input, '.') === false
30
            ? $this->withDefaultID($input)
31
            : $this->withCustomID(explode('.', $input));
32
    }
33
34
    /**
35
     * Get the permission name.
36
     *
37
     * @return string
38
     */
39
    public function getName()
40
    {
41
        return $this->name;
42
    }
43
44
    /**
45
     * Get the column name.
46
     *
47
     * @return string
48
     */
49
    public function getColumn()
50
    {
51
        return $this->column;
52
    }
53
54
    /**
55
     * Instantiate the instance with a column name 'id'.
56
     *
57
     * @param $permission
58
     */
59
    private function withDefaultID($permission)
60
    {
61
        $this->column = 'id';
62
        $this->name   = $permission;
63
    }
64
65
    /**
66
     * Instantiate the instance with a custom column name.
67
     *
68
     * @param array $args
69
     */
70
    private function withCustomID(array $args)
71
    {
72
        $this->name   = $args[0];
73
        $this->column = $args[1];
74
    }
75
}