Passed
Push — master ( 661b73...ccb1dd )
by Sebastian
08:54 queued 05:17
created

QuotesTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 45
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceOuterQuotes() 0 9 1
A initQuotesAttributes() 0 4 3
A addSurroundingQuotes() 0 9 2
1
<?php
2
/*
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2017 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Styles;
11
use Seboettg\CiteProc\CiteProc;
12
use Seboettg\CiteProc\Util\StringHelper;
13
use SimpleXMLElement;
14
15
/**
16
 * Trait QuotesTrait
17
 *
18
 * The quotes attribute may set on cs:text. When set to “true” (“false” is default), the rendered text is wrapped in
19
 * quotes (the quotation marks used are terms). The localized punctuation-in-quote option controls whether an adjoining
20
 * comma or period appears outside (default) or inside the closing quotation mark.
21
 *
22
 * @package Seboettg\CiteProc\Styles
23
 * @author Sebastian Böttger <[email protected]>
1 ignored issue
show
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 1
Loading history...
24
 */
3 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
25
trait QuotesTrait
26
{
27
28
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var bool
30
     */
31
    private $quotes = false;
0 ignored issues
show
Coding Style introduced by
Private member variable "quotes" must be prefixed with an underscore
Loading history...
32
33 85
    public function initQuotesAttributes(SimpleXMLElement $node)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function initQuotesAttributes()
Loading history...
34
    {
35 85
        if (isset($node['quotes']) && "true" === (string) $node['quotes']) {
36 24
            $this->quotes = true;
37
        }
38 85
    }
39
40
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @param string $text
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
42
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
43
     */
44 69
    public function addSurroundingQuotes($text)
45
    {
46 69
        if ($this->quotes) {
47 4
            $openQuote = CiteProc::getContext()->getLocale()->filter("terms", "open-quote")->single;
48 4
            $closeQuote = CiteProc::getContext()->getLocale()->filter("terms", "close-quote")->single;
49 4
            $text = $this->replaceOuterQuotes($text, $openQuote, $closeQuote);
50 4
            return $openQuote . $text . $closeQuote;
51
        }
52 69
        return $text;
53
    }
54
55
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $text should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $outerOpenQuote should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $outerCloseQuote should have a doc-comment as per coding-style.
Loading history...
56
     * @param $text
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
57
     * @param $outerOpenQuote
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
58
     * @param $outerCloseQuote
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
59
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
60
     */
61 4
    private function replaceOuterQuotes($text, $outerOpenQuote, $outerCloseQuote)
1 ignored issue
show
Coding Style introduced by
Private method name "QuotesTrait::replaceOuterQuotes" must be prefixed with an underscore
Loading history...
62
    {
63
64 4
        $innerOpenQuote = CiteProc::getContext()->getLocale()->filter("terms", "open-inner-quote")->single;
65 4
        $innerCloseQuote = CiteProc::getContext()->getLocale()->filter("terms", "close-inner-quote")->single;
66
67 4
        $text = StringHelper::replaceOuterQuotes($text, "\"", "\"", $innerOpenQuote, $innerCloseQuote);
68 4
        $text = StringHelper::replaceOuterQuotes($text, $outerOpenQuote, $outerCloseQuote, $innerOpenQuote, $innerCloseQuote);
69 4
        return $text;
70
    }
71
}
72