Passed
Pull Request — master (#15)
by Daniel
03:17
created

Initializer::executeForSingleRepository()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 19
rs 9.9332
1
<?php
2
3
namespace Dandelion\Operation;
4
5
use Dandelion\Console\Command\InitCommand;
6
use Dandelion\Exception\RepositoryNotFoundException;
7
8
class Initializer extends AbstractOperation implements InitializerInterface
9
{
10
    /**
11
     * @param string $repositoryName
12
     *
13
     * @return \Dandelion\Operation\InitializerInterface
14
     */
15
    public function executeForSingleRepository(string $repositoryName): InitializerInterface
16
    {
17
        $configuration = $this->configurationLoader->load();
18
        $repositories = $configuration->getRepositories();
19
20
        if (!$repositories->offsetExists($repositoryName)) {
21
            throw new RepositoryNotFoundException(sprintf('Could not find repository "%s".', $repositoryName));
22
        }
23
24
        $platform = $this->platformFactory->create($configuration->getVcs());
25
        $repository = $repositories->offsetGet($repositoryName);
26
27
        if ($platform->existsSplitRepository($repository)) {
28
            return $this;
29
        }
30
31
        $platform->initSplitRepository($repository);
32
33
        return $this;
34
    }
35
36
    /**
37
     * @param string[] $commandArguments
38
     *
39
     * @return string[]
40
     */
41
    protected function getCommand(array $commandArguments): array
42
    {
43
        return array_merge(
44
            [
45
                DANDELION_BINARY,
46
                InitCommand::NAME,
47
            ],
48
            $commandArguments
49
        );
50
    }
51
}
52