Issues (199)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/extensions/DMSDocumentCartExtension.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Class DMSDocumentCartExtension
5
 *
6
 * @property Boolean     AllowedInCart
7
 * @property Int         PrintRequestCount
8
 *
9
 * @property DMSDocument owner
10
 */
11
class DMSDocumentCartExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13
    /**
14
     * @var DMSDocumentCartController
15
     */
16
    private $cartController;
17
18
    private static $db = array(
0 ignored issues
show
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
        'AllowedInCart'       => 'Boolean',
20
        'MaximumCartQuantity' => 'Int',
21
        // Running total of print requests on this document
22
        'PrintRequestCount'   => 'Int',
23
    );
24
25
    private static $summary_fields = array(
0 ignored issues
show
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
        'PrintRequestCount' => 'Print Requests',
27
    );
28
29
    /**
30
     * Returns if a Document is permitted to reflect in a cart
31
     *
32
     * @return boolean
33
     */
34
    public function isAllowedInCart()
35
    {
36
        return ($this->owner->AllowedInCart && $this->owner->canView());
37
    }
38
39
    public function updateCMSFields(FieldList $fields)
40
    {
41
        Requirements::javascript(DMS_CART_DIR . '/javascript/dmscart.js');
42
43
        $newFields = array(
44
            CheckboxField::create(
45
                'AllowedInCart',
46
                _t('DMSDocumentCart.ALLOWED_IN_CART', 'Allowed in document cart')
47
            )->addExtraClass('dms-allowed-in-cart'),
48
            TextField::create(
49
                'MaximumCartQuantity',
50
                _t('DMSDocumentCart.MAXIMUM_CART_QUANTITY', 'Maximum cart quantity')
51
            )->setRightTitle(
52
                _t(
53
                    'DMSDocumentCart.MAXIMUM_CART_QUANTITY_HELP',
54
                    'If set, this will enforce a maximum number of this item that can be ordered per cart'
55
                )
56
            )->addExtraClass('dms-maximum-cart-quantity hide')
57
        );
58
59
        foreach ($newFields as $field) {
60
            $fields->insertBefore($field, 'Description');
0 ignored issues
show
$field is of type object<CheckboxField>|object<TextField>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
'Description' is of type string, but the function expects a object<FormField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
        }
62
    }
63
64
    /**
65
     * Increments the number of times a document was printed
66
     *
67
     * @return DMSDocument
68
     */
69
    public function incrementPrintRequest()
70
    {
71
        $this->owner->PrintRequestCount++;
72
        $this->owner->write();
73
74
        return $this->owner;
75
    }
76
77
    /**
78
     * Checks if a given document already exists within the Cart. True if it does, false otherwise
79
     *
80
     * @return bool
81
     */
82
    public function isInCart()
83
    {
84
        return (bool) $this->getCart()->isInCart($this->owner->ID);
85
    }
86
87
    /**
88
     * Returns whether the current document has a limit on how many items can be added to a single cart
89
     *
90
     * @return bool
91
     */
92
    public function getHasQuantityLimit()
93
    {
94
        return $this->owner->getMaximumQuantity() > 0;
95
    }
96
97
    /**
98
     * Get the maximum quantity of this document that can be ordered in a single cart
99
     *
100
     * @return int
101
     */
102
    public function getMaximumQuantity()
103
    {
104
        return (int) $this->owner->MaximumCartQuantity;
105
    }
106
107
    /**
108
     * Builds and returns a valid DMSDocumentController URL from the given $action link
109
     *
110
     * @param string $action Can be either 'add', 'remove' or 'checkout'
111
     *
112
     * @return string
0 ignored issues
show
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
113
     *
114
     * @throws DMSDocumentCartException if the provided $action is not allowed.
115
     */
116
    public function getActionLink($action = 'add')
117
    {
118
        $action = strtolower($action);
119
        $allowedActions = array_merge($this->getCartController()->allowedActions(), array('checkout'));
120
        if (!in_array($action, $allowedActions)) {
121
            throw new DMSDocumentCartException("{$action} is not accepted for this method.");
122
        }
123
124
        if ($action === 'checkout') {
125
            $result = DMSCheckoutController::singleton()->Link();
126
        } else {
127
            $result = Controller::join_links('documentcart', $action, $this->owner->ID);
128
        }
129
130
        return $result;
131
    }
132
133
    /**
134
     * Retrieves a DMSDocumentCartController handle
135
     *
136
     * @return DMSDocumentCartController
137
     */
138
    public function getCartController()
139
    {
140
        if (!$this->cartController) {
141
            $this->cartController = DMSDocumentCartController::create();
142
        }
143
144
        return $this->cartController;
145
    }
146
147
    /**
148
     * Retrieves a DMSDocumentCart handle
149
     *
150
     * @return DMSDocumentCart
151
     */
152
    public function getCart()
153
    {
154
        return $this->getCartController()->getCart();
155
    }
156
157
    /**
158
     * Returns any validation messages that may have been in the session and clears them
159
     *
160
     * @return false
0 ignored issues
show
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
161
     */
162
    public function getValidationResult()
163
    {
164
        if ($result = Session::get('dms-cart-validation-message')) {
165
            Session::clear('dms-cart-validation-message');
166
            return $result;
167
        }
168
        return false;
169
    }
170
171
    /**
172
     * Add a "print request count" field to the summary fields for editing a DMS document
173
     *
174
     * @see DMSDocument::getFieldsForFile
175
     * @param FieldGroup $fieldGroup
176
     */
177
    public function updateFieldsForFile(FieldGroup $fieldGroup)
178
    {
179
        $fields = $fieldGroup->FieldList();
180
181
        /** @var FieldList $summaryFields */
182
        $summaryFields = $fields->fieldByName('FilePreview.FilePreviewData.FilePreviewDataFields');
183
        if (!($summaryFields instanceof CompositeField)) {
184
            return;
185
        }
186
187
        $summaryFields->FieldList()->push(
188
            ReadonlyField::create(
189
                'PrintRequestCount',
190
                _t(
191
                    __CLASS__ . '.PRINT_REQUEST_COUNT',
192
                    'Print request count:'
193
                ),
194
                $this->owner->PrintRequestCount
195
            )
196
        );
197
    }
198
}
199