Completed
Branch master (2ac5a6)
by Nicola
01:38
created

Hacks::addCallbackMethodToInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
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 string $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');
0 ignored issues
show
Bug introduced by
The method hasMethod cannot be called on $instance (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
23
        self::$extra_methods[get_class($instance)][strtolower($method)] = [
24
            'wrap'   => $wrap,
25
            'method' => $method,
26
        ];
27
    }
28
29 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...
30
    {
31
        // hasMethod() trigger the population of $extra_methods
32
        $instance->hasMethod('UnexistentMethod');
33
        self::$extra_methods[get_class($instance)][strtolower($method)] = [
34
            'callback' => $callback,
35
        ];
36
    }
37
}
38