BaseCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 16
c 1
b 0
f 1
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A writeErrorln() 0 16 3
A setOutput() 0 4 2
A writeln() 0 4 2
A setVerbosity() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Db3v4l\Command;
4
5
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\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...
6
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface 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 Symfony\Component\Console\Output\ConsoleOutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Consol...\ConsoleOutputInterface 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
9
abstract class BaseCommand extends Command
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class BaseCommand
Loading history...
10
{
11
    /** @var OutputInterface $output */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
12
    protected $output;
13
    /** @var OutputInterface $errorOutput */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
14
    protected $errorOutput;
15
    protected $verbosity = OutputInterface::VERBOSITY_NORMAL;
16
17
    /**
18
     * Small tricks to allow us to lower verbosity between NORMAL and QUIET and have a decent writeln API, even with old SF versions
19
     * @param $message
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
20
     * @param int $verbosity
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
21
     * @param int $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
22
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
23
    protected function writeln($message, $verbosity = OutputInterface::VERBOSITY_NORMAL, $type = OutputInterface::OUTPUT_NORMAL)
24
    {
25
        if ($this->verbosity >= $verbosity) {
26
            $this->output->writeln($message, $type);
27
        }
28
    }
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @param string|array $message The message as an array of lines or a single string
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
31
     * @param int $verbosity
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
32
     * @param int $type
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
33
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
34
    protected function writeErrorln($message, $verbosity = OutputInterface::VERBOSITY_QUIET, $type = OutputInterface::OUTPUT_NORMAL)
35
    {
36
        if ($this->verbosity >= $verbosity) {
37
38
            // When verbosity is set to quiet, SF swallows the error message in the writeln call
39
            // (unlike for other verbosity levels, which are left for us to handle...)
40
            // We resort to a hackish workaround to _always_ print errors to stderr, even in quiet mode.
41
            // If the end user does not want any error echoed, she can just 2>/dev/null
42
            if ($this->errorOutput->getVerbosity() == OutputInterface::VERBOSITY_QUIET) {
43
                $this->errorOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL);
44
                $this->errorOutput->writeln($message, $type);
45
                $this->errorOutput->setVerbosity(OutputInterface::VERBOSITY_QUIET);
46
            }
47
            else
0 ignored issues
show
Coding Style introduced by
Expected "} else \n"; found "\n else\n {\n"
Loading history...
48
            {
49
                $this->errorOutput->writeln($message, $type);
50
            }
51
        }
52
    }
53
54
    protected function setOutput(OutputInterface $output)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setOutput()
Loading history...
55
    {
56
        $this->output = $output;
57
        $this->errorOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
58
    }
59
60
    protected function setVerbosity($verbosity)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setVerbosity()
Loading history...
61
    {
62
        $this->verbosity = $verbosity;
63
    }
64
}
65