RepositoryCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifierSuggestion() 0 3 1
A registerRepository() 0 16 1
1
<?php
2
3
namespace Startwind\Forrest\CliCommand\Repository;
4
5
use Startwind\Forrest\CliCommand\ForrestCommand;
6
7
abstract class RepositoryCommand extends ForrestCommand
8
{
9
    /**
10
     * Normalize the repository name to fit as an identifier.
11
     */
12
    protected function getIdentifierSuggestion(string $name): string
13
    {
14
        return strtolower(str_replace(' ', '-', $name));
15
    }
16
17
    /**
18
     * Register a new repository
19
     */
20
    protected function registerRepository(string $identifier, string $name, string $description, string $repositoryFileName): void
21
    {
22
        $repoArray = [
23
            'adapter' => 'yaml',
24
            'name' => $name,
25
            'description' => $description,
26
            'config' => [
27
                'file' => $repositoryFileName
28
            ]
29
        ];
30
31
        $configHandler = $this->getConfigHandler();
32
33
        $config = $configHandler->parseConfig();
34
        $config->addRepository($identifier, $repoArray);
35
        $configHandler->dumpConfig($config);
36
    }
37
}
38