MonitorApplicationConfig::configure()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 41
rs 8.8571
cc 1
eloc 27
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the hogosha-monitor package
5
 *
6
 * Copyright (c) 2016 Guillaume Cavana
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Feel free to edit as you please, and have fun.
12
 *
13
 * @author Guillaume Cavana <[email protected]>
14
 */
15
16
namespace Hogosha\Monitor\Console;
17
18
use Hogosha\Monitor\Configuration\ConfigurationDumper;
19
use Hogosha\Monitor\Configuration\ConfigurationLoader;
20
use Hogosha\Monitor\Console\Handler\InitHandler;
21
use Hogosha\Monitor\Console\Handler\RunHandler;
22
use Hogosha\Monitor\Monitor;
23
use Symfony\Component\Filesystem\Filesystem;
24
use Webmozart\Console\Api\Args\Format\Option;
25
use Webmozart\Console\Config\DefaultApplicationConfig;
26
27
/**
28
 * @author Guillaume Cavana <[email protected]>
29
 */
30
class MonitorApplicationConfig extends DefaultApplicationConfig
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35
    protected function configure()
36
    {
37
        parent::configure();
38
39
        $configurationLoader = new ConfigurationLoader();
40
        $configurationDumper = new ConfigurationDumper();
41
42
        $filesystem = new Filesystem();
43
44
        $signature = <<<SIGNATURE
45
  _   _   ___    ____   ___   ____   _   _     _
46
 | | | | / _ \  / ___| / _ \ / ___| | | | |   / \
47
 | |_| || | | || |  _ | | | |\___ \ | |_| |  / _ \
48
 |  _  || |_| || |_| || |_| | ___) ||  _  | / ___ \
49
 |_| |_| \___/  \____| \___/ |____/ |_| |_|/_/   \_\
50
51
SIGNATURE;
52
53
        $this
0 ignored issues
show
Bug introduced by
The method beginCommand does only exist in Webmozart\Console\Api\Config\ApplicationConfig, but not in Webmozart\Console\Api\Config\CommandConfig.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
54
            ->setDisplayName($signature."\n".'Hogosha Monitoring Tool')
55
            ->setName('monitor')
56
            ->setVersion(Monitor::VERSION)
57
                ->addOption('config', 'c', Option::OPTIONAL_VALUE, 'Config file path', rtrim(getcwd(), DIRECTORY_SEPARATOR))
58
                ->beginCommand('init')
59
                    ->setDescription('Create a default configuration file if you do not have one')
60
                    ->setHandler(function () use ($configurationLoader, $configurationDumper, $filesystem) {
61
                        return new InitHandler($configurationLoader, $configurationDumper, $filesystem);
62
                    })
63
                    ->setHelp('php <info>bin/monitor</info> init')
64
                    ->addOption('force', 'f', Option::OPTIONAL_VALUE, 'Overwrite the config file')
65
                ->end()
66
                ->beginCommand('run')
67
                    ->setDescription('Launch the monitor process')
68
                    ->setHandler(function () use ($configurationLoader) {
69
                        return new RunHandler($configurationLoader);
70
                    })
71
                    ->setHelp('php <info>bin/monitor</info> run')
72
                    ->addOption('format', 'f', Option::OPTIONAL_VALUE, 'The formatter', 'list')
73
                ->end()
74
        ;
75
    }
76
}
77