Completed
Push — master ( bdaaad...4f4372 )
by personal
04:35 queued 45s
created

Parser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 42
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 14 38 11

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Hal\Application\Config;
3
4
class Parser
5
{
6
7
    public function parse($argv)
8
    {
9
        $config = new Config;
10
11
        if (sizeof($argv) === 0) {
12
            return $config;
13
        }
14
15
        if (preg_match('!\.php$!', $argv[0]) || preg_match('!phpmetrics$!', $argv[0]) || preg_match('!phpmetrics.phar$!', $argv[0])) {
16
            array_shift($argv);
17
        }
18
19
        // arguments with options
20 View Code Duplication
        foreach ($argv as $k => $arg) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
            if (preg_match('!\-\-([\w\-]+)=(.*)!', $arg, $matches)) {
22
                list(, $parameter, $value) = $matches;
23
                $config->set($parameter, trim($value, ' "\''));
24
                unset($argv[$k]);
25
            }
26
        }
27
28
        // arguments without options
29 View Code Duplication
        foreach ($argv as $k => $arg) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
            if (preg_match('!\-\-([\w\-]+)$!', $arg, $matches)) {
31
                list(, $parameter) = $matches;
32
                $config->set($parameter, true);
33
                unset($argv[$k]);
34
            }
35
        }
36
37
        // last argument
38
        $files = array_pop($argv);
39
        if ($files && !preg_match('!^\-\-!', $files)) {
40
            $config->set('files', explode(',', $files));
41
        }
42
43
        return $config;
44
    }
45
}