Passed
Push — feature/locators-issue-82 ( f7cde7...464c3c )
by Sebastian
04:57
created

Locator::matchForVariable()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 4
nop 2
dl 0
loc 7
ccs 4
cts 5
cp 0.8
crap 4.128
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Constraint;
11
12
use Seboettg\CiteProc\CiteProc;
13
14
/**
15
 * Class Locator
16
 *
17
 * Tests whether the locator matches the given locator types (see Locators). Use “sub-verbo” to test for the
18
 * “sub verbo” locator type.
19
 *
20
 * @codeCoverageIgnore
21
 *
22
 * @package Seboettg\CiteProc\Constraint
23
 *
24
 * @author Sebastian Böttger <[email protected]>
25
 */
26
/** @noinspection PhpUnused */
27
class Locator extends AbstractConstraint
28
{
29
    /**
30
     * @inheritDoc
31
     */
32 3
    protected function matchForVariable($variable, $data)
33
    {
34 3
        if (!empty($data->id)) {
35 3
            $citationItem = CiteProc::getContext()->getCitationItemById($data->id);
36 3
            return !empty($citationItem) && !empty($citationItem->label) && $citationItem->label === $variable;
37
        }
38
        return false;
39
    }
40
}
41