LinkedCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 25 5
A configure() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the composer-link plugin.
7
 *
8
 * Copyright (c) 2021-2022 Sander Visser <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE.md
11
 * file that was distributed with this source code.
12
 *
13
 * @link https://github.com/SanderSander/composer-link
14
 */
15
16
namespace ComposerLink\Commands;
17
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class LinkedCommand extends Command
22
{
23
    protected function configure(): void
24
    {
25
        $this->setName('linked');
26
        $this->setDescription('List all linked packages');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output): int
33
    {
34
        $linkedPackages = $this->plugin->getRepository()->all();
35
        if (count($linkedPackages) === 0) {
36
            $output->writeln('No packages are linked');
37
38
            return 0;
39
        }
40
41
        $longest = 0;
42
        foreach ($linkedPackages as $linkedPackage) {
43
            if (strlen($linkedPackage->getName()) > $longest) {
44
                $longest = strlen($linkedPackage->getName());
45
            }
46
        }
47
48
        foreach ($linkedPackages as $linkedPackage) {
49
            $output->writeln(sprintf(
50
                "%s\t%s",
51
                str_pad($linkedPackage->getName(), $longest),
52
                $linkedPackage->getPath()
53
            ));
54
        }
55
56
        return 0;
57
    }
58
}
59