Completed
Pull Request — master (#14)
by Matthew
13:01
created

QuantityFieldExtension::onBeforeRender()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\FoxyStripe\Extension;
4
5
6
use SilverStripe\Core\Extension;
7
8
/**
9
 * Class QuantityFieldExtension
10
 * @package Dynamic\FoxyStripe\Extension
11
 *
12
 * @property-read \Dynamic\FoxyStripe\Form\QuantityField|\Dynamic\FoxyStripe\Extension\QuantityFieldExtension $owner
13
 */
14
class QuantityFieldExtension extends Extension
15
{
16
17
    public function onBeforeRender() {
18
        if (!$this->owner->getProduct()->getHasInventory()) {
0 ignored issues
show
Bug introduced by
The method getProduct() does not exist on Dynamic\FoxyStripe\Exten...\QuantityFieldExtension. ( 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->owner->/** @scrutinizer ignore-call */ getProduct()->getHasInventory()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
            return;
20
        }
21
        $this->owner->setAttribute(
0 ignored issues
show
Bug introduced by
The method setAttribute() does not exist on Dynamic\FoxyStripe\Exten...\QuantityFieldExtension. ( Ignorable by Annotation )

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

21
        $this->owner->/** @scrutinizer ignore-call */ 
22
                      setAttribute(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
            'data-limit',
23
            $this->owner->getProduct()->getNumberAvailable()
24
        );
25
    }
26
27
    /**
28
     * @param $value
29
     */
30
    public function updateValue(&$value)
31
    {
32
        if (!$this->owner->getProduct()->getHasInventory()) {
33
            return;
34
        }
35
36
        if ($value >= $this->owner->getProduct()->getNumberAvailable()) {
37
            $value = $this->owner->getProduct()->getNumberAvailable();
38
        }
39
    }
40
}
41