Locator::matchForVariable()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 4
nop 2
dl 0
loc 7
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\CiteProc;
14
use stdClass;
15
16
/**
17
 * Class Locator
18
 *
19
 * Tests whether the locator matches the given locator types (see Locators). Use “sub-verbo” to test for the
20
 * “sub verbo” locator type.
21
 */
22
class Locator extends AbstractConstraint
23
{
24
    /**
25
     * @inheritDoc
26
     */
27
    protected function matchForVariable(string $variable, stdClass $data): bool
28
    {
29
        if (!empty($data->id)) {
30
            $citationItem = CiteProc::getContext()->getCitationItemById($data->id);
31
            return !empty($citationItem) && !empty($citationItem->label) && $citationItem->label === $variable;
32
        }
33
        return false;
34
    }
35
}
36