Psr4PathGenerator::getPath()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 18

Duplication

Lines 3
Ratio 16.67 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 0
Metric Value
dl 3
loc 18
ccs 10
cts 11
cp 0.9091
rs 9.3554
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5.0187
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