Hacks::addCallbackMethodToInstance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
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