VendorsController::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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