VendorsController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 87.5 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 42
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 4 4 1
A Title() 4 4 1
A Link() 4 4 1
A Vendors() 20 25 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
 * Handles listing package vendors.
4
 */
5 View Code Duplication
class VendorsController extends SiteController
0 ignored issues
show
Duplication introduced by
This class 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...
6
{
7
8
    public static $allowed_actions = array(
9
        'index'
10
    );
11
12
    public function index()
13
    {
14
        return $this->renderWith(array('Vendors', 'Page'));
15
    }
16
17
    public function Title()
18
    {
19
        return 'Vendors';
20
    }
21
22
    public function Link()
23
    {
24
        return Controller::join_links(Director::baseURL(), 'vendors');
25
    }
26
27
    public function Vendors()
28
    {
29
        $query = new SQLQuery();
0 ignored issues
show
Deprecated Code introduced by
The class SQLQuery has been deprecated with message: since version 4.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
30
        $result = new ArrayList();
31
32
        $query
33
            ->setSelect('"AddonVendor"."Name"')
34
            ->selectField('COUNT("Addon"."ID")'. 'Count')
35
            ->setFrom('"AddonVendor"')
36
            ->addLeftJoin('Addon', '"Addon"."VendorID" = "AddonVendor"."ID"')
37
            ->setGroupBy('"AddonVendor"."ID"')
38
            ->setOrderBy(array('"Count"' => 'DESC', '"Name"' => 'ASC'));
39
40
        foreach ($query->execute() as $row) {
41
            $link = Controller::join_links(
42
                Director::baseURL(),
43
                'add-ons',
44
                $row['Name']
45
            );
46
47
            $result->push(new ArrayData($row + array('Link' => $link)));
48
        }
49
50
        return $result;
51
    }
52
}
53