Passed
Push — master ( 5d5c93...4556a9 )
by Daniel
02:35
created

executeForSingleRepository()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 18
rs 9.9666
1
<?php
2
3
namespace Dandelion\Operation;
4
5
use Dandelion\Console\Command\SplitRepositoryInitCommand;
6
use Dandelion\Exception\RepositoryNotFoundException;
7
8
class SplitRepositoryInitializer extends AbstractOperation implements SplitRepositoryInitializerInterface
9
{
10
    /**
11
     * @param string $repositoryName
12
     *
13
     * @return \Dandelion\Operation\SplitRepositoryInitializerInterface
14
     */
15
    public function executeForSingleRepository(string $repositoryName): SplitRepositoryInitializerInterface
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
26
        if ($platform->existsSplitRepository($repositoryName)) {
27
            return $this;
28
        }
29
30
        $platform->initSplitRepository($repositoryName);
31
32
        return $this;
33
    }
34
35
    /**
36
     * @param string[] $commandArguments
37
     *
38
     * @return string[]
39
     */
40
    protected function getCommand(array $commandArguments): array
41
    {
42
        return array_merge(
43
            [
44
                DANDELION_BINARY,
45
                SplitRepositoryInitCommand::NAME,
46
            ],
47
            $commandArguments
48
        );
49
    }
50
}
51