Psr4PathGenerator::getPath()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16

Duplication

Lines 3
Ratio 18.75 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 0
Metric Value
dl 3
loc 16
ccs 9
cts 10
cp 0.9
rs 9.4222
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5.025
1
<?php
2
namespace Goetas\Xsd\XsdToPhp\Php\PathGenerator;
3
4
use Goetas\Xsd\XsdToPhp\PathGenerator\PathGeneratorException;
5
use Goetas\Xsd\XsdToPhp\PathGenerator\Psr4PathGenerator as Psr4PathGeneratorBase;
6
use Goetas\Xsd\XsdToPhp\Php\Structure\PHPClass;
7
8
class Psr4PathGenerator extends Psr4PathGeneratorBase implements PathGenerator
9
{
10
11 3
    public function getPath(PHPClass $php)
12
    {
13 3
        foreach ($this->namespaces as $namespace => $dir) {
14 3
            if (strpos(trim($php->getNamespace()) . "\\", $namespace) === 0) {
15 2
                $d = strtr(substr($php->getNamespace(), strlen($namespace)), "\\", "/");
16 2
                $dir = rtrim($dir, "/") . "/" . $d;
17 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...
18
                    throw new PathGeneratorException("Can't create the '$dir' directory");
19
                }
20
21 2
                return rtrim($dir, "/") . "/" . $php->getName() . ".php";
22
            }
23 1
        }
24
25 1
        throw new PathGeneratorException("Can't find a defined location where save '$php' object");
26
    }
27
}
28
29