LastPagedResults()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class ChildPaginatorControllerExtension extends Extension
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...
4
{
5
    /*
6
    Call this from a template to iterate through a number of items (default 10) for the
7
    currently selected page.  The result is saved as a variable called $this->lastPagedResults for
8
    caching purposes when it comes to rendering the pagination
9
10
    <code>
11
    <% control PagedChildren(NewsItem,8) %>
12
    <li>
13
    <a href="$Link">$Title</a>
14
    <br/>
15
    <a href="$Link">$NewsItemImage.SetWidth(200)</a>
16
    <br/>
17
    <a href="$Link">$NewsItemDate.Nice</a>
18
19
    </li>
20
    <% end_control %>
21
    </code>
22
    */
23 View Code Duplication
    public function PagedChildren($klazz, $pageLength = 10, $prime = false, $relationship_key = 'ParentID')
0 ignored issues
show
Unused Code introduced by
The parameter $relationship_key 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...
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::PagedChildren" is not in camel caps format
Loading history...
24
    {
25
        $parentID = $this->owner->ID;
26
        $req = Controller::curr()->getRequest();
27
        $list = DataList::create($klazz)->where('"ParentID" = '.$parentID);
28
        $this->lastPagedResults = new PaginatedList($list, $req);
0 ignored issues
show
Bug introduced by
The property lastPagedResults does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
        $this->lastPagedResults->setPageLength($pageLength);
30
        $this->lastPagedResults->setLimitItems($pageLength);
0 ignored issues
show
Documentation introduced by
$pageLength is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
        $result = $this->lastPagedResults;
32
        if ($prime == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
33
        $result = ''; // render nothing to the template, we are only updating variables
0 ignored issues
show
Coding Style introduced by
It seems like the identation of this line is off (expected at least 12 spaces, but found 8).
Loading history...
34
        }
35
36
        return $result;
37
    }
38
39 View Code Duplication
    public function AllPagedChildren($pageLength = 10, $sort = 'Sort', $prime = false, $relationship_key = 'ParentID')
0 ignored issues
show
Unused Code introduced by
The parameter $sort 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...
Unused Code introduced by
The parameter $relationship_key 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...
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::AllPagedChildren" is not in camel caps format
Loading history...
40
    {
41
        $parentID = $this->owner->ID;
42
        $req = Controller::curr()->getRequest();
43
        $list = SiteTree::get()->where('"ParentID" = '.$parentID);
44
        $this->lastPagedResults = new PaginatedList($list, $req);
45
        $this->lastPagedResults->setPageLength($pageLength);
46
        $this->lastPagedResults->setLimitItems($pageLength);
0 ignored issues
show
Documentation introduced by
$pageLength is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        $result = $this->lastPagedResults;
48
        if ($prime == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
49
            $result = ''; // render nothing to the template, we are only updating variables
50
        }
51
52
        return $result;
53
    }
54
55
    public function PagedDataObjectsByClassName($klazz, $pageLength = 10, $sort = 'ASC')
0 ignored issues
show
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::PagedDataObjectsByClassName" is not in camel caps format
Loading history...
56
    {
57
        $req = Controller::curr()->getRequest();
58
        $this->lastPagedResults = new PaginatedList(DataList::create($klazz)->sort('LastEdited '.$sort), $req);
59
        $this->lastPagedResults->setPageLength($pageLength);
60
        $this->lastPagedResults->setLimitItems($pageLength);
0 ignored issues
show
Documentation introduced by
$pageLength is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
62
        return $this->lastPagedResults;
63
    }
64
65
    public function SetPagedOffset($newoffset)
0 ignored issues
show
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::SetPagedOffset" is not in camel caps format
Loading history...
66
    {
67
        $this->PagedOffset = $newoffset;
0 ignored issues
show
Bug introduced by
The property PagedOffset does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
68
    }
69
70
    public function PagedChildrenAllButFirst()
0 ignored issues
show
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::PagedChildrenAllButFirst" is not in camel caps format
Loading history...
71
    {
72
    }
73
74
    /*
75
    The current page number.  This is only populated after the call to PagedChildren
76
    */
77
    public function PageNumber()
0 ignored issues
show
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::PageNumber" is not in camel caps format
Loading history...
78
    {
79
        return $this->PageNumber; // variable, not the method, populated when loading the pages items
0 ignored issues
show
Bug introduced by
The property PageNumber does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
80
    }
81
82
    /*
83
    A cached copy of the pagination results
84
    */
85
    public function LastPagedResults()
0 ignored issues
show
Coding Style introduced by
Method name "ChildPaginatorControllerExtension::LastPagedResults" is not in camel caps format
Loading history...
86
    {
87
        return $this->lastPagedResults;
88
    }
89
}
90