LongNamingStrategy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 17.78 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 8
loc 45
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeName() 0 4 1
A getAnonymousTypeName() 0 4 1
A getItemName() 8 8 2
A getPropertyName() 0 4 1
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 LongNamingStrategy 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
    public function getTypeName(Type $type)
25
    {
26
        return $this->classify($type->getName()) . "Type";
27
    }
28
29
    public function getAnonymousTypeName(Type $type, $parentName)
30
    {
31
        return $this->classify($parentName) . "AnonymousType";
32
    }
33
34 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...
35
    {
36
        $name = $this->classify($item->getName());
37
        if (in_array(strtolower($name), $this->reservedWords)) {
38
            $name .= 'Xsd';
39
        }
40
        return $name;
41
    }
42
43
    public function getPropertyName($item)
44
    {
45
        return Inflector::camelize(str_replace(".", " ", $item->getName()));
46
    }
47
48
    private function classify($name)
49
    {
50
        return Inflector::classify(str_replace(".", " ", $name));
51
    }
52
}
53