Completed
Push — master ( 3b1037...b7d405 )
by Matthew
05:38
created

QuantityField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 57
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Field() 0 11 1
A getProduct() 0 3 1
A newvalue() 0 19 3
1
<?php
2
3
namespace Dynamic\FoxyStripe\Form;
4
5
use Dynamic\FoxyStripe\Model\FoxyStripeSetting;
6
use Dynamic\FoxyStripe\Page\ProductPage;
7
use SilverStripe\Control\Controller;
8
use SilverStripe\Control\HTTPRequest;
9
use SilverStripe\Forms\NumericField;
10
use SilverStripe\View\Requirements;
11
12
/**
13
 * Class QuantityField
14
 * @package Dynamic\FoxyStripe\Form
15
 */
16
class QuantityField extends NumericField
17
{
18
    /**
19
     * @var array
20
     */
21
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
22
        'newvalue',
23
    ];
24
25
    /**
26
     * @param array $properties
27
     * @return string
28
     */
29
    public function Field($properties = [])
30
    {
31
        //Requirements::javascript('dynamic/foxystripe: javascript/quantity.js');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
        //Requirements::css('dynamic/foxystripe: client/dist/css/quantityfield.css');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
34
35
        $this->setAttribute('data-link', $this->Link('newvalue'));
36
        $this->setAttribute('data-code', $this->getProduct()->Code);
37
        $this->setAttribute('data-id', $this->getProduct()->ID);
38
39
        return parent::Field($properties);
40
    }
41
42
    /**
43
     * @return ProductPage
44
     */
45
    public function getProduct()
46
    {
47
        return $this->getForm()->getProduct();
48
    }
49
50
    /**
51
     * @param SS_HTTPRequest $request
0 ignored issues
show
Bug introduced by
The type Dynamic\FoxyStripe\Form\SS_HTTPRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
     * @return bool|string
53
     */
54
    public function newvalue(HTTPRequest $request)
55
    {
56
        if (!$value = $request->getVar('value')) {
57
            return '';
58
        }
59
60
        if (!$code = $request->getVar('code')) {
61
            return '';
62
        }
63
64
        $this->extend('updateQuantity', $value);
65
66
        $data = array(
67
            'quantity' => $value,
68
            'quantityGenerated' => ProductPage::getGeneratedValue($code, 'quantity', $value, 'value'),
69
        );
70
71
        $this->extend('updateData', $data);
72
        return json_encode($data);
73
    }
74
}
75