UpdateCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
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