Test Failed
Push — master ( 3b4c09...efb6fb )
by Richard
02:50
created

Atom   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __toString() 0 3 1
A check() 0 5 2
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\Definition\AST;
12
13
/**
14
 * An atom is something like a keyword and not a name.
15
 *
16
 * Atoms look like ^[a-z]+(\s+[a-z]+)*$
17
 */
18
class Atom extends Definition {
19
    /**
20
     * @var string
21
     */
22
    protected $atom;
23
24
    public function __construct($atom) {
25
        assert('is_string($atom)');
26
        $this->check($atom);
27
        $this->atom = $atom;
28
    }
29
30
    /**
31
     * @return  string
32
     */
33
    public function __toString() {
34
        return $this->atom;
35
    }
36
37
    /**
38
     * @param   string
39
     * @throws  \InvalidArgumentException if string is not a valid atom.
40
     * @return  null
41
     */
42
    protected function check($atom) {
43
        if (preg_match("%^[a-z]+(\s+[a-z]+)*$%", $atom) !== 1) {
44
            throw new \InvalidArgumentException("Invalid atom '$atom'");
45
        }
46
    }
47
}
48