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

Hacks   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 54.84 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 17
loc 31
rs 10
c 0
b 0
f 0

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 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