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

BaseGenerator::transformField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 2
crap 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