Passed
Pull Request — master (#2)
by Matthew
14:00
created

ProductControllerExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addToWishList() 0 9 1
A WishListForm() 0 3 1
1
<?php
2
3
namespace Dynamic\Wishlist\Extensions;
4
5
use Dynamic\Wishlist\Form\AddToWishListForm;
6
use Dynamic\Wishlist\Model\ProductWishList;
7
use SilverStripe\Core\Extension;
8
use SilverStripe\Forms\Form;
9
10
/**
11
 * Class ProductExtension
12
 * @package Dynamic\Wishlist\Extensions
13
 *
14
 * @property-read \SilverStripe\Control\Controller $owner
15
 */
16
class ProductControllerExtension extends Extension
17
{
18
    /**
19
     * @var array
20
     */
21
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
22
        'AddToWishListForm',
23
    ];
24
25
    /**
26
     * @return \Dynamic\Wishlist\Form\AddToWishListForm
27
     */
28
    public function WishListForm()
29
    {
30
        return AddToWishListForm::create($this->owner, 'WishListForm');
31
    }
32
33
    /**
34
     * @param $data
35
     * @param \SilverStripe\Forms\Form $form
36
     * @return \SilverStripe\Control\HTTPResponse
37
     * @throws \Exception
38
     */
39
    public function addToWishList($data, Form $form)
0 ignored issues
show
Unused Code introduced by
The parameter $form 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

39
    public function addToWishList($data, /** @scrutinizer ignore-unused */ Form $form)

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...
40
    {
41
        /** @var ProductWishList|\Dynamic\Nucu\Extension\WishListExtension $list */
42
        $list = ProductWishList::get()->filter([
43
            'ID' => $data['List'],
44
        ])->first();
45
        $list->Products()->add($data['ProductID']);
0 ignored issues
show
Bug introduced by
The method Products() 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

45
        $list->/** @scrutinizer ignore-call */ 
46
               Products()->add($data['ProductID']);
Loading history...
46
47
        return $this->owner->redirectBack();
48
    }
49
}
50