ShortNamingStrategy   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 16.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 8
loc 49
ccs 16
cts 18
cp 0.8889
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeName() 0 8 3
A getAnonymousTypeName() 0 4 1
A getPropertyName() 0 4 1
A getItemName() 8 8 2
A classify() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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