Completed
Push — master ( cfe8fe...f9982c )
by Rougin
04:59
created

BaseGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A transformField() 0 16 2
1
<?php
2
3
namespace Rougin\Combustor\Generator;
4
5
use Rougin\Describe\Describe;
6
use Rougin\Combustor\Common\Inflector;
7
8
/**
9
 * Base Generator
10
 * 
11
 * @package Combustor
12
 * @author  Rougin Royce Gutib <[email protected]>
13
 */
14
class BaseGenerator
15
{
16
    /**
17
     * @var \Rougin\Describe\Describe
18
     */
19
    protected $describe;
20
21
    /**
22
     * @var array
23
     */
24
    protected $data = [];
25
26
    /**
27
     * @param \Rougin\Describe\Describe $describe
28
     * @param array $data
29
     */
30 18
    public function __construct(Describe $describe, array $data)
31
    {
32 18
        $this->describe = $describe;
33 18
        $this->data = $data;
34 18
    }
35
36
    /**
37
     * Transforms the field into the template.
38
     * 
39
     * @param  string $field
40
     * @param  string $type
41
     * @return array
42
     */
43 12
    protected function transformField($field, $type)
44
    {
45 12
        if ($type == 'camelize') {
46
            return [
47 12
                'field' => lcfirst(Inflector::camelize($field)),
48 12
                'accessor' => lcfirst(Inflector::camelize('set_' . $field)),
49 12
                'mutator' => lcfirst(Inflector::camelize('get_' . $field))
50 12
            ];
51
        }
52
53
        return [
54 12
            'field' => lcfirst(Inflector::underscore($field)),
55 12
            'accessor' => lcfirst(Inflector::underscore('set_' . $field)),
56 12
            'mutator' => lcfirst(Inflector::underscore('get_' . $field))
57 12
        ];
58
    }
59
}
60