Completed
Pull Request — master (#185)
by Janne
03:01
created

CommentsGridFieldBulkAction_Handlers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 64.15 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
c 4
b 0
f 0
lcom 0
cbo 3
dl 34
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A spam() 17 18 2
A approve() 17 18 2

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
/**
4
 * @package comments
5
 */
6
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
}
9
10
/**
11
 * A {@link GridFieldBulkActionHandler} for bulk marking comments as spam
12
 *
13
 * @package comments
14
 */
15
class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
16
{
17
18
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'spam',
20
        'approve',
21
    );
22
23
    private static $url_handlers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_handlers is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
        'spam' => 'spam',
25
        'approve' => 'approve',
26
    );
27
28
29 View Code Duplication
    public function spam(SS_HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
        $ids = array();
32
33
        foreach ($this->getRecords() as $record) {
34
            array_push($ids, $record->ID);
35
            $record->markSpam();
36
        }
37
38
        $response = new SS_HTTPResponse(Convert::raw2json(array(
39
            'done' => true,
40
            'records' => $ids
41
        )));
42
43
        $response->addHeader('Content-Type', 'text/json');
44
45
        return $response;
46
    }
47
48
49 View Code Duplication
    public function approve(SS_HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
50
    {
51
        $ids = array();
52
53
        foreach ($this->getRecords() as $record) {
54
            array_push($ids, $record->ID);
55
            $record->markApproved();
56
        }
57
58
        $response = new SS_HTTPResponse(Convert::raw2json(array(
59
            'done' => true,
60
            'records' => $ids
61
        )));
62
63
        $response->addHeader('Content-Type', 'text/json');
64
65
        return $response;
66
    }
67
}
68