Completed
Push — master ( 888d29...e13826 )
by Sebastian
06:20
created

Text   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 69
rs 10
c 1
b 0
f 0
wmc 15
lcom 1
cbo 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 4
C render() 0 31 11
1
<?php
2
3
namespace Seboettg\CiteProc\Rendering;
4
use Seboettg\CiteProc\CiteProc;
5
use Seboettg\CiteProc\Styles\AffixesTrait;
6
use Seboettg\CiteProc\Styles\DisplayTrait;
7
use Seboettg\CiteProc\Styles\FormattingTrait;
8
use Seboettg\CiteProc\Styles\QuotesTrait;
9
use Seboettg\CiteProc\Styles\TextCaseTrait;
10
11
12
/**
13
 * Class Term
14
 * @package Seboettg\CiteProc\Node\Style
15
 *
16
 * @author Sebastian Böttger <[email protected]>
17
 */
18
class Text implements RenderingInterface
19
{
20
    use FormattingTrait,
21
        AffixesTrait,
22
        TextCaseTrait,
23
        DisplayTrait;
24
25
    /**
26
     * @var string
27
     */
28
    private $toRenderType;
29
30
    /**
31
     * @var string
32
     */
33
    private $toRenderTypeValue;
34
35
    private $form = "long";
36
37
    public function __construct(\SimpleXMLElement $node)
38
    {
39
        foreach ($node->attributes() as $attribute) {
40
            $name = $attribute->getName();
41
            if (in_array($name, ['value', 'variable', 'macro', 'term'])) {
42
                $this->toRenderType = $name;
43
                $this->toRenderTypeValue = (string) $attribute;
44
            }
45
            if ($name === "form") {
46
                $this->form = (string) $attribute;
47
            }
48
        }
49
        $this->initFormattingAttributes($node);
50
        $this->initDisplayAttributes($node);
51
        $this->initTextCaseAttributes($node);
52
        $this->initAffixesAttributes($node);
53
    }
54
55
    public function render($data)
56
    {
57
        $lang = (isset($data->language) && $data->language != 'en') ? $data->language : 'en';
58
59
        $renderedText = "";
60
        switch ($this->toRenderType) {
61
            case 'value':
62
                $renderedText = $this->applyTextCase($this->toRenderTypeValue, $lang);
63
                break;
64
            case 'variable':
65
                // check if there is an attribute with prefix short or long e.g. shortTitle or longAbstract
66
                // test case group_ShortOutputOnly.json
67
                if (in_array($this->form, ["short", "long"])) {
68
                    $attrWithPrefix = $this->form . ucfirst($this->toRenderTypeValue);
69
                    if (isset($data->{$attrWithPrefix}) && !empty($data->{$attrWithPrefix})) {
70
                        $renderedText = $this->applyTextCase($data->{$attrWithPrefix}, $lang);
71
                    }
72
                }
73
                if (isset($data->{$this->toRenderTypeValue})) {
74
                    $renderedText = $this->applyTextCase($data->{$this->toRenderTypeValue}, $lang);
75
                }
76
                break;
77
            case 'macro':
78
                $renderedText = CiteProc::getContext()->getMacro($this->toRenderTypeValue)->render($data);
79
                break;
80
            case 'term':
81
                $renderedText = $this->applyTextCase(CiteProc::getContext()->getLocale()->filter("terms", $this->toRenderTypeValue, $this->form)->single, $lang);
82
        }
83
        $text = $this->format($renderedText);
84
        return $this->addAffixes($text, $this->quotes);
0 ignored issues
show
Unused Code introduced by
The call to Text::addAffixes() has too many arguments starting with $this->quotes.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
85
    }
86
}