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

Locator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 12
ccs 4
cts 5
cp 0.8
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A matchForVariable() 0 7 4
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