StaffFolder_Controller::StaffFolderCacheKey()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6
Metric Value
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.4285
cc 2
eloc 12
nc 2
nop 0
crap 6
1
<?php
2
/**
3
* Defines the StaffFolder page type.
4
*/
5
class StaffFolder extends Page implements RenderableAsPortlet
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...
6
    {
7
    public static $db = array(
8
        'LinkToIndividualStaffPages' => 'Boolean',
9
    );
10
    public static $has_one = array(
11
        'MainImage' => 'Image',
12
    );
13
14
    private static $icon = 'weboftalent-staff/icons/employees.png';
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
15
16
    public static $allowed_children = array('Staff');
17
18
    public function getCMSFields()
19
    {
20
        $fields = parent::getCMSFields();
21
        $fields->addFieldToTab('Root.Image', new UploadField('MainImage'));
22
        $fields->addFieldToTab('Root.Layout', new CheckboxField('LinkToIndividualStaffPages', 'If biographies are short, leave this as false to only show a single page of staff'));
23
24
        return $fields;
25
    }
26
27
    public function getPortletTitle()
28
    {
29
        return $this->Title;
30
    }
31
32
    // FIXME - make this more efficient
33
    public function getPortletImage()
34
    {
35
        return $this->MainImage();
36
    }
37
38
    public function getPortletCaption()
39
    {
40
        return '';
41
    }
42
}
43
44
class StaffFolder_Controller extends Page_Controller
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...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
45
{
46
    public function StaffFolderCacheKey()
0 ignored issues
show
Coding Style introduced by
StaffFolderCacheKey uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
Method name "StaffFolder_Controller::StaffFolderCacheKey" is not in camel caps format
Loading history...
47
    {
48
        $start = isset($_GET['start']) ? (int) (Convert::raw2sql($_GET['start'])) : 0;
49
50
        return implode('_', array(
51
            'StaffFolders',
52
            $this->Locale,
53
            $this->AllChildren()->max('LastEdited'),
54
            '_',
55
            $this->ID,
56
            '_',
57
            $this->LastEdited,
58
            '_',
59
            $start,
60
            )
61
        );
62
    }
63
}
64