Completed
Push — master ( d8bbba...ff2348 )
by Rougin
04:25
created

Parser::column()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Rougin\Refinery;
4
5
/**
6
 * Parser
7
 *
8
 * @package Refinery
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 */
11
class Parser
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $column = '';
17
18
    /**
19
     * @var string
20
     */
21
    protected $command = '';
22
23
    /**
24
     * @var string
25
     */
26
    protected $table = '';
27
28
    /**
29
     * Initializes the parser instance.
30
     *
31
     * @param string $name
32
     */
33
    public function __construct($name)
34
    {
35
        $allowed = implode('|', $this->commands());
36
37
        $pattern = '/(' . $allowed . ')_(.*)_table/';
38
39
        preg_match($pattern, $name, $matches);
40
41
        $this->table = (string) $matches[2];
42
43
        $this->command = (string) $matches[1];
44
45
        $pattern = (string) '/(.*)_in_(.*)/';
46
47
        preg_match($pattern, $matches[2], $matches);
48
49
        if (isset($matches[0])) {
50
            $this->column = $matches[1];
51
52
            $this->table = $matches[2];
53
        }
54
    }
55
56
    /**
57
     * Returns an array of commands.
58
     *
59
     * @return string[]
60
     */
61
    public function commands()
62
    {
63
        $commands = array();
64
65
        $commands[] = 'add';
66
        $commands[] = 'create';
67
        $commands[] = 'delete';
68
        $commands[] = 'modify';
69
        $commands[] = 'remove';
70
        $commands[] = 'update';
71
72
        return $commands;
73
    }
74
75
    /**
76
     * Returns the command.
77
     *
78
     * @return string
79
     */
80
    public function command()
81
    {
82
        return $this->command;
83
    }
84
85
    /**
86
     * Returns the column.
87
     *
88
     * @return string
89
     */
90
    public function column()
91
    {
92
        return $this->column;
93
    }
94
95
    /**
96
     * Returns the table.
97
     *
98
     * @return string
99
     */
100
    public function table()
101
    {
102
        return $this->table;
103
    }
104
}
105