Completed
Pull Request — development (#819)
by
unknown
05:16
created

AppExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 23.26 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 20
loc 86
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 0 10 1
A getFunctions() 0 6 1
A oc_Filter_D() 10 10 2
A oc_Filter_T() 10 10 2
A oc_Filter_rot13() 0 4 1
A oc_Filter_rot13_gc() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Oc\Twig;
4
5
use Twig\Extension\AbstractExtension;
6
use Twig\TwigFilter;
7
use Twig\TwigFunction;
8
9
/**
10
 * Class AppExtension
11
 *
12
 * @package Oc\Twig
13
 */
14
class AppExtension extends AbstractExtension
15
{
16
    /**
17
     * @return TwigFilter[]
18
     */
19
    public function getFilters()
20
    : array
21
    {
22
        return [
23
            new TwigFilter('ocFilterD', [$this, 'oc_Filter_D']),
24
            new TwigFilter('ocFilterT', [$this, 'oc_Filter_T']),
25
            new TwigFilter('rot13', [$this, 'oc_Filter_rot13']),
26
            new TwigFilter('rot13gc', [$this, 'oc_Filter_rot13_gc']),
27
        ];
28
    }
29
30
    /**
31
     * @return TwigFunction[]
32
     */
33
    public function getFunctions()
34
    : array
35
    {
36
        return [];
37
        //        return [new TwigFunction('area', [$this, 'calculateArea']),];
38
    }
39
40
    /**
41
     * calculate and format difficulty value
42
     *
43
     * @param $number
44
     *
45
     * @return string
46
     */
47 View Code Duplication
    public function oc_Filter_D($number)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
48
    : string {
49
        if ($number % 2 === 0) {
50
            $value = 'D' . number_format($number / 2, 0);
51
        } else {
52
            $value = 'D' . number_format($number / 2, 1);
53
        }
54
55
        return $value;
56
    }
57
58
    /**
59
     * calculate and format terrain value
60
     *
61
     * @param $number
62
     *
63
     * @return string
64
     */
65 View Code Duplication
    public function oc_Filter_T($number)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
66
    : string {
67
        if ($number % 2 === 0) {
68
            $value = 'T' . number_format($number / 2, 0);
69
        } else {
70
            $value = 'T' . number_format($number / 2, 1);
71
        }
72
73
        return $value;
74
    }
75
76
    /**
77
     * convert string via ROT13
78
     *
79
     * @param $string
80
     *
81
     * @return string
82
     */
83
    public function oc_Filter_rot13($string)
84
    : string {
85
        return str_rot13($string);
86
    }
87
88
    /**
89
     * convert string via ROT13, but ignore characters in [] brackets
90
     *
91
     * @param $string
92
     *
93
     * @return string
94
     */
95
    public function oc_Filter_rot13_gc($string)
96
    : string {
97
        return str_rot13_gc($string);
98
    }
99
}
100