Issues (36)

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/forms/SiteTreeListboxField.php (12 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 SiteTreeListboxField extends ListboxField
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
     *
8
     * @var Int
9
     */
10
    protected $siteTreeParentID = 0;
11
12
    /**
13
     *
14
     * @var Array
15
     */
16
    protected $arrayOfAllowedIDs = array();
17
18
    /**
19
     *
20
     * @var array
21
     */
22
    protected $classNamesForItems = array("SiteTree");
23
24
    /**
25
     *
26
     * @var Array
27
     */
28
    protected $siteTreeParentAllChildren = array();
29
30
    /**
31
     * Creates a new dropdown field.
32
     *
33
     * @param string $name The field name
34
     * @param string $title The field title
35
     * @param array $source An map of the dropdown items
36
     * @param string|array $value You can pass an array of values or a single value like a drop down to be selected
37
     * @param int $size Optional size of the select element
0 ignored issues
show
Should the type for parameter $size not be integer|null?

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...
38
     * @param form The parent form
39
     */
40
    public function __construct($name, $title = '', $source = array(), $value = '', $size = null)
41
    {
42
        parent::__construct($name, $title, $source, $value, $size, true);
43
    }
44
45
    /**
46
     *
47
     * @param Int $id
48
     */
49
    public function setSiteTreeParentID($id)
50
    {
51
        $this->siteTreeParentID = $id;
52
    }
53
54
    /**
55
     *
56
     * @param Int $id
57
     * @param Int | string $array
58
     */
59
    public function setSiteTreeParentAndChildClassNames($id, $array)
60
    {
61
        $this->siteTreeParentID = $id;
62
        $this->setClassNamesForItems($array);
63
    }
64
65
    /**
66
     *
67
     * @param Array | str $array
68
     */
69
    public function setClassNamesForItems($array)
70
    {
71
        unset($this->classNamesForItems);
72
        if (is_array($array)) {
73
            $this->classNamesForItems = $array;
74
        } else {
75
            $this->classNamesForItems = array($array);
76
        }
77
    }
78
79
    /**
80
     *
81
     * @param String $str
82
     */
83
    public function addClassNameForItems($str)
84
    {
85
        $this->classNamesForItems[] = $str;
86
    }
87
88
    /**
89
     *
90
     * @param Array | SS_Map
91
     */
92
    public function setSource($source)
93
    {
94
        if ($source instanceof SS_Map) {
95
            $source = $source->toArray();
96
        }
97
        if ($source) {
98
            $hasCommas = array_filter(
99
                array_keys($source),
100
                create_function('$key', 'return strpos($key, ",") !== FALSE;')
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
101
            );
102
            if ($hasCommas) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $hasCommas of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
103
                throw new InvalidArgumentException('No commas allowed in $source keys');
104
            }
105
        }
106
        parent::setSource($source);
107
        return $this;
108
    }
109
110
    /**
111
     *
112
     * @return Array
0 ignored issues
show
Should the return type not be array|ArrayAccess?

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
    public function getSource()
115
    {
116
        $source = parent::getSource();
117
        //debug::log("original source count ".implode($this->classNamesForItems)." ".$this->siteTreeParentID.": ".count($source));
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
        if ($this->siteTreeParentID) {
119
            $arrayItems = array();
0 ignored issues
show
$arrayItems 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...
120
            $allChildrenForSiteTreeParent = $this->getAllChildrenForSiteTreeParent($this->siteTreeParentID);
121
            //debug::log("new source count: ".count($allChildrenForSiteTreeParent));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
122
            $finalSource = array();
123
            foreach ($source as $sourceKey => $sourceValue) {
124
                if (isset($allChildrenForSiteTreeParent[$sourceKey])) {
125
                    $finalSource[$sourceKey] = $sourceValue;
126
                }
127
            }
128
        } else {
129
            $finalSource = $source;
130
        }
131
        //debug::log("final source count: ".count($finalSource));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
132
        return $finalSource;
133
    }
134
135
    /**
136
     * @param Int
137
     * @return Array
138
     */
139 View Code Duplication
    private function getAllChildrenForSiteTreeParent($parentID)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141
        $children = SiteTree::get()->filter(array("ParentID" => $parentID));
142
        if ($children && $children->count()) {
143
            foreach ($children as $child) {
144
                foreach ($this->classNamesForItems as $matchingCLassName) {
145
                    //debug::log("has child");
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
146
                    if ($child instanceof $matchingCLassName) {
147
                        //debug::log("we now have ".count($this->siteTreeParentAllChildren)." children");
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...
148
                        $this->siteTreeParentAllChildren[$child->ID] = $child->ID;
149
                    }
150
                }
151
                $this->getAllChildrenForSiteTreeParent($child->ID);
152
            }
153
        }
154
        return $this->siteTreeParentAllChildren;
155
    }
156
}
157