Completed
Push — master ( cc2765...340ff8 )
by Richard
08:19
created

Symbol   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 99
Duplicated Lines 20.2 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 11
lcom 2
cbo 1
dl 20
loc 99
ccs 33
cts 33
cp 1
rs 10
c 4
b 0
f 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 10 3
A regexp() 0 3 1
A binding_power() 0 3 1
A null_denotation_is() 0 5 1
A null_denotation() 8 8 2
A left_denotation_is() 0 5 1
A left_denotation() 8 8 2

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
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 *
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 * 
7
 * This software is licensed under The MIT License. You should have received
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Definition;
12
13
/**
14
 * A symbol in known to the parser.
15
 */
16
class Symbol {
17
    /**
18
     * @var string
19
     */
20
    protected $regexp;
21
22
    /**
23
     * @var int
24
     */
25
    protected $binding_power;
26
27
    /**
28
     * This defines what a token means when appearing in the initial position
29
     * of an expression.
30
     *
31
     * @var \Closure
32
     */
33
    protected $null_denotation = null;
34
35
    /**
36
     * This defines what a token means when appearing inside an expression
37
     * to the left of the rest.
38
     *
39
     * @var \Closure
40
     */
41
    protected $left_denotation = null;
42
43 51
    public function __construct($regexp, $binding_power) {
44 51
        assert('is_string($regexp)');
45 51 View Code Duplication
        if (!is_string($regexp) || @preg_match("%$regexp%", "") === false) {
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...
46 1
            throw new \InvalidArgumentException("Invalid regexp: '%$regexp%'");
47
        }
48 50
        assert('is_int($binding_power)');
49 50
        assert('$binding_power >= 0');
50 50
        $this->regexp = $regexp;
51 50
        $this->binding_power = $binding_power;
52 50
    }
53
54
    /**
55
     * @return  string
56
     */
57 43
    public function regexp() {
58 43
        return $this->regexp;
59
    }
60
61
    /**
62
     * @return  int
63
     */
64 31
    public function binding_power() {
65 31
        return $this->binding_power;
66
    }
67
68
    /**
69
     * @param   \Closure    $led
70
     * @return  self
71
     */
72 38
    public function null_denotation_is(\Closure $led) {
73 38
        assert('$this->null_denotation === null');
74 38
        $this->null_denotation = $led;
75 38
        return $this;
76
    }
77
78
    /**
79
     * @param   array   $matches
80
     * @return  mixed
81
     */
82 33 View Code Duplication
    public function null_denotation(array &$matches) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
83 33
        if ($this->null_denotation === null) {
84 1
            $m = $matches[0];
85 1
            throw new ParserException("Syntax Error: $m");
86
        }
87 32
        $led = $this->null_denotation;
88 32
        return $led($matches);
89
    }
90
91
    /**
92
     * @param   \Closure    $led
93
     * @return  self
94
     */
95 38
    public function left_denotation_is(\Closure $led) {
96 38
        assert('$this->left_denotation === null');
97 38
        $this->left_denotation = $led;
98 38
        return $this;
99
    }
100
101
    /**
102
     * @param   mixed   $left
103
     * @param   array   $matches
104
     * @return  mixed
105
     */
106 22 View Code Duplication
    public function left_denotation($left, array &$matches) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
107 22
        if ($this->left_denotation === null) {
108 1
            $m = $matches[0];
109 1
            throw new ParserException("Syntax Error: $m");
110
        }
111 21
        $led = $this->left_denotation;
112 21
        return $led($left, $matches);
113
    }
114
}
115