Parser::command()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Rougin\Refinery;
4
5
/**
6
 * Parser
7
 *
8
 * @package Refinery
9
 * @author  Rougin 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 48
    public function __construct($name)
34
    {
35 48
        $allowed = implode('|', $this->commands());
36
37 48
        $pattern = '/(' . $allowed . ')_(.*)_table/';
38
39 48
        preg_match($pattern, $name, $matches);
40
41 48
        $this->table = (string) $matches[2];
42
43 48
        $this->command = (string) $matches[1];
44
45 48
        $pattern = (string) '/(.*)_in_(.*)/';
46
47 48
        preg_match($pattern, $matches[2], $matches);
48
49 48
        if (isset($matches[0]))
50 16
        {
51 12
            $this->column = $matches[1];
52
53 12
            $this->table = $matches[2];
54 4
        }
55 48
    }
56
57
    /**
58
     * Returns an array of commands.
59
     *
60
     * @return string[]
61
     */
62 48
    public function commands()
63
    {
64 48
        $commands = array();
65
66 48
        $commands[] = 'add';
67 48
        $commands[] = 'create';
68 48
        $commands[] = 'delete';
69 48
        $commands[] = 'modify';
70 48
        $commands[] = 'remove';
71 48
        $commands[] = 'update';
72
73 48
        return $commands;
74
    }
75
76
    /**
77
     * Returns the command.
78
     *
79
     * @return string
80
     */
81 30
    public function command()
82
    {
83 30
        return $this->command;
84
    }
85
86
    /**
87
     * Returns the column.
88
     *
89
     * @return string
90
     */
91 39
    public function column()
92
    {
93 39
        return $this->column;
94
    }
95
96
    /**
97
     * Returns the table.
98
     *
99
     * @return string
100
     */
101 39
    public function table()
102
    {
103 39
        return $this->table;
104
    }
105
}
106