Issues (136)

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/PageRowPageExtension.php (28 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
class PageRowPageExtension extends SiteTreeExtension
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...
4
{
5
6
7
    private static $many_many = [
0 ignored issues
show
The property $many_many 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...
8
        'PageRows' => 'PageRow'
9
    ];
10
11
    private static $many_many_extraFields = [
0 ignored issues
show
The property $many_many_extraFields 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...
12
        'PageRows' => [
13
            'SortOrder' => 'Int'
14
        ]
15
    ];
16
17
    public function PageRows()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
18
    {
19
        return $this->getPageRows();
20
    }
21
22
    public function getPageRows()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
23
    {
24
        return $this->owner->getManyManyComponents('PageRows')->sort(['SortOrder' => 'ASC']);
25
    }
26
27
    #######################
28
    ### Further DB Field Details
29
    #######################
30
31
    #######################
32
    ### Field Names and Presentation Section
33
    #######################
34
35
    private static $field_labels = [
0 ignored issues
show
The property $field_labels 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...
36
        'PageRows' => 'Content Blocks'
37
    ];
38
39
    private static $field_labels_right = [
0 ignored issues
show
The property $field_labels_right 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...
40
        'PageRows' => 'Please edit with care! You can add content blocks that are not ready for publication, but they will not be visible until they are ticked as available.',
41
    ];
42
43
44
    #######################
45
    ### Casting Section
46
    #######################
47
48
49
    #######################
50
    ### can Section
51
    #######################
52
53
54
55
    #######################
56
    ### write Section
57
    #######################
58
59
60
61
    public function onAfterWrite()
62
    {
63
        if (Security::database_is_ready()  && $this->owner->HasPageRows()) {
64
            // debug::Log('-------------------------');
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
65
            $currentPageRows = [];
66
            if ($this->owner->PageRows()->count() > 0) {
67
                $sortOrder = 1;
68
                foreach ($this->owner->PageRows() as $pageRow) {
69
                    $currentPageRows[$sortOrder] = $pageRow;
70
                    $sortOrder++;
71
                }
72
            }
73
            $rowClassNames = $this->owner->DefaultPageRows();
74
            $sortOrder = 1;
75
            foreach ($rowClassNames as $className) {
76
                $childClassName = null;
77
                if (is_array($className)) {
78
                    $childClassName = $className['Child'];
79
                    // debug::log($childClassName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
80
                    $className = $className['Parent'];
81
                }
82
                if (isset($currentPageRows[$sortOrder])) {
83
                    $row = $currentPageRows[$sortOrder];
84
                    if ($row->ClassName === $className) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
85
                        //all OK!
86
                    } else {
0 ignored issues
show
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
87
                        // $this->owner->removePageRowFromThisPage($row);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
88
                        //we do not delete the row as it may be used somewhere else ...
89
                        // $this->owner->deletePageRowFromMe($row);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
90
                    }
91
                } else {
92
                    $row = $className::create();
93
                    $row->Title = 'Title '.$row->singular_name().' #'.$className::get()->count().' for '.$this->owner->MenuTitle;
94
                    $row->write();
95
                    $this->owner->PageRows()->add($row, ['SortOrder' => $sortOrder]);
96
                    $currentPageRows[$sortOrder] = $row;
97
                }
98
                DB::query('
99
                    UPDATE "Page_PageRows"
100
                    SET "SortOrder" = '.$sortOrder.'
101
                    WHERE
102
                        "PageID" ='.$this->owner->ID.' AND
103
                        "PageRowID" = '.$row->ID.'
104
                    LIMIT 1;
105
                ');
106
                if ($childClassName) {
107
                    $childClassMethod = $row->ChildClassMethodName();
108
                    if ($childClassMethod) {
109
                        $child = $row->$childClassMethod();
110
                        if ($child && $child->exists()) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
111
                        } else {
112
                            $childClassMethodFieldName = $childClassMethod.'ID';
113
                            $child = $childClassName::create();
114
                            $child->Title = 'New '.$child->singular_name().' for '.$row->getTitle();
115
                            $child->write();
116
                            // debug::log($childClassMethodFieldName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
117
                            // debug::log($child->ID);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
118
                            // debug::log($child->Title);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
119
                            $row->$childClassMethodFieldName = $child->ID;
120
                            $row->write();
121
                        }
122
                    } else {
123
                        user_error('no childclass method set in '.$row->ClassName);
124
                    }
125
                }
126
                $sortOrder++;
127
            }
128
            $sortOrder = 1;
129
            foreach ($this->owner->PageRows() as $pageRow) {
130
                $sortOrder++;
131
                $delete = false;
132
                if (!isset($rowClassNames[$sortOrder])) {
133
                    $delete = true;
134
                } elseif ($rowClassNames[$sortOrder] !== $pageRow->ClassName) {
135
                    $delete = true;
136
                }
137
                if ($delete) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
138
                    // $this->owner->removePageRowFromThisPage($pageRow);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
139
                }
140
            }
141
        }
142
    }
