Variable::matchForVariable()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 6
nop 2
dl 0
loc 10
rs 9.6111
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
class Variable extends AbstractConstraint
17
{
18
    /**
19
     * @param string $variable
20
     * @param stdClass $data
21
     * @return bool
22
     */
23
    protected function matchForVariable(string $variable, stdClass $data): bool
24
    {
25
        $variableExistsInCitationItem = false;
26
        if (CiteProc::getContext()->isModeCitation() && isset($data->id)) {
27
            $citationItem = CiteProc::getContext()->getCitationItemById($data->id);
28
            if (!empty($citationItem)) {
29
                $variableExistsInCitationItem = !empty($citationItem->{$variable});
30
            }
31
        }
32
        return !empty($data->{$variable}) || $variableExistsInCitationItem;
33
    }
34
}
35