Completed
Push — master ( 0bfae6...7513f1 )
by Bernhard
04:21
created

ArgsUtil   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 44.44%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 10
c 1
b 1
f 0
lcom 0
cbo 3
dl 0
loc 58
ccs 8
cts 18
cp 0.4444
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getPackageNames() 0 19 5
A getPackageNamesWithoutRoot() 0 15 4
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the puli/cli package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Cli\Util;
13
14
use Puli\Manager\Api\Package\PackageCollection;
15
use Webmozart\Console\Api\Args\Args;
16
17
/**
18
 * Utilities for inspecting {@link Args} instances.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class ArgsUtil
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
25
{
26
    /**
27
     * Returns the packages selected in the console arguments.
28
     *
29
     * @param Args              $args     The console arguments.
30
     * @param PackageCollection $packages The available packages.
31
     *
32
     * @return string[] The package names.
33
     */
34 36
    public static function getPackageNames(Args $args, PackageCollection $packages)
35
    {
36
        // Display all packages if "all" is set
37 36
        if ($args->isOptionSet('all')) {
38
            return $packages->getPackageNames();
39
        }
40
41 36
        $packageNames = array();
42
43 36
        if ($args->isOptionSet('root')) {
44 9
            $packageNames[] = $packages->getRootPackage()->getName();
45
        }
46
47 36
        foreach ($args->getOption('package') as $packageName) {
48 12
            $packageNames[] = $packageName;
49
        }
50
51 36
        return $packageNames ?: $packages->getPackageNames();
52
    }
53
54
    /**
55
     * Returns the non-root packages selected in the console arguments.
56
     *
57
     * @param Args              $args     The console arguments.
58
     * @param PackageCollection $packages The available packages.
59
     *
60
     * @return string[] The package names.
61
     */
62
    public static function getPackageNamesWithoutRoot(Args $args, PackageCollection $packages)
63
    {
64
        // Display all packages if "all" is set
65
        if ($args->isOptionSet('all')) {
66
            return $packages->getInstalledPackageNames();
67
        }
68
69
        $packageNames = array();
70
71
        foreach ($args->getOption('package') as $packageName) {
72
            $packageNames[] = $packageName;
73
        }
74
75
        return $packageNames ?: $packages->getInstalledPackageNames();
76
    }
77
78
    private function __construct()
79
    {
80
    }
81
}
82