143
144
    protected function removePageRowFromThisPage($rowOrRowID)
145
    {
146
        if ($rowOrRowID instanceof PageRow) {
147
            $rowOrRowID = $rowOrRowID->ID;
148
        }
149
        DB::query('
150
            DELETE
151
            FROM "Page_PageRows"
152
            WHERE
153
                "PageID" ='.$this->owner->ID.' AND
154
                "PageRowID" = '.$rowOrRowID.'
155
            LIMIT 1;
156
        ');
157
    }
158
159
160
    public function DefaultPageRows()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
161
    {
162
        if($this->owner->hasMethod('MyDefaultPageRows')) {
163
            return $this->owner->MyDefaultPageRows();
164
        }
165
        return [];
166
    }
167
168
    #######################
169
    ### Import / Export Section
170
    #######################
171
172
173
174
    #######################
175
    ### CMS Edit Section
176
    #######################
177
178
    /**
179
     * Update Fields
180
     * @return FieldList
0 ignored issues
show
Should the return type not be FieldList|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...
181
     */
182
    public function updateCMSFields(FieldList $fields)
183
    {
184
        $list = $this->owner->PageRows();
0 ignored issues
show
$list is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
185
        if($this->owner->canEdit() && $this->owner->exists() && $this->HasPageRows()) {
186
            $fields->addFieldsToTab(
187
                'Root.ContentBlocks',
188
                $this->owner->ContentBlocksFields()
189
            );
190
        }
191
    }
192
193
    public function ContentBlocksFields()
194
    {
195
        $conf = GridFieldConfig_RelationEditor::create(100);
196
        $conf->addComponent(new GridFieldSortableRows('SortOrder'));
197
        // switch ($this->owner->ClassName) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
198
        //     case 'HomePage':
199
        //         // leave as is ...
200
        //         $conf->removeComponentsByType('GridFieldAddExistingAutocompleter');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
201
        //         $conf->removeComponentsByType('GridFieldDeleteAction');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
202
        //         $conf->removeComponentsByType('GridFieldAddNewButton');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
203
        //         break;
204
        //     default:
205
        // }
206
        //
207
        $conf->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(['Code', 'Title']);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface GridFieldComponent as the method setSearchFields() does only exist in the following implementations of said interface: GridFieldAddExistingAutocompleter.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
208
209
        $pageRowField = GridField::create(
210
            'PageRows',
211
            'Content Blocks',
212
            $this->owner->PageRows(),
213
            $conf
214
        );
215
        $array = [$pageRowField];
216
        $arrayRowList = [];
217
        foreach ($this->owner->DefaultPageRows() as $count => $className) {
218
            if (is_array($className)) {
219
                $className = $className['Parent'];
220
            }
221
            $humanCount = $count + 1;
222
            $arrayRowList[$className.'_'.$count] = $humanCount . ' - '.Injector::inst()->get($className)->singular_name().' ('.$className.')';
223
        }
224
        if(count($arrayRowList)) {
225
            $array[] = LiteralField::create(
226
                'ListOfContentBlocks',
227
                '<h2>By default, this page type ('.$this->owner->singular_name().') has the following content blocks:</h2><p>'.implode('</p><p>', $arrayRowList).'</p>'
228
            );
229
        }
230
231
        return $array;
232
    }
233
234
    public function HasPageRows()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
235
    {
236
        switch($this->owner->ClassName) {
237
            case 'ErrorPage':
238
            case 'RedirectorPage':
239
            case 'VirtualPage':
240
                return false;
241
        }
242
        if($this->owner->hasMethod('MyHasPageRows')) {
243
            return $this->owner->MyHasPageRows();
244
        }
245
        return true;
246
    }
247
248
}
249