Passed
Pull Request — master (#309)
by Jason
13:47
created

DonationProductController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 69
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A updatevalue() 0 14 3
A PurchaseForm() 0 23 2
1
<?php
2
3
use Dynamic\FoxyStripe\Page\ProductPage;
4
use Dynamic\FoxyStripe\Page\ProductPageController;
5
use SilverStripe\SiteConfig\SiteConfig;
6
use SilverStripe\View\Requirements;
7
8
class DonationProductController extends ProductPageController
9
{
10
11
    /**
12
     * @var array
13
     */
14
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
15
        'PurchaseForm',
16
        'updatevalue',
17
    ];
18
19
    /**
20
     *
21
     */
22
    public function init()
23
    {
24
        parent::init();
25
        Requirements::javascript("framework/thirdparty/jquery/jquery.js");
26
    }
27
28
    /**
29
     * @return FoxyStripePurchaseForm
0 ignored issues
show
Bug introduced by
The type FoxyStripePurchaseForm 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...
30
     */
31
    public function PurchaseForm()
32
    {
33
        $form = parent::PurchaseForm();
34
35
        $fields = $form->Fields();
36
37
        $fields->replaceField(ProductPage::getGeneratedValue($this->Code, 'price',
0 ignored issues
show
Bug Best Practice introduced by
The property Code does not exist on DonationProductController. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
            $this->Price), $currencyField = CurrencyField::create('price', 'Amount'));
0 ignored issues
show
Bug Best Practice introduced by
The property Price does not exist on DonationProductController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The type CurrencyField 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...
39
40
        $fields->removeByName(array(
41
            'quantity',
42
            ProductPage::getGeneratedValue($this->Code, 'weight', $this->Weight),
0 ignored issues
show
Bug Best Practice introduced by
The property Weight does not exist on DonationProductController. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
        ));
44
45
        if (SiteConfig::current_site_config()->CartValidation) {
46
            Requirements::javascript("framework/thirdparty/jquery-validate/jquery.validate.js");
47
            Requirements::javascriptTemplate("foxystripe/javascript/donationProduct.js", [
48
                'Trigger'   => (string)$currencyField->getAttribute('id'),
49
                'UpdateURL' => Director::absoluteURL($this->Link('updatevalue')),
50
            ]);
51
        }
52
53
        return $form;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $form returns the type Dynamic\FoxyStripe\Form\FoxyStripePurchaseForm which is incompatible with the documented return type FoxyStripePurchaseForm.
Loading history...
54
    }
55
56
    /**
57
     * create new encrypted price value based on user input
58
     *
59
     * @param $request
60
     *
61
     * @return string|\SilverStripe\Control\HTTPResponse
62
     */
63
    public function updatevalue(\SilverStripe\Control\HTTPRequest $request)
64
    {
65
        if ($request->getVar('Price') && SiteConfig::current_site_config()->CartValidation) {
66
            $vars        = $request->getVars();
67
            $signedPrice = FoxyCart_Helper::fc_hash_value($this->Code, 'price', $vars['Price'], 'name', false);
0 ignored issues
show
Bug Best Practice introduced by
The property Code does not exist on DonationProductController. Since you implemented __get, consider adding a @property annotation.
Loading history...
68
            $json        = json_encode(['Price' => $signedPrice]);
69
            $response    = new HTTPResponse($json);
0 ignored issues
show
Unused Code introduced by
The call to HTTPResponse::__construct() has too many arguments starting with $json. ( Ignorable by Annotation )

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

69
            $response    = /** @scrutinizer ignore-call */ new HTTPResponse($json);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
            $response->removeHeader('Content-Type');
0 ignored issues
show
Bug introduced by
The method removeHeader() does not exist on HttpResponse. ( Ignorable by Annotation )

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

70
            $response->/** @scrutinizer ignore-call */ 
71
                       removeHeader('Content-Type');

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...
71
            $response->addHeader('Content-Type', 'application/json');
0 ignored issues
show
Bug introduced by
The method addHeader() does not exist on HttpResponse. ( Ignorable by Annotation )

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

71
            $response->/** @scrutinizer ignore-call */ 
72
                       addHeader('Content-Type', 'application/json');

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...
72
73
            return $response;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response returns the type HTTPResponse which is incompatible with the documented return type SilverStripe\Control\HTTPResponse|string.
Loading history...
74
        }
75
76
        return 'false';
77
    }
78
}