CommandLineOptions   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A parseDefaults() 0 19 4
A assertValidState() 0 6 4
1
<?php
2
3
namespace SugaredRim\PHPMD\TextUI;
4
5
class CommandLineOptions extends \PHPMD\TextUI\CommandLineOptions
6
{
7
    public function __construct(array $args, array $availableRuleSets = array(), $defaults = null)
8
    {
9
        $this->parseDefaults($args, $defaults);
10
11
        try {
12
            parent::__construct($args, $availableRuleSets);
13
        } catch (\InvalidArgumentException $err) {
14
            if ($err->getCode() !== self::INPUT_ERROR) {
15
                throw $err;
16
            }
17
        }
18
19
        $this->assertValidState();
20
    }
21
22
    protected function parseDefaults(&$args, $defaults = null)
23
    {
24
        if ($defaults === null) {
25
            return;
26
        }
27
28
        foreach (get_object_vars($defaults) as $k => $v) {
29
            switch ($k) {
30
                case 'inputfile':
31
                    // prepend inputPath arg
32
                    $script = array_shift($args);
33
                    array_unshift($args, $this->inputPath = $this->readInputFile($v));
34
                    array_unshift($args, $script);
35
                    break;
36
                default:
37
                    $this->$k = $v;
38
            }
39
        }
40
    }
41
42
    protected function assertValidState()
43
    {
44
        if (empty($this->inputPath) || empty($this->reportFormat) || empty($this->ruleSets)) {
45
            throw new \InvalidArgumentException($this->usage(), self::INPUT_ERROR);
46
        }
47
    }
48
}
49