Completed
Push — master ( bf66ca...210cc2 )
by Sebastian
05:53
created

CiteProcHelper::applyAdditionMarkupFunction()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 8
Ratio 44.44 %

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 6
nop 3
dl 8
loc 18
rs 8.8571
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
}