Failed Conditions
Push — master ( c3b9f6...b14904 )
by Yo
02:03
created

NamespaceResolver::resolve()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 19
cp 0
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 14
nc 6
nop 3
crap 20
1
<?php
2
namespace Yoanm\DefaultPhpRepository\Resolver;
3
4
use Yoanm\DefaultPhpRepository\Command\RepositorySubType;
5
use Yoanm\DefaultPhpRepository\Command\RepositoryType;
6
use Yoanm\DefaultPhpRepository\Model\Template;
7
8
/**
9
 * Class NamespaceResolver
10
 */
11
class NamespaceResolver
12
{
13
    /** Repository type namespaces */
14
    const LIBRARY_NAMESPACE = 'library';
15
    const PROJECT_NAMESPACE = 'project';
16
17
    /** Repository sub type namespaces */
18
    const SYMFONY_LIBRARY_NAMESPACE = 'symfony-library';
19
20
    /**
21
     * @param Template[] $templateList
22
     * @param string     $repositoryType
23
     * @param string     $repositorySubType
24
     */
25
    public function resolve(array $templateList, $repositoryType, $repositorySubType)
26
    {
27
        $namespace = RepositoryType::LIBRARY === $repositoryType
28
            ? self::LIBRARY_NAMESPACE
29
            : self::PROJECT_NAMESPACE
30
        ;
31
        // Override base namespace for specific files
32
        if (RepositoryType::LIBRARY === $repositoryType) {
33
            $this->setNamespace($templateList, 'composer.config', $namespace);
34
            $this->setNamespace($templateList, 'git.gitignore', $namespace);
35
            $this->setNamespace($templateList, 'git.readme', $namespace);
36
37
            // Override with sub type
38
            if (RepositorySubType::SYMFONY === $repositorySubType) {
39
                $subNamespace = self::SYMFONY_LIBRARY_NAMESPACE;
40
                $this->setNamespace($templateList, 'ci.travis', $subNamespace);
41
                $this->setNamespace($templateList, 'git.readme', $subNamespace);
42
            }
43
        } else {
44
            $this->setNamespace($templateList, 'ci.scrutinizer', $namespace);
45
        }
46
    }
47
48
    /**
49
     * @param Template[] $templateList
50
     * @param string     $key
51
     * @param string     $namespace
52
     */
53
    protected function setNamespace(array $templateList, $key, $namespace)
54
    {
55
        if (isset($templateList[$key])) {
56
            $templateList[$key]->setNamespace($namespace);
57
        }
58
    }
59
}
60