Passed
Push — master ( a6005d...2dc161 )
by Brice
02:02
created

UpdateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
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\Exception\InvalidArgumentException;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
final class UpdateCommand extends Command
15
{
16
    /** @var Gitlab */
17
    private $gitlab;
18
19
    /** @var GitlabRepositoryManager */
20
    private $repositoryManager;
21
22
    public function __construct(Gitlab $gitlab, GitlabRepositoryManager $repositoryManager)
23
    {
24
        $this->gitlab = $gitlab;
25
        $this->repositoryManager = $repositoryManager;
26
27
        parent::__construct();
28
    }
29
30
    public function configure()
31
    {
32
        $this
33
            ->setName('update')
34
            ->setDescription('Update a GitLab project in CompoLab')
35
            ->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.')
36
            ->addArgument('project', InputArgument::REQUIRED, 'Project ID (can be found from GitLab in project settings')
37
        ;
38
    }
39
40
    public function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $projectId = $input->getArgument('project');
43
44
        $output->write(sprintf('Find project %d from GitLab...', $projectId));
0 ignored issues
show
Bug introduced by
It seems like $projectId can also be of type string[]; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $output->write(sprintf('Find project %d from GitLab...', /** @scrutinizer ignore-type */ $projectId));
Loading history...
45
46
        $project = (new Project($projectId, $this->gitlab))->show();
47
        if (!$project) {
0 ignored issues
show
introduced by
$project is of type Gitlab\Model\Project, thus it always evaluated to true.
Loading history...
48
            throw new InvalidArgumentException(sprintf('Impossible to retrieve Gitlab project %d', $projectId));
49
        }
50
51
        $output->writeln(' OK');
52
53
        $output->write('Update project in CompoLab...');
54
55
        $this->repositoryManager->registerProject($project);
56
        $this->repositoryManager->save();
57
58
        $output->writeln(' OK');
59
60
        $output->writeln('Finished');
61
    }
62
}
63