Completed
Pull Request — master (#309)
by Jason
05:20
created

DonationProductController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 71
ccs 0
cts 30
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A updatevalue() 0 14 3
B PurchaseForm() 0 26 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
     * @var array
12
     */
13
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
14
        'PurchaseForm',
15
        'updatevalue',
16
    ];
17
18
    /**
19
     *
20
     */
21
    public function init()
22
    {
23
        parent::init();
24
        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
25
    }
26
27
    /**
28
     * @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...
29
     */
30
    public function PurchaseForm()
31
    {
32
        $form = parent::PurchaseForm();
33
34
        $fields = $form->Fields();
35
36
        $fields->replaceField(ProductPage::getGeneratedValue(
37
            $this->Code,
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
            'price',
39
            $this->Price
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...
40
        ), $currencyField = CurrencyField::create('price', 'Amount'));
0 ignored issues
show
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...
41
42
        $fields->removeByName(array(
43
            'quantity',
44
            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...
45
        ));
46
47
        if (SiteConfig::current_site_config()->CartValidation) {
48
            Requirements::javascript('framework/thirdparty/jquery-validate/jquery.validate.js');
49
            Requirements::javascriptTemplate('foxystripe/javascript/donationProduct.js', [
50
                'Trigger' => (string) $currencyField->getAttribute('id'),
51
                'UpdateURL' => Director::absoluteURL($this->Link('updatevalue')),
52
            ]);
53
        }
54
55
        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...
56
    }
57
58
    /**
59
     * create new encrypted price value based on user input.
60
     *
61
     * @param $request
62
     *
63
     * @return string|\SilverStripe\Control\HTTPResponse
64
     */
65
    public function updatevalue(\SilverStripe\Control\HTTPRequest $request)
66
    {
67
        if ($request->getVar('Price') && SiteConfig::current_site_config()->CartValidation) {
68
            $vars = $request->getVars();
69
            $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...
70
            $json = json_encode(['Price' => $signedPrice]);
71
            $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

71
            $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...
72
            $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

72
            $response->/** @scrutinizer ignore-call */ 
73
                       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...
73
            $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

73
            $response->/** @scrutinizer ignore-call */ 
74
                       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...
74
75
            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...
76
        }
77
78
        return 'false';
79
    }
80
}
81