Completed
Push — master ( 7bef7a...470c23 )
by Richard
07:03
created

Name   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 34
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A fetch_arguments() 0 4 1
A arguments_are_valid() 0 6 3
A compile() 0 4 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 license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Variables;
12
13
use Lechimp\Dicto\Regexp;
14
use Lechimp\Dicto\Graph\PredicateFactory;
15
use Lechimp\Dicto\Definition\ArgumentParser;
16
17
/**
18
 * Name is a property, right?
19
 */
20
class Name extends Property {
21
    /**
22
     * @inheritdocs
23
     */
24 52
    public function name() {
1 ignored issue
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
25 52
        return "name";
26
    }
27
28
    /**
29
     * @inheritdocs
30
     */
31 6
    public function fetch_arguments(ArgumentParser $parser) {
32 6
        $regexp = new Regexp($parser->fetch_string());
33 6
        return array($regexp);
34
    }
35
36
    /**
37
     * @inheritdocs
38
     */
39 32
    public function arguments_are_valid(array &$arguments) {
40 32
        if (count($arguments) != 1 || !($arguments[0] instanceof Regexp)) {
41
            return false;
42
        }
43 32
        return true;
44
    }
45
46
    /**
47
     * @inheritdocs
48
     */
49 26
    public function compile(PredicateFactory $f, array &$arguments) {
50 26
        assert('$this->arguments_are_valid($arguments)');
51 26
        return $f->_property("name")->_matches($arguments[0]);
52
    }
53
}
54