Completed
Push — master ( fb1da0...84ba9e )
by Nic
10s
created

getController()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * Class ProductWishListControllerExtension
5
 */
6
class ProductWishListControllerExtension extends Extension
7
{
8
9
    /**
10
     * @var array
11
     */
12
    private static $allowed_actions = [
13
        'view',
14
    ];
15
16
    /**
17
     * @return ContentController|Object
18
     */
19
    protected function getController()
20
    {
21
        return ($this->owner->hasMethod('getCurrentPage'))
22
            ? $this->owner->getCurrentPage()
23
            : $this->owner;
24
    }
25
26
    /**
27
     * @param SS_HTTPRequest|null $request
28
     *
29
     * @return ViewableData_Customised|SS_HTTPResponse
30
     */
31 1
    public function view(SS_HTTPRequest $request = null)
32
    {
33 1
        if ($request === null) {
34
            $request = $this->getController()->getRequest();
35
        }
36 1
        $id = $request->param('ID');
37
38 1
        if ($record = ProductWishList::get()->byID($id)) {
39 1
            if ($record->canView(Member::currentUser())) {
0 ignored issues
show
Bug introduced by
It seems like \Member::currentUser() targeting Member::currentUser() can also be of type object<DataObject>; however, DataObject::canView() does only seem to accept object<Member>|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
40
                return $this->getController()->customise([
41
                    'WishList' => $record,
42
                    'Breadcrumbs' => $record->Breadcrumbs(),
43
                    'ProductWishListForm' => false,
44
                ]);
45
            }
46
47 1
            return Security::permissionFailure($this->owner, "You don't have permission to view this record.");
48
        }
49
50
        return $this->getController()->httpError(404);
51
    }
52
53
    /**
54
     * @param $collection
55
     * @param $searchCriteria
56
     */
57
    public function updateCollectionItems(&$collection, $searchCriteria)
0 ignored issues
show
Unused Code introduced by
The parameter $searchCriteria 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...
58
    {
59
        $collection = $collection->filter(['MemberID' => Member::currentUserID()]);
60
    }
61
62
}