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

WithName::variable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
nc 1
cc 1
eloc 2
nop 0
crap 1
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