Passed
Pull Request — master (#7)
by Jason
01:50
created

TestAddToCartForm   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 28 7
1
<?php
2
3
namespace Dynamic\Foxy\Inventory\Test\TestOnly\Form;
4
5
use Dynamic\Foxy\Form\AddToCartForm;
6
use Dynamic\Foxy\Inventory\Extension\AddToCartFormExtension;
7
use Dynamic\Foxy\Model\FoxyHelper;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\RequiredFields;
10
11
class TestAddToCartForm extends AddToCartForm
12
{
13
    /**
14
     * @var array
15
     */
16
    private static $extensions = [
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
17
        AddToCartFormExtension::class,
18
    ];
19
20
    public function __construct(
21
        $controller,
22
        $name,
23
        FieldList $fields = null,
24
        FieldList $actions = null,
25
        $validator = null,
26
        $product = null,
27
        $helper = null
28
    ) {
29
        $this->setProduct($product);
30
        $this->setFoxyHelper($helper);
31
32
        $fields = ($fields != null && $fields->exists()) ?
33
            $this->getProductFields($fields) :
34
            $this->getProductFields(FieldList::create());
35
36
        $actions = ($actions != null && $actions->exists()) ?
37
            $this->getProductActions($actions) :
38
            $this->getProductActions(FieldList::create());
39
40
        $validator = (!empty($validator) || $validator != null) ? $validator : RequiredFields::create();
41
42
        parent::__construct($controller, $name, $fields, $actions, $validator);
43
44
        //have to call after parent::__construct()
45
        $this->setAttribute('action', FoxyHelper::FormActionURL());
46
        $this->disableSecurityToken();
47
        $this->setHTMLID($this->getTemplateHelper()->generateFormID($this) . "_{$product->ID}");
48
    }
49
}
50