Completed
Pull Request — master (#2)
by Matthew
07:05 queued 04:26
created

updateCollectionItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Dynamic\Wishlist\Extensions;
4
5
use Dynamic\Wishlist\Model\ProductWishList;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Core\Extension;
8
use SilverStripe\Security\Security;
9
10
/**
11
 * Class ProductWishListControllerExtension
12
 */
13
class ProductWishListControllerExtension extends Extension
14
{
15
16
    /**
17
     * @var array
18
     */
19
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
20
        'view',
21
    ];
22
23
    /**
24
     * @return \SilverStripe\CMS\Controllers\ContentController|Object
25
     */
26
    protected function getController()
27
    {
28
        return ($this->owner->hasMethod('getCurrentPage'))
29
            ? $this->owner->getCurrentPage()
30
            : $this->owner;
31
    }
32
33
    /**
34
     * @param HTTPRequest|null $request
35
     *
36
     * @return \SilverStripe\View\ViewableData_Customised|\SilverStripe\Control\HTTPResponse
37
     * @throws \SilverStripe\Control\HTTPResponse_Exception
38
     */
39 1
    public function view(HTTPRequest $request = null)
40
    {
41 1
        if ($request === null) {
42
            $request = $this->getController()->getRequest();
43
        }
44 1
        $id = $request->param('ID');
45
46 1
        if ($record = ProductWishList::get()->byID($id)) {
0 ignored issues
show
Bug introduced by
$id of type string is incompatible with the type integer expected by parameter $id of SilverStripe\ORM\DataList::byID(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        if ($record = ProductWishList::get()->byID(/** @scrutinizer ignore-type */ $id)) {
Loading history...
47 1
            if ($record->canView(Security::getCurrentUser())) {
48
                return $this->getController()->customise([
49
                    'WishList' => $record,
50
                    'Breadcrumbs' => $record->Breadcrumbs(),
51
                    'ProductWishListForm' => false,
52
                ]);
53
            }
54
55 1
            return Security::permissionFailure($this->owner, "You don't have permission to view this record.");
56
        }
57
58
        return $this->getController()->httpError(404);
59
    }
60
61
    /**
62
     * @param \SilverStripe\ORM\ArrayList $collection
63
     * @param $searchCriteria
64
     */
65
    public function updateCollectionItems(&$collection, $searchCriteria)
0 ignored issues
show
Unused Code introduced by
The parameter $searchCriteria is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
    public function updateCollectionItems(&$collection, /** @scrutinizer ignore-unused */ $searchCriteria)

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

Loading history...
66
    {
67
        $collection = $collection->filter(['MemberID' => Security::getCurrentUser()->ID]);
68
    }
69
70
}
71