Completed
Push — master ( d9583a...7cefe7 )
by Sebastian
05:03 queued 22s
created

CiteProcHelper::cloneArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 6
rs 10
c 0
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
14
class CiteProcHelper
15
{
16
17
    /**
18
     * Applies additional functions for markup extension
19
     *
20
     * @param \stdClass $dataItem the actual item
21
     * @param string $valueToRender value the has to apply on
22
     * @param string $renderedText actual by citeproc rendered text
23
     * @return string
24
     */
25
    public static function applyAdditionMarkupFunction($dataItem, $valueToRender, $renderedText)
26
    {
27
        $markupExtension = CiteProc::getContext()->getMarkupExtension();
28
        if (array_key_exists($valueToRender, $markupExtension)) {
29
            $function = $markupExtension[$valueToRender];
30
            if (is_callable($function)) {
31
                $renderedText = $function($dataItem, $renderedText);
32
            }
33 View Code Duplication
        } else if (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
            if (array_key_exists($valueToRender, $markupExtension[$mode])) {
35
                $function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender];
36
                if (is_callable($function)) {
37
                    $renderedText = $function($dataItem, $renderedText);
38
                }
39
            }
40
        }
41
        return $renderedText;
42
    }
43
44
    /**
45
     * @param array $array
46
     * @return array
47
     */
48
    public static function cloneArray(array $array)
49
    {
50
        $newArray = [];
51
        foreach ($array as $key => $value) {
52
            $newArray[$key] = clone $value;
53
        }
54
        return $newArray;
55
    }
56
}
57