UpdateCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 39
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 13 1
A __construct() 0 6 1
1
<?php
2
3
namespace CompoLab\Application\Cli;
4
5
use CompoLab\Application\GitlabRepositoryManager;
6
use Gitlab\Client as Gitlab;
7
use Gitlab\Model\Project;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
final class UpdateCommand extends Command
14
{
15
    /** @var Gitlab */
16
    private $gitlab;
17
18
    /** @var GitlabRepositoryManager */
19
    private $repositoryManager;
20
21
    public function __construct(Gitlab $gitlab, GitlabRepositoryManager $repositoryManager)
22
    {
23
        $this->gitlab = $gitlab;
24
        $this->repositoryManager = $repositoryManager;
25
26
        parent::__construct();
27
    }
28
29
    public function configure()
30
    {
31
        $this
32
            ->setName('update')
33
            ->setDescription('Update a GitLab project in CompoLab')
34
            ->setHelp('This command will update a specific project (tags and branches) in the packages.json file, and download associated package archives into the web-accessible cache directory.')
35
            ->addArgument('project', InputArgument::REQUIRED, 'Project ID (can be found from GitLab in project settings')
36
        ;
37
    }
38
39
    public function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $projectId = (int) $input->getArgument('project');
42
        $output->write(sprintf('Find project %d from GitLab...', $projectId));
43
        $project = (new Project($projectId, $this->gitlab))->show();
44
        $output->writeln(' OK');
45
46
        $output->write('Update project in CompoLab...');
47
        $this->repositoryManager->registerProject($project);
48
        $this->repositoryManager->save();
49
        $output->writeln(' OK');
50
51
        $output->writeln('Finished');
52
    }
53
}
54