Completed
Push — master ( 14784f...87aa66 )
by Richard
05:56
created

With::name()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 4
Bugs 1 Features 1
Metric Value
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 4
b 1
f 1
nc 2
cc 2
eloc 7
nop 1
crap 2.0116
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\Fluid;
12
use Lechimp\Dicto\Definition\Variables as Vars;
13
14
/**
15
 * Provides fluid interface for with().
16
 */
17
class With extends Base {
18
    /**
19
     * Say to mean only artifacts whose name matches the provided regexp.
20
     *
21
     * @param   string  $regexp
22
     * @return  ExistingVar
23
     */
24 9
    public function name($regexp) {
25 9
        $subject = $this->rt->get_current_var();
26 9
        if (!($subject instanceof Vars\Variable)) {
27
            throw new \RuntimeException("Could not get current var from runtime.");
28
        }
29 9
        $this->rt->current_var_is(
30 9
            new Vars\WithName($regexp, $subject));
31
32 8
        return new ExistingVar($this->rt);
33
    }
34
}
35