Completed
Push — master ( f08276...333f55 )
by Richard
06:54 queued 34s
created

WithName   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 8.82 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 1
dl 3
loc 34
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 8 3
A regexp() 0 3 1
A variable() 0 3 1

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, 2015 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the licence along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Variables;
12
13
/**
14
 * Another variable that has a certain name.
15
 */
16
class WithName extends Variable {
17
    /**
18
     * @var string
19
     */
20
    private $regexp;
21
22
    /**
23
     * @var Variable
24
     */
25
    private $other;
26
27 48
    public function __construct($regexp, Variable $other) {
28 48
        parent::__construct($other->name());
29 48 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...
30 1
            throw new \InvalidArgumentException("Invalid regexp: '%$regexp%'");
31
        }
32 47
        $this->regexp = $regexp;
33 47
        $this->other = $other;
34 47
    }
35
36
    /**
37
     * @return  string
38
     */
39 29
    public function regexp() {
40 29
        return $this->regexp;
41
    }
42
43
    /**
44
     * @return  Variable
45
     */
46 29
    public function variable() {
47 29
        return $this->other;
48
    }
49
}
50