Completed
Push — master ( e2dc10...6f7e0c )
by Richard
06:21
created

ContainText   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 7.32 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 62.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 1
dl 3
loc 41
ccs 10
cts 16
cp 0.625
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A invoke() 0 3 1
A regexp() 0 3 1
A explain() 0 5 1
A __construct() 3 7 3
A variables() 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 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\Definition\Rules;
12
use Lechimp\Dicto\Definition\Variables as Vars;
13
14
class ContainText extends Rule {
15
    /**
16
     * @var string
17
     */
18
    private $regexp;
19
20 49
    public function __construct($mode, Vars\Variable $var, $regexp) {
21 49
        parent::__construct($mode, $var);
22 49 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...
23 1
            throw new \InvalidArgumentException("Invalid regexp: '%regexp'");
24
        }
25 48
        $this->regexp = $regexp;
26 48
    }
27
28
    public function invoke(Functions $fun) {
29
        return InvokeRule($this, $fun);
30
    }
31
32
    /**
33
     * @return  string
34
     */
35 11
    public function regexp() {
36 11
        return $this->regexp;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function explain($text) {
43
        $r = new ContainTextRule($this->mode(), $this->subject(), $this->regexp);
44
        $r->setExplanation($text);
45
        return $r;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51 1
    public function variables() {
52 1
        return array($this->subject());
53
    }
54
}
55