Passed
Pull Request — master (#309)
by Jason
13:47
created

ProductPageController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 24 3
A PurchaseForm() 0 8 1
1
<?php
2
3
namespace Dynamic\FoxyStripe\Page;
4
5
use Dynamic\FoxyStripe\Form\FoxyStripePurchaseForm;
6
use SilverStripe\View\Requirements;
7
8
class ProductPageController extends \PageController
9
{
10
11
    private static $allowed_actions = array(
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
12
        'PurchaseForm'
13
    );
14
15
    public function init()
16
    {
17
        parent::init();
18
        Requirements::javascript("framework/thirdparty/jquery/jquery.js");
19
        if ($this->data()->Available && $this->ProductOptions()->exists()) {
0 ignored issues
show
Bug introduced by
The method ProductOptions() does not exist on Dynamic\FoxyStripe\Page\ProductPageController. 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

19
        if ($this->data()->Available && $this->/** @scrutinizer ignore-call */ ProductOptions()->exists()) {
Loading history...
20
            $formName = $this->PurchaseForm()->FormName();
21
            Requirements::javascriptTemplate(
22
                "foxystripe/javascript/out_of_stock.js",
23
                [
24
                    'FormName' => $formName,
25
                ],
26
                'foxystripe.out_of_stock'
27
            );
28
            Requirements::javascriptTemplate(
29
                'foxystripe/javascript/product_options.js',
30
                [
31
                    'FormName' => $formName,
32
                ],
33
                'foxystripe.product_options'
34
            );
35
        }
36
37
        Requirements::customScript(<<<JS
38
		var productID = {$this->data()->ID};
39
JS
40
        );
41
    }
42
43
    /**
44
     * @return FoxyStripePurchaseForm
45
     */
46
    public function PurchaseForm()
47
    {
48
49
        $form = FoxyStripePurchaseForm::create($this, __FUNCTION__, null, null, null, $this->data());
0 ignored issues
show
Bug introduced by
__FUNCTION__ of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

49
        $form = FoxyStripePurchaseForm::create($this, /** @scrutinizer ignore-type */ __FUNCTION__, null, null, null, $this->data());
Loading history...
Bug introduced by
$this->data() of type SilverStripe\CMS\Model\SiteTree is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

49
        $form = FoxyStripePurchaseForm::create($this, __FUNCTION__, null, null, null, /** @scrutinizer ignore-type */ $this->data());
Loading history...
Bug introduced by
$this of type Dynamic\FoxyStripe\Page\ProductPageController is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

49
        $form = FoxyStripePurchaseForm::create(/** @scrutinizer ignore-type */ $this, __FUNCTION__, null, null, null, $this->data());
Loading history...
50
51
        $this->extend('updateFoxyStripePurchaseForm', $form);
52
53
        return $form;
54
55
    }
56
}
57