Command::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Solr\Console\Command\Schema;
4
5
use Symfony\Component\Console\Command\Command as BaseCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption as IOpt;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
abstract class Command extends BaseCommand
11
{
12
    /**
13
     * @var \Zookeeper
14
     */
15
    protected $client;
16
17
    public function __construct(\Zookeeper $client = null)
18
    {
19
        parent::__construct();
20
21
        $this->client = $client;
22
23
        $this->addOption('host', null, IOpt::VALUE_REQUIRED, 'Zookeeper address like csv list of host:port values (e.g. "host1:2181,host2:2181")');
24
    }
25
26
    protected function initialize(InputInterface $input, OutputInterface $output)
27
    {
28
        $host = $input->getOption('host');
29
30
        if (is_null($host) && !$this->client instanceof \Zookeeper) {
0 ignored issues
show
Bug introduced by
The class Zookeeper does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
            throw new \RuntimeException('Please define a host or Zookeeper client instance');
32
        }
33
34
        if (is_null($host)) {
35
            return $this->client;
36
        }
37
38
        $this->client = new \Zookeeper($host);
39
    }
40
}
41