Issues (1704)

Branch: master

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.

Resolver/WidgetMapChildrenResolver.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
namespace Victoire\Bundle\WidgetMapBundle\Resolver;
4
5
use Symfony\Bridge\Monolog\Logger;
6
use Victoire\Bundle\CoreBundle\Entity\View;
7
use Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap;
8
9
class WidgetMapChildrenResolver
0 ignored issues
show
Missing class doc comment
Loading history...
10
{
11
    private $logger;
12
13
    /**
14
     * WidgetMapChildrenResolver constructor.
15
     *
16
     * @param Logger $logger
17
     */
18
    public function __construct(Logger $logger)
19
    {
20
        $this->logger = $logger;
21
    }
22
23
    /**
0 ignored issues
show
Doc comment for parameter "$widgetMap" missing
Loading history...
Doc comment for parameter "$view" missing
Loading history...
24
     * Return "after" and "before" children,
25
     * based on contextual View and its Templates.
26
     *
27
     * @return array
28
     */
29
    public function getChildren(WidgetMap $widgetMap, View $view = null)
30
    {
31
        $positions = [WidgetMap::POSITION_BEFORE, WidgetMap::POSITION_AFTER];
32
        $children = [];
33
        foreach ($positions as $position) {
34
            $matchingChildren = [];
35
36
            //Position is null by default
37
            $children[$position] = null;
38
39
            //Pass through all current WidgetMap children for a given position
40 View Code Duplication
            foreach ($widgetMap->getContextualChildren($position) as $_child) {
0 ignored issues
show
This code seems to be duplicated across 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...
41
                //If child don't have a substitute for this View and Templates, this is the one
42
                if (null === $_child->getSubstituteForView($view)) {
0 ignored issues
show
It seems like $view defined by parameter $view on line 29 can be null; however, Victoire\Bundle\WidgetMa...:getSubstituteForView() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
43
                    $children[$position] = $_child;
44
                    $matchingChildren[] = $_child->getId();
45
                }
46
            }
47
48
            //If children has not been found for this position
49
            //and current WidgetMap is a substitute
50
            if (!$children[$position] && $widgetMap->getReplaced()) {
51
                //Pass through all replaced WidgetMap children for a given position
52 View Code Duplication
                foreach ($widgetMap->getReplaced()->getContextualChildren($position) as $_child) {
0 ignored issues
show
This code seems to be duplicated across 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...
53
                    //If child don't have a substitute for this View and Templates, this is the one
54
                    if (null === $_child->getSubstituteForView($view)) {
0 ignored issues
show
It seems like $view defined by parameter $view on line 29 can be null; however, Victoire\Bundle\WidgetMa...:getSubstituteForView() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
55
                        $children[$position] = $_child;
56
                        $matchingChildren[] = $_child->getId();
57
                    }
58
                }
59
            }
60
61
            $matchingChildren = array_unique($matchingChildren);
62
            if (count($matchingChildren) > 1) {
63
                $this->logger->critical(sprintf(
64
                    'Conflict found between WidgetMaps %s for View %s',
65
                    implode(', ', $matchingChildren),
66
                    $view->getId()
0 ignored issues
show
It seems like $view is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
67
                ));
68
            }
69
        }
70
71
        return $children;
72
    }
73
74
    /**
0 ignored issues
show
Doc comment for parameter "$widgetMap" missing
Loading history...
Doc comment for parameter "$position" missing
Loading history...
75
     * @param $position
0 ignored issues
show
Missing parameter name
Loading history...
76
     * @param View|null $view
0 ignored issues
show
Doc comment for parameter $view does not match actual variable name $position
Loading history...
77
     *
78
     * @return bool
79
     */
80
    public function hasChildren(WidgetMap $widgetMap, $position, View $view = null)
81
    {
82
        foreach ($this->getChildren($widgetMap, $view) as $child) {
83
            if ($child && $child->getPosition() === $position) {
84
                return true;
85
            }
86
        }
87
88
        return false;
89
    }
90
}
91