Completed
Push — master ( f8f77e...d2a4ab )
by Jason
05:01
created

ProductPageController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
dl 0
loc 44
ccs 0
cts 19
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 24 3
A PurchaseForm() 0 7 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
    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...
11
        'PurchaseForm',
12
    );
13
14
    public function init()
15
    {
16
        parent::init();
17
        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
18
        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

18
        if ($this->data()->Available && $this->/** @scrutinizer ignore-call */ ProductOptions()->exists()) {
Loading history...
19
            $formName = $this->PurchaseForm()->FormName();
20
            Requirements::javascriptTemplate(
21
                'foxystripe/javascript/out_of_stock.js',
22
                [
23
                    'FormName' => $formName,
24
                ],
25
                'foxystripe.out_of_stock'
26
            );
27
            Requirements::javascriptTemplate(
28
                'foxystripe/javascript/product_options.js',
29
                [
30
                    'FormName' => $formName,
31
                ],
32
                'foxystripe.product_options'
33
            );
34
        }
35
36
        Requirements::customScript(<<<JS
37
		var productID = {$this->data()->ID};
38
JS
39
        );
40
    }
41
42
    /**
43
     * @return FoxyStripePurchaseForm
44
     */
45
    public function PurchaseForm()
46
    {
47
        $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

47
        $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

47
        $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

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