Completed
Push — master ( 389cae...29b40e )
by Richard
06:27
created

WithName   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 6.82 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.32%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 3
loc 44
ccs 11
cts 15
cp 0.7332
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 8 3
A regexp() 0 3 1
A variable() 0 3 1
A explain() 0 5 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
 * Provides fluid interface to _with.
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
    /**
51
     * @inheritdoc
52
     */
53
    public function explain($text) {
54
        $v = new WithName($this->name(), $this->other);
55
        $v->setExplanation($text);
56
        return $v;
57
    }
58
59
}
60