Hacks   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 41.46 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 45.45%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 1
dl 17
loc 41
ccs 5
cts 11
cp 0.4545
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addWrapperMethodToInstance() 9 9 1
A addCallbackMethodToInstance() 8 8 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 eNTiDi\Autotoc;
4
5
use SilverStripe\View\ViewableData;
6
7
class Hacks extends ViewableData
8
{
9
    /**
10
     * Add a new wrapper method.
11
     *
12
     * Similar to addWrapperMethod() but made public and working on
13
     * custom instances to allow to inject custom wrappers.
14
     *
15
     * @param ViewableData $instance
16
     * @param string $method
17
     * @param string $wrap
18
     */
19 View Code Duplication
    public static function addWrapperMethodToInstance($instance, $method, $wrap)
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...
20
    {
21
        // hasMethod() trigger the population of $extra_methods
22
        $instance->hasMethod('UnexistentMethod');
23
        self::$extra_methods[get_class($instance)][strtolower($method)] = [
24
            'wrap'   => $wrap,
25
            'method' => $method,
26
        ];
27
    }
28
29
    /**
30
     * Add callback as a method.
31
     *
32
     * Similar to addCallbackMethod() but made public and working on
33
     * custom instances to allow to inject custom callbacks.
34
     *
35
     * @param ViewableData $instance
36
     * @param string $method
37
     * @param \Closure $callback
38
     */
39 5 View Code Duplication
    public static function addCallbackMethodToInstance($instance, $method, $callback)
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...
40
    {
41
        // hasMethod() trigger the population of $extra_methods
42 5
        $instance->hasMethod('UnexistentMethod');
43 5
        self::$extra_methods[get_class($instance)][strtolower($method)] = [
44 5
            'callback' => $callback,
45
        ];
46 5
    }
47
}
48