Issues (26)

Security Analysis    no request data  

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.

src/BulkLoader_Result.php (6 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
namespace ilateral\SilverStripe\SlightlyBetterBulkLoader;
4
5
use SilverStripe\ORM\ValidationResult;
6
use SilverStripe\Dev\BulkLoader_Result as SS_BulkLoader_Result;
7
8
/**
9
 * Custom bulk loader result that also tracks errors in submission
10
 */
11
class BulkLoader_Result extends SS_BulkLoader_Result
12
{
13
14
    /**
15
     * List of errors tracked, each error should be an error message
16
     * (as a string).
17
     *
18
     * @var array (see {@link $created})
19
     */
20
    protected $errors = [];
21
22
    /**
23
     * Return the number of errors
24
     *
25
     * @return int
26
     */
27
    public function ErrorCount()
28
    {
29
        return count($this->errors);
30
    }
31
32
    /**
33
     * Add an error message to the stack
34
     *
35
     * @param string $message The error message
36
     *
37
     * @return self
38
     */
39
    public function addError($message, $id = null)
40
    {
41
        $this->lastChange = [
42
            'Message' => $message,
43
            'ID' => $id,
44
            '_BulkLoaderMessage' => $message
45
        ];
46
        $this->errors[] = $message;
47
        $this->lastChange['ChangeType'] = 'error';
48
49
        return $this;
50
    }
51
52
    /**
53
     * Merges another BulkLoader_Result into this one.
54
     *
55
     * @param BulkLoader_Result $other
0 ignored issues
show
Should the type for parameter $other not be SS_BulkLoader_Result?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
56
     */
57
    public function merge(SS_BulkLoader_Result $other)
58
    {
59
        $this->created = array_merge($this->created, $other->getCreated());
0 ignored issues
show
The method getCreated() does not exist on SilverStripe\Dev\BulkLoader_Result. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
60
        $this->updated = array_merge($this->updated, $other->getUpdated());
0 ignored issues
show
The method getUpdated() does not exist on SilverStripe\Dev\BulkLoader_Result. Did you maybe mean Updated()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
61
        $this->deleted = array_merge($this->deleted, $other->getDeleted());
0 ignored issues
show
The method getDeleted() does not exist on SilverStripe\Dev\BulkLoader_Result. Did you maybe mean Deleted()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
62
        $this->errors = array_merge($this->errors, $other->getErrors());
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SilverStripe\Dev\BulkLoader_Result as the method getErrors() does only exist in the following sub-classes of SilverStripe\Dev\BulkLoader_Result: ilateral\SilverStripe\Sl...oader\BulkLoader_Result. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
63
    }
64
65
    /**
66
     * Get he total number of results tracked
67
     *
68
     * @return int
69
     */
70
    public function getTotal()
71
    {
72
        return $this->CreatedCount() + $this->UpdatedCount() + $this->DeletedCount() + $this->ErrorCount();
73
    }
74
75
    /**
76
     * Get created array
77
     *
78
     * @return array
79
     */
80
    public function getCreated()
81
    {
82
        return $this->created;
83
    }
84
85
    /**
86
     * Get updated array
87
     *
88
     * @return array
89
     */
90
    public function getUpdated()
91
    {
92
        return $this->updated;
93
    }
94
95
    /**
96
     * Get updated array
97
     *
98
     * @return array
99
     */
100
    public function getDeleted()
101
    {
102
        return $this->deleted;
103
    }
104
105
    /**
106
     * Get errors array
107
     *
108
     * @return array
109
     */
110
    public function getErrors()
111
    {
112
        return $this->errors;
113
    }
114
115
    /**
116
     * Get an array of all messages stored
117
     *
118
     * @return array
119
     */
120
    public function getMessagesArray()
121
    {
122
        $messages = [];
123
124
        if ($this->CreatedCount() > 0) {
125
            $messages[] = _t(
126
                'SilverStripe\\Admin\\ModelAdmin.IMPORTEDRECORDS',
127
                "Imported {count} records.",
128
                ['count' => $this->CreatedCount()]
129
            );
130
        }
131
132
        if ($this->UpdatedCount() > 0) {
133
            $messages[] = _t(
134
                'SilverStripe\\Admin\\ModelAdmin.UPDATEDRECORDS',
135
                "Updated {count} records.",
136
                ['count' => $this->UpdatedCount()]
137
            );
138
        }
139
140
        if ($this->DeletedCount() > 0) {
141
            $messages[] = _t(
142
                'SilverStripe\\Admin\\ModelAdmin.DELETEDRECORDS',
143
                "Deleted {count} records.",
144
                ['count' => $this->DeletedCount()]
145
            );
146
        }
147
        
148
        // Finally include any errors
149
        return array_merge($messages, $this->getErrors());
150
    }
151
152
    /**
153
     * Return a string of all messages (that can be rendered into a message window)
154
     *
155
     * @param bool $html Add the newline as a HTML "<br/>"
0 ignored issues
show
There is no parameter named $html. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
156
     *
157
     * @return string
158
     */
159
    public function getMessagesString($delimiter = ";")
160
    {
161
        return implode($delimiter, $this->getMessagesArray());
162
    }
163
164
    /**
165
     * Get the "type" of message (using SilverStripe's Validation result)
166
     *
167
     * @return string
168
     */
169
    public function getMessageType()
170
    {
171
        $type = ValidationResult::TYPE_GOOD;
172
173
        if (count($this->getErrors()) > 0) {
174
            $type = ValidationResult::TYPE_ERROR;
175
        }
176
177
        return $type;
178
    }
179
}
180