Passed
Push — master ( 54ac54...9db44e )
by Sebastian
05:57
created

AbstractConstraint::matchAny()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php /** @noinspection PhpUnused */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
2
3
/*
4
 * citeproc-php: AbstractConstraint.php
5
 * User: Sebastian Böttger <[email protected]>
6
 * created at 26.10.19, 14:12
7
 */
8
9
namespace Seboettg\CiteProc\Constraint;
10
11
use stdClass;
12
13
/**
14
 * Class AbstractConstraint
15
 * @package Seboettg\CiteProc\Constraint
2 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 6 spaces but found 1
Loading history...
16
 * @noinspection PhpUnused
17
 */
4 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
18
abstract class AbstractConstraint implements Constraint
19
{
20
21
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
     * @var string
23
     */
24
    protected $match;
25
26
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
27
     * @var array
28
     */
29
    protected $conditionVariables;
30
31
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $data should have a doc-comment as per coding-style.
Loading history...
32
     * @param string $variable
3 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
33
     * @param stdClass $data;
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Doc comment for parameter $data; does not match actual variable name $data
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
34
     * @return bool
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
35
     */
36
    protected abstract function matchForVariable($variable, $data);
37
38
    /**
39
     * Variable constructor.
40
     * @param string $value
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
41
     * @param string $match
42
     */
43
    /** @noinspection PhpUnused */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $value should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $match should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
44 45
    public function __construct($value, $match = "any")
45
    {
46 45
        $this->conditionVariables = explode(" ", $value);
47 45
        $this->match = $match;
48 45
    }
49
50
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
51
     * @param $value
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
52
     * @param int|null $citationNumber
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
53
     * @return bool
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
54
     */
55 39
    public function validate($value, $citationNumber = null)
56
    {
57 39
        switch ($this->match) {
58 39
            case Constraint::MATCH_ALL:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
59 37
                return $this->matchAll($value);
60 28
            case Constraint::MATCH_NONE:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
61 17
                return !$this->matchAny($value); //no match for any value
62 26
            case Constraint::MATCH_ANY:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
63
            default:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
64 26
                return $this->matchAny($value);
65
        }
66
    }
67
68 28
    private function matchAny($value)
1 ignored issue
show
Coding Style introduced by
Private method name "AbstractConstraint::matchAny" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function matchAny()
Loading history...
69
    {
70 28
        $conditionMatched = false;
71 28
        foreach ($this->conditionVariables as $variable) {
72 28
            $conditionMatched |= $this->matchForVariable($variable, $value);
73
        }
74 28
        return (bool)$conditionMatched;
75
    }
76
77 37
    private function matchAll($value)
1 ignored issue
show
Coding Style introduced by
Private method name "AbstractConstraint::matchAll" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function matchAll()
Loading history...
78
    {
79 37
        $conditionMatched = true;
80 37
        foreach ($this->conditionVariables as $variable) {
81 37
            $conditionMatched &= $this->matchForVariable($variable, $value);
82
        }
83 37
        return (bool)$conditionMatched;
84
    }
85
}
86