Passed
Push — master ( b63d68...e3d258 )
by Sebastian
06:46 queued 02:06
created

CiteProcHelper::isUsingAffixesByMarkupExtentsion()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 8.064

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 9
nc 6
nop 2
dl 0
loc 16
ccs 9
cts 10
cp 0.9
crap 8.064
rs 8.4444
c 1
b 0
f 0
1
<?php
2
/*
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\Util;
11
12
use Seboettg\CiteProc\CiteProc;
13
use stdClass;
14
15
class CiteProcHelper
16
{
17
18
    /**
19
     * Applies additional functions for markup extension
20
     *
21
     * @param stdClass $dataItem the actual item
22
     * @param string $valueToRender value the has to apply on
23
     * @param string $renderedText actual by citeproc rendered text
24
     * @return string
25
     */
26 170
    public static function applyAdditionMarkupFunction($dataItem, $valueToRender, $renderedText)
27
    {
28 170
        $markupExtension = CiteProc::getContext()->getMarkupExtension();
29 170
        if (array_key_exists($valueToRender, $markupExtension)) {
30 3
        	if (is_array($markupExtension[$valueToRender]) && array_key_exists('function', $markupExtension[$valueToRender])) {
31 1
				$function = $markupExtension[$valueToRender]['function'];
32
			} else {
33 2
				$function = $markupExtension[$valueToRender];
34
			}
35 3
            if (is_callable($function)) {
36 3
                $renderedText = $function($dataItem, $renderedText);
37
            }
38 170
        } elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) {
39 2
            if (array_key_exists($valueToRender, $markupExtension[$mode])) {
40 2
				if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('function', $markupExtension[$mode][$valueToRender])) {
41
					$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['function'];
42
				} else {
43 2
					$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender];
44
				}
45 2
                if (is_callable($function)) {
46 2
                    $renderedText = $function($dataItem, $renderedText);
47
                }
48
            }
49
        }
50 170
        return $renderedText;
51
    }
52
53
    /**
54
     * @param array $array
55
     * @return array
56
     */
57 166
    public static function cloneArray(array $array)
58
    {
59 166
        $newArray = [];
60 166
        foreach ($array as $key => $value) {
61 166
            $newArray[$key] = clone $value;
62
        }
63 166
        return $newArray;
64
    }
65
66
	/**
67
	 * @param stdClass $dataItem the actual item
68
	 * @param string $valueToRender value the has to apply on
69
	 * @return bool
70
	 */
71 103
    public static function isUsingAffixesByMarkupExtentsion($dataItem, $valueToRender)
0 ignored issues
show
Unused Code introduced by
The parameter $dataItem is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

71
    public static function isUsingAffixesByMarkupExtentsion(/** @scrutinizer ignore-unused */ $dataItem, $valueToRender)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
	{
73 103
		$markupExtension = CiteProc::getContext()->getMarkupExtension();
74 103
		if (array_key_exists($valueToRender, $markupExtension)) {
75 3
			if (is_array($markupExtension[$valueToRender]) && array_key_exists('affixes', $markupExtension[$valueToRender])) {
76 3
				return $markupExtension[$valueToRender]['affixes'];
77
			}
78 103
		} elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) {
79 2
			if (array_key_exists($valueToRender, $markupExtension[$mode])) {
80 1
				if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('affixes', $markupExtension[$mode][$valueToRender])) {
81
					return CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['affixes'];
82
				}
83
			}
84
		}
85
86 103
		return FALSE;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected false, but found FALSE.
Loading history...
87
	}
88
}
89