ProductWishListControllerExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 22
c 2
b 0
f 0
dl 0
loc 62
ccs 9
cts 21
cp 0.4286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCollectionItems() 0 7 2
A view() 0 25 4
A getController() 0 3 1
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;
29
    }
30
31
    /**
32
     * @param HTTPRequest|null $request
33
     *
34
     * @return \SilverStripe\View\ViewableData_Customised|\SilverStripe\Control\HTTPResponse
35
     * @throws \SilverStripe\Control\HTTPResponse_Exception
36
     */
37 1
    public function view(HTTPRequest $request = null)
38
    {
39 1
        if ($request === null) {
40
            $request = $this->getController()->getRequest();
41
        }
42 1
        $id = $request->param('ID');
43
44
        /** @var ProductWishList $record */
45 1
        $record = ProductWishList::get()->filter([
46 1
            'URLSegment' => $id,
47 1
        ])->first();
48
        
49 1
        if ($record) {
0 ignored issues
show
introduced by
$record is of type Dynamic\Wishlist\Model\ProductWishList, thus it always evaluated to true.
Loading history...
50 1
            if ($record->canView(Security::getCurrentUser())) {
51
                return $this->getController()->customise([
52
                    'WishList' => $record,
53
                    'Breadcrumbs' => $record->Breadcrumbs(),
0 ignored issues
show
Bug introduced by
The method Breadcrumbs() does not exist on Dynamic\Wishlist\Model\ProductWishList. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

53
                    'Breadcrumbs' => $record->/** @scrutinizer ignore-call */ Breadcrumbs(),
Loading history...
54
                    'ProductWishListForm' => false,
55
                ]);
56
            }
57
58 1
            return Security::permissionFailure($this->owner, "You don't have permission to view this record.");
59
        }
60
61
        return $this->getController()->httpError(404);
62
    }
63
64
    /**
65
     * @param \SilverStripe\ORM\ArrayList $collection
66
     * @param $searchCriteria
67
     */
68
    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

68
    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...
69
    {
70
        $memberID = 0;
71
        if ($member = Security::getCurrentUser()) {
72
            $memberID = $member->ID;
73
        }
74
        $collection = $collection->filter(['MemberID' => $memberID]);
75
    }
76
}
77