Psr4PathGenerator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 13.64 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 3
loc 22
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getPath() 3 18 5

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 Goetas\Xsd\XsdToPhp\Jms\PathGenerator;
3
4
use Goetas\Xsd\XsdToPhp\PathGenerator\PathGeneratorException;
5
use Goetas\Xsd\XsdToPhp\PathGenerator\Psr4PathGenerator as Psr4PathGeneratorBase;
6
7
class Psr4PathGenerator extends Psr4PathGeneratorBase implements PathGenerator
8
{
9
10 3
    public function getPath($yaml)
11
    {
12 3
        $ns = key($yaml);
13
14 3
        foreach ($this->namespaces as $namespace => $dir) {
15
16 3
            $pos = strpos($ns, $namespace);
17
18 3
            if ($pos === 0) {
19 2 View Code Duplication
                if (!is_dir($dir) && !mkdir($dir, 0777, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
20
                    throw new PathGeneratorException("Can't create the folder '$dir'");
21
                }
22 2
                $f = strtr(substr($ns, strlen($namespace)), "\\/", "..");
23 2
                return $dir . "/" . $f . ".yml";
24
            }
25 1
        }
26 1
        throw new PathGeneratorException("Can't find a defined location where save '$ns' metadata");
27
    }
28
}
29
30