Passed
Push — new-api ( f151f9...5a646f )
by Sebastian
04:44
created

Locator::matchForVariable()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.074

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 4
nop 2
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
crap 4.074
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/*
4
 * citeproc-php
5
 *
6
 * @link        http://github.com/seboettg/citeproc-php for the source repository
7
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
8
 * @license     https://opensource.org/licenses/MIT
9
 */
10
11
namespace Seboettg\CiteProc\Constraint;
12
13
use Seboettg\CiteProc\Rendering\Observer\RenderingObserver;
14
use Seboettg\CiteProc\Rendering\Observer\RenderingObserverTrait;
15
use stdClass;
16
use function Seboettg\CiteProc\getCurrentById;
17
18
/**
19
 * Class Locator
20
 *
21
 * Tests whether the locator matches the given locator types (see Locators). Use “sub-verbo” to test for the
22
 * “sub verbo” locator type.
23
 *
24
 * @package Seboettg\CiteProc\Constraint
25
 */
26
class Locator extends AbstractConstraint implements RenderingObserver
27
{
28
    use RenderingObserverTrait;
29
30 21
    public function __construct(string $value, string $match = "any")
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$match" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$match"; expected 0 but found 1
Loading history...
31
    {
32 21
        parent::__construct($value, $match);
33 21
        $this->initObserver();
34 21
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39 4
    protected function matchForVariable(string $variable, stdClass $data): bool
40
    {
41 4
        if (!empty($data->id)) {
42 4
            $id = $data->id;
43 4
            $citationItem = getCurrentById($this->citationItems, $id);
44 4
            return !empty($citationItem) && !empty($citationItem->label) && $citationItem->label === $variable;
45
        }
46
        return false;
47
    }
48
}
49