Passed
Pull Request — master (#32)
by Jitendra
01:59
created

Factory   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isVersion() 0 3 2
A before() 0 21 4
A isHelp() 0 3 2
A isGlobalHelp() 0 8 3
1
<?php
2
3
namespace PhalconExt\Cli\Middleware;
4
5
use Ahc\Cli\Helper\OutputHelper;
0 ignored issues
show
Bug introduced by
The type Ahc\Cli\Helper\OutputHelper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Ahc\Cli\Input\Command;
0 ignored issues
show
Bug introduced by
The type Ahc\Cli\Input\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Ahc\Cli\Output\Writer;
0 ignored issues
show
Bug introduced by
The type Ahc\Cli\Output\Writer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Phalcon\Cli\Console;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cli\Console was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Phalcon\Cli\Task;
0 ignored issues
show
Bug introduced by
The type Phalcon\Cli\Task was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Phalcon\DiInterface;
0 ignored issues
show
Bug introduced by
The type Phalcon\DiInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use PhalconExt\Di\ProvidesDi;
12
13
/**
14
 * Factory middleware that injects Parser instance and responses to `--help` or `--version`.
15
 */
16
class Factory
17
{
18
    use ProvidesDi;
19
20
    public function before(Console $console)
21
    {
22
        $argv    = $console->argv();
23
        $app     = $console->app();
24
        $command = $app->commandFor($argv);
25
26
        if ($this->isVersion($argv)) {
27
            return $command->showVersion();
28
        }
29
30
        if ($this->isGlobalHelp($argv)) {
31
            return $app->showHelp();
32
        }
33
34
        if ($this->isHelp($argv)) {
35
            return $command->showHelp();
36
        }
37
38
        $this->di()->setShared('command', $app->parse($argv));
39
40
        return true;
41
    }
42
43
    protected function isGlobalHelp(array $argv): bool
44
    {
45
        // For a specific help, it would be [cmd, task, action, --help]
46
        // If it is just [cmd, --help] then we deduce it is global help!
47
48
        $isGlobal = ($argv[1][0] ?? '-') === '-' && ($argv[2][0] ?? '-') === '-';
49
50
        return $isGlobal && $this->isHelp($argv);
51
    }
52
53
    protected function isHelp(array $argv): bool
54
    {
55
        return \in_array('--help', $argv) || \in_array('-h', $argv);
56
    }
57
58
    protected function isVersion(array $argv): bool
59
    {
60
        return \in_array('--version', $argv) || \in_array('-V', $argv);
61
    }
62
}
63