ShortNamingStrategy::getPropertyName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 1
crap 1
1
<?php
2
namespace GoetasWebservices\Xsd\XsdToPhp\Naming;
3
4
use Doctrine\Common\Inflector\Inflector;
5
use GoetasWebservices\XML\XSDReader\Schema\Item;
6
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
7
8
class ShortNamingStrategy implements NamingStrategy
9
{
10
    protected $reservedWords = [
11
        'int',
12
        'float',
13
        'bool',
14
        'string',
15
        'true',
16
        'false',
17
        'null',
18
        'resource',
19
        'object',
20
        'mixed',
21
        'numeric',
22
    ];
23
24 25
    public function getTypeName(Type $type)
25
    {
26 25
        $name = $this->classify($type->getName());
27 25
        if ($name && substr($name, -4) !== 'Type') {
28 25
            $name .= "Type";
29 25
        }
30 25
        return $name;
31
    }
32
33 4
    public function getAnonymousTypeName(Type $type, $parentName)
34
    {
35 4
        return $this->classify($parentName) . "AType";
36
    }
37
38 27
    public function getPropertyName($item)
39
    {
40 27
        return Inflector::camelize(str_replace(".", " ", $item->getName()));
41
    }
42
43 26 View Code Duplication
    public function getItemName(Item $item)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45 26
        $name = $this->classify($item->getName());
46 26
        if (in_array(strtolower($name), $this->reservedWords)) {
47
            $name .= 'Xsd';
48
        }
49 26
        return $name;
50
    }
51
52 48
    private function classify($name)
53
    {
54 48
        return Inflector::classify(str_replace(".", " ", $name));
55
    }
56
}
57