Completed
Pull Request — master (#2)
by Matthew
16:50 queued 01:51
created

ProductExtension::getRemoveLink()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Dynamic\Wishlist\Extensions;
4
5
6
use Dynamic\Wishlist\Model\ProductWishList;
7
use SilverStripe\Control\Controller;
8
use SilverStripe\Core\Config\Config;
9
use SilverStripe\Core\Extension;
10
use SilverStripe\Security\Security;
11
12
/**
13
 * Class ProductExtension
14
 * @package Dynamic\Wishlist\Extensions
15
 */
16
class ProductExtension extends Extension
17
{
18
19
    /**
20
     * @return bool|String
21
     */
22
    public function getRemoveLink()
23
    {
24
        $wishListPage = Config::inst()->get(ProductWishList::class, 'listing_page_class');
25
        if ($this->canRemoveFromWishList()) {
26
            /** @var \SilverStripe\CMS\Model\SiteTree $page */
27
            if ($page = $wishListPage::get()->first()) {
28
                return Controller::join_links(
29
                    $page->Link('remove'),
30
                    Controller::curr()->getRequest()->param('ID'),
31
                    $this->owner->ID
32
                );
33
            }
34
        }
35
36
        return false;
37
    }
38
39
    /**
40
     * @return bool
41
     */
42
    protected function canRemoveFromWishList()
43
    {
44
        $request = Controller::curr()->getRequest();
45
        if ($request->param('Action') == 'view') {
46
            $listID = $request->param('ID');
47
            return (ProductWishList::get()->byID($listID)->canEdit(Security::getCurrentUser()));
0 ignored issues
show
Bug introduced by
$listID 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

47
            return (ProductWishList::get()->byID(/** @scrutinizer ignore-type */ $listID)->canEdit(Security::getCurrentUser()));
Loading history...
48
        }
49
        return false;
50
    }
51
}
52