Test Failed
Pull Request — master (#110)
by Sebastian
05:14
created

CiteProcHelper::applyAdditionMarkupFunction()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 17
nc 10
nop 3
dl 0
loc 25
ccs 13
cts 13
cp 1
crap 10
rs 7.6666
c 1
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 169
    public static function applyAdditionMarkupFunction($dataItem, $valueToRender, $renderedText)
27
    {
28 169
        $markupExtension = CiteProc::getContext()->getMarkupExtension();
29 169
        if (array_key_exists($valueToRender, $markupExtension)) {
30 2
        	if (is_array($markupExtension[$valueToRender]) && array_key_exists('function', $markupExtension[$valueToRender])) {
31 2
				$function = $markupExtension[$valueToRender]['function'];
32 2
			} else {
33
				$function = $markupExtension[$valueToRender];
34 169
			}
35 2
            if (is_callable($function)) {
36 2
                $renderedText = $function($dataItem, $renderedText);
37 2
            }
38 2
        } elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) {
39
            if (array_key_exists($valueToRender, $markupExtension[$mode])) {
40
				if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('function', $markupExtension[$mode][$valueToRender])) {
41
					$function = $function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['function'];
0 ignored issues
show
Unused Code introduced by
The assignment to $function is dead and can be removed.
Loading history...
42 169
				} else {
43
					$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender];
44
				}
45
                if (is_callable($function)) {
46
                    $renderedText = $function($dataItem, $renderedText);
47
                }
48
            }
49 165
        }
50
        return $renderedText;
51 165
    }
52 165
53 165
    /**
54
     * @param array $array
55 165
     * @return array
56
     */
57
    public static function cloneArray(array $array)
58
    {
59
        $newArray = [];
60
        foreach ($array as $key => $value) {
61
            $newArray[$key] = clone $value;
62
        }
63
        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
    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
		$markupExtension = CiteProc::getContext()->getMarkupExtension();
74
		if (array_key_exists($valueToRender, $markupExtension)) {
75
			if (is_array($markupExtension[$valueToRender]) && array_key_exists('affixes', $markupExtension[$valueToRender])) {
76
				return $markupExtension[$valueToRender]['affixes'];
77
			}
78
		} elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) {
79
			if (array_key_exists($valueToRender, $markupExtension[$mode])) {
80
				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
		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