Issues (12)

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/Factory.php (6 issues)

Labels

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
declare(strict_types = 1);
4
5
namespace Foo\Grid;
6
7
use Foo\Grid\Cell\Cell;
8
use Foo\Grid\Collection\Actions;
9
use Foo\Grid\Collection\Cells;
10
use Foo\Grid\Collection\Rows;
11
use Foo\Grid\Row\Row;
12
use Foo\Grid\Table\Table;
13
use Foo\Translate\ITranslator;
14
use Opulence\Orm\IEntity;
15
16
class Factory
17
{
18
    const CELL_ACTIONS_CONTENT = 'grid:actions';
19
    const CELL_ACTIONS_GROUP   = 'actions';
20
21
    /**
22
     * @param array            $entities
23
     * @param array            $getters
24
     * @param array            $headers
25
     * @param array            $headerAttributes
26
     * @param array            $bodyAttributes
27
     * @param array            $tableAttributes
28
     * @param array            $gridAttributes
29
     * @param Actions|null     $cellActions
30
     * @param Actions|null     $gridActions
31
     * @param ITranslator|null $translator
32
     *
33
     * @return Grid
34
     */
35
    public static function createGrid(
36
        array $entities,
37
        array $getters,
38
        array $headers,
39
        array $headerAttributes = [],
40
        array $bodyAttributes = [],
41
        array $tableAttributes = [],
42
        array $gridAttributes = [],
43
        Actions $cellActions = null,
44
        Actions $gridActions = null,
45
        ITranslator $translator = null
46
    ) {
47
        $tableBody   = static::createTableBody($entities, $getters, $bodyAttributes, $cellActions);
0 ignored issues
show
Since createTableBody() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of createTableBody() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
48
        $tableHeader = static::createTableHeader($headers, $headerAttributes, $cellActions);
0 ignored issues
show
Since createTableHeader() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of createTableHeader() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
49
50
        $table = new Table($tableBody, $tableHeader, $tableAttributes);
0 ignored issues
show
It seems like $tableBody defined by static::createTableBody(...tributes, $cellActions) on line 47 can also be of type array; however, Foo\Grid\Table\Table::__construct() does only seem to accept object<Foo\Grid\Collection\Rows>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $tableHeader defined by static::createTableHeade...tributes, $cellActions) on line 48 can also be of type array; however, Foo\Grid\Table\Table::__construct() does only seem to accept object<Foo\Grid\Collection\Cells>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
51
52
        $grid = new Grid($table, null, $gridActions, $gridAttributes);
53
54
        $grid->setIndentation(8);
55
56
        if ($translator) {
57
            $grid->setTranslator($translator);
58
        }
59
60
        return $grid;
61
    }
62
63
    /**
64
     * @param array        $entities
65
     * @param array        $getters
66
     * @param array        $bodyAttributes
67
     * @param Actions|null $actions
68
     *
69
     * @return array|Rows
70
     */
71
    private static function createTableBody(
72
        array $entities,
73
        array $getters,
74
        array $bodyAttributes = [],
75
        Actions $actions = null
76
    ) {
77
        $tableBody = new Rows();
78
79
        foreach ($entities as $entity) {
80
            $cells = static::createTableRowCell($getters, $bodyAttributes, $entity);
0 ignored issues
show
Since createTableRowCell() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of createTableRowCell() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
81
82
            $rowActions = $actions ? $actions->duplicate() : null;
83
84
            $row = new Row($cells, $rowActions);
0 ignored issues
show
It seems like $cells defined by static::createTableRowCe...odyAttributes, $entity) on line 80 can also be of type array; however, Foo\Grid\Row\Row::__construct() does only seem to accept object<Foo\Grid\Collection\Cells>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
85
            $row->setEntity($entity);
86
87
            $tableBody[] = $row;
88
        }
89
90
        return $tableBody;
91
    }
92
93
    /**
94
     * @param array   $getters
95
     * @param array   $bodyAttributes
96
     * @param IEntity $entity
97
     *
98
     * @return array|Cells
99
     */
100
    private static function createTableRowCell(
101
        array $getters,
102
        array $bodyAttributes,
103
        IEntity $entity
104
    ) {
105
        $cells = new Cells();
106
107
        foreach ($getters as $group => $getter) {
108
            $content = is_callable($getter) ? $getter($entity) : (string)$entity->$getter();
109
110
            $cells[] = new Cell($content, $group, $bodyAttributes, Cell::BODY);
111
        }
112
113
        return $cells;
114
    }
115
116
    /**
117
     * @param array        $headers
118
     * @param array        $headerAttributes
119
     * @param Actions|null $actions
120
     *
121
     * @return array|Cells
122
     */
123
    private static function createTableHeader(array $headers, array $headerAttributes = [], Actions $actions = null)
124
    {
125
        $cells = new Cells(Cells::HEAD);
126
        foreach ($headers as $group => $content) {
127
            $cells[] = new Cell($content, $group, $headerAttributes, Cell::HEAD);
128
        }
129
130
        if ($actions) {
131
            $cells[] = new Cell(static::CELL_ACTIONS_CONTENT, static::CELL_ACTIONS_GROUP, [], Cell::HEAD);
132
        }
133
134
        return $cells;
135
    }
136
}