Completed
Push — master ( 39d73f...2e8f8e )
by Matthew
03:26
created

FoxyStripeInventoryManagerExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 41.18%

Importance

Changes 0
Metric Value
wmc 6
eloc 17
dl 0
loc 28
rs 10
c 0
b 0
f 0
ccs 7
cts 17
cp 0.4118

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateFoxyStripePurchaseForm() 0 23 6
1
<?php
2
3
namespace Dynamic\FoxyStripe\ORM;
4
5
use Dynamic\FoxyStripe\Page\ProductPage;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\Forms\DropdownField;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\HeaderField;
10
11
/**
12
 * Class FoxyStripeInventoryManagerExtension
13
 * @package Dynamic\FoxyStripe\ORM
14
 *
15
 * @property ProductPage|\Dynamic\FoxyStripe\ORM\FoxyStripeInventoryManager $owner
16
 */
17
class FoxyStripeInventoryManagerExtension extends Extension
18
{
19
    /**
20
     * @param \SilverStripe\Forms\Form $form
21
     */
22 1
    public function updateFoxyStripePurchaseForm(&$form)
23
    {
24 1
        if ($this->owner->Available && !$this->owner->getIsProductAvailable()) {
0 ignored issues
show
Bug introduced by
The property Available does not seem to exist on Dynamic\FoxyStripe\ORM\FoxyStripeInventoryManager.
Loading history...
25 1
            $form->setFields(FieldList::create([
26 1
                HeaderField::create('OutOfStock', 'Currently Out of Stock', 4),
27
            ]));
28 1
            if ($submit = $form->Actions()->fieldByName('')) {
29 1
                $submit->setAttribute('Disabled', true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $value of SilverStripe\Forms\FormField::setAttribute(). ( Ignorable by Annotation )

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

29
                $submit->setAttribute('Disabled', /** @scrutinizer ignore-type */ true);
Loading history...
30
            }
31 1
            return;
32
        }
33
34
        if ($this->owner->getHasInventory()) {
35
            $quantityMax = $this->owner->getNumberAvailable();
36
            $count = 1;
37
            $quantity = array();
38
            while ($count <= $quantityMax) {
39
                $countVal = ProductPage::getGeneratedValue($this->owner->Code, 'quantity', $count, 'value');
0 ignored issues
show
Bug introduced by
The property Code does not seem to exist on Dynamic\FoxyStripe\ORM\FoxyStripeInventoryManager.
Loading history...
40
                $quantity[$countVal] = $count;
41
                $count++;
42
            }
43
            $fields = $form->Fields();
44
            $fields->replaceField('quantity', DropdownField::create('quantity', 'Quantity', $quantity));
45
        }
46
    }
47
}
48