Issues (115)

src/Commands/InteractsWithInputs.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace VGirol\JsonApi\Commands;
4
5
trait InteractsWithInputs
6
{
7
    /**
8
     * Get the value of a command option.
9
     *
10
     * @param  string|null  $key
11
     * @return string|array|bool|null
12
     */
13
    public function option($key = null)
14
    {
15
        if (!is_null($key) && !$this->hasOption($key)) {
0 ignored issues
show
It seems like hasOption() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

15
        if (!is_null($key) && !$this->/** @scrutinizer ignore-call */ hasOption($key)) {
Loading history...
16
            return false;
17
        }
18
19
        return parent::option($key);
20
    }
21
22
    /**
23
     * Get the console command arguments.
24
     *
25
     * @return array
26
     */
27
    protected function getOptions()
28
    {
29
        return $this->removeKeys(
30
            \array_merge(
31
                $this->getAddedOptions(),
32
                parent::getOptions()
33
            ),
34
            $this->getHiddenOptions()
35
        );
36
    }
37
38
    /**
39
     * Returns the options of the parent commant that must be deactivated
40
     *
41
     * @return array
42
     */
43
    protected function getHiddenOptions(): array
44
    {
45
        return [];
46
    }
47
48
    /**
49
     * Returns the options to add to parent options
50
     *
51
     * @return array
52
     */
53
    protected function getAddedOptions(): array
54
    {
55
        return [];
56
    }
57
58
    /**
59
     * Undocumented function
60
     *
61
     * @param array $args
62
     * @param array $keys
63
     *
64
     * @return array
65
     */
66
    protected function removeKeys(array $args, array $keys): array
67
    {
68
        return collect($args)->filter(function ($item) use ($keys) {
69
            return !\in_array($item[0], $keys);
70
        })->toArray();
71
    }
72
}
73