Command   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPaths() 0 12 3
A __construct() 0 5 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 Composer\Command\BaseCommand;
19
use ComposerLink\PathHelper;
20
use ComposerLink\Plugin;
21
use Symfony\Component\Console\Input\InputInterface;
22
23
abstract class Command extends BaseCommand
24
{
25
    protected Plugin $plugin;
26
27
    public function __construct(Plugin $plugin)
28
    {
29
        parent::__construct();
30
31
        $this->plugin = $plugin;
32
    }
33
34
    /**
35
     * @return PathHelper[]
36
     */
37
    protected function getPaths(InputInterface $input): array
38
    {
39
        $helper = new PathHelper($input->getArgument('path'));
40
41
        // When run in global we should transform path to absolute path
42
        if ($this->plugin->isGlobal()) {
43
            /** @var string $working */
44
            $working = $this->getApplication()->getInitialWorkingDirectory();
45
            $helper = $helper->toAbsolutePath($working);
46
        }
47
48
        return $helper->isWildCard() ? $helper->getPathsFromWildcard() : [$helper];
49
    }
50
}
51