ParsesCliParameters::parseArguments()   A
last analyzed

Complexity

Conditions 5
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 1
nop 0
dl 0
loc 15
rs 9.4555
c 0
b 0
f 0
1
<?php
2
3
namespace Reallyli\LaravelDeployer\Concerns;
4
5
use Symfony\Component\Console\Input\ArrayInput;
6
7
trait ParsesCliParameters
8
{
9
    public function getParametersAsString($parameters = null)
10
    {
11
        $parameters = $parameters ?? $this->getParameters();
12
13
        return (string) new ArrayInput($parameters->toArray(), null);
14
    }
15
16
    public function getParameters()
17
    {
18
        return $this->parseArguments()
19
            ->merge($this->parseOptions())
20
            ->merge($this->parseVerbosityLevel());
21
    }
22
23
    public function parseArguments()
24
    {
25
        return collect($this->arguments())
0 ignored issues
show
Bug introduced by
The method arguments() does not exist on Reallyli\LaravelDeployer...rns\ParsesCliParameters. Did you maybe mean parseArguments()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
26
            ->reject(function ($value) {
27
                return ! $value && ! is_string($value) && ! is_numeric($value);
28
            })
29
            ->pipe(function ($arguments) {
30
                $command = $arguments->get('command');
31
32
                return $command && $arguments->get(0) === $command
33
                    ? $arguments->forget(0)
34
                    : $arguments;
35
            })
36
            ->forget('command');
37
    }
38
39
    public function parseOptions()
40
    {
41
        $i = 0;
42
43
        return collect($this->options())
0 ignored issues
show
Bug introduced by
The method options() does not exist on Reallyli\LaravelDeployer...rns\ParsesCliParameters. Did you maybe mean parseOptions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
44
            ->filter(function ($value) {
45
                return $value || is_string($value) || is_numeric($value);
46
            })
47
            ->mapWithKeys(function ($value, $key) use (&$i) {
48
                return is_bool($value) ? [$i++ => "--$key"] : ["--$key" => $value];
49
            });
50
    }
51
52
    public function parseVerbosityLevel()
53
    {
54
        if ($this->getOutput()->isDebug()) {
0 ignored issues
show
Bug introduced by
It seems like getOutput() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
55
            return ['-vvv'];
56
        }
57
        if ($this->getOutput()->isVeryVerbose()) {
0 ignored issues
show
Bug introduced by
It seems like getOutput() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
            return ['-vv'];
59
        }
60
        if ($this->getOutput()->isVerbose()) {
0 ignored issues
show
Bug introduced by
It seems like getOutput() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
            return ['-v'];
62
        }
63
        if ($this->getOutput()->isQuiet()) {
0 ignored issues
show
Bug introduced by
It seems like getOutput() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
64
            return ['-q'];
65
        }
66
67
        return [];
68
    }
69
}
70