Issues (40)

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.

src/View/View.php (3 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 Anax\View;
4
5
use Anax\View\Exception;
6
use Anax\View\ViewRenderFile;
7
use Psr\Container\ContainerInterface;
8
9
/**
10
 * A view connected to a template file, supporting Anax DI.
11
 */
12
class View
13
{
14
    /**
15
     * @var $template     Template file or array
16
     * @var $templateData Data to send to template file
17
     * @var $sortOrder    For sorting views
18
     * @var $type         Type of view
19
     */
20
    private $template;
21
    private $templateData = [];
22
    private $sortOrder;
23
    private $type;
24
25
26
27
    /**
28
     * Set values for the view.
29
     *
30
     * @param array|string|callable $template the template file, array
31
     *                                        or callable
32
     * @param array        $data     variables to make available to the
33
     *                               view, default is empty
34
     * @param integer      $sort     which order to display the views,
35
     *                               if suitable
36
     * @param string       $type     which type of view
37
     *
38
     * @return self
39
     */
40 6
    public function set($template, $data = [], $sort = 0, $type = "file")
41
    {
42 6
        if (empty($template)) {
43
            $type = "empty";
44 6
        } elseif (is_array($template)) {
45 2
            if (isset($template["callback"])) {
46 2
                $type = "callback";
47 2
                $this->template = $template["callback"];
48
            } else {
49
                $this->template = $template["template"];
50
            }
51
52 2
            $this->sortOrder = $template["sort"] ?? $sort;
53 2
            $this->type = $template["type"] ?? $type;
54
55
            // Merge data array
56 2
            $data1 = $template["data"] ?? [];
57 2
            if (empty($data)) {
58
                $this->templateData = $data1;
59 2
            } else if (empty($data1)) {
60
                $this->templateData = $data;
61
            } else {
62 2
                foreach ($data as $key => $val) {
63 2
                    if (is_array($val)) {
64 1
                        if (!array_key_exists($key, $data1)) {
65
                            $data1[$key] = [];
66
                        }
67 1
                        $data1[$key] = array_merge($data1[$key], $val);
68
                    } else {
69 2
                        $data1[$key] = $val;
70
                    }
71 2
                    $this->templateData = $data1;
72
                }
73
            }
74
75 2
            return;
76
        }
77
78 4
        $this->template     = $template;
79 4
        $this->templateData = $data;
80 4
        $this->sortOrder    = $sort;
81 4
        $this->type         = $type;
82
83 4
        return $this;
84
    }
85
86
87
88
    /**
89
     * Render the view by its type.
90
     *
91
     * @param object $di optional with access to the framework resources.
92
     *
93
     * @return void
94
     */
95 6
    public function render(ContainerInterface $di = null)
96
    {
97 6
        switch ($this->type) {
98 6
            case "file":
99
                if ($di->has("viewRenderFile")) {
100
                    $viewRender = $di->get("viewRenderFile");
0 ignored issues
show
It seems like $di 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...
101
                } else {
102
                    $viewRender = new ViewRenderFile($di);
0 ignored issues
show
The call to ViewRenderFile::__construct() has too many arguments starting with $di.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
103
                    $viewRender->setDI($di);
0 ignored issues
show
It seems like $di defined by parameter $di on line 95 can be null; however, Anax\Commons\ContainerInjectableTrait::setDI() 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...
104
                }
105
                $viewRender->render($this->template, $this->templateData);
106
                break;
107
108 6
            case "callback":
109 4
                if (!is_callable($this->template)) {
110
                    throw new Exception("View is expecting a valid callback, provided callback seems to not be a callable.");
111
                }
112 4
                echo call_user_func($this->template, $this->templateData);
113 4
                break;
114
115 2
            case "string":
116 1
                echo $this->template;
117 1
                break;
118
119 1
            case "empty":
120
                break;
121
122
            default:
123 1
                throw new Exception("Not a valid template type: '{$this->type}'.");
124
        }
125 5
    }
126
127
128
129
    /**
130
     * Give the sort order for this view.
131
     *
132
     * @return int
133
     */
134
    public function sortOrder()
135
    {
136
        return $this->sortOrder;
137
    }
138
}
139