Issues (18)

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/Charcoal/View/ViewableTrait.php (1 issue)

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 Charcoal\View;
6
7
use InvalidArgumentException;
8
9
// From 'charcoal-view'
10
use Charcoal\View\ViewInterface;
11
12
/**
13
 * Implementation, as trait, of the {@see \Charcoal\View\ViewableInterface}.
14
 */
15
trait ViewableTrait
16
{
17
    /**
18
     * The object's template identifier.
19
     *
20
     * @var string
21
     */
22
    private $templateIdent = '';
23
24
    /**
25
     * The context for the {@see self::$view} to render templates.
26
     *
27
     * @var ViewableInterface
28
     */
29
    private $viewController;
30
31
    /**
32
     * The renderable view.
33
     *
34
     * @var ViewInterface
35
     */
36
    private $view;
37
38
    /**
39
     * Render the viewable object.
40
     *
41
     * @return string
42
     */
43
    public function __toString()
44
    {
45
        return $this->render();
46
    }
47
48
    /**
49
     * Set the template identifier for this viewable object.
50
     *
51
     * Usually, a path to a file containing the template to be rendered at runtime.
52
     *
53
     * @param string $templateIdent The template ID.
54
     * @return self
55
     */
56
    public function setTemplateIdent(string $templateIdent)
57
    {
58
        $this->templateIdent = $templateIdent;
59
        return $this;
60
    }
61
62
    /**
63
     * Retrieve the template identifier for this viewable object.
64
     *
65
     * @return string
66
     */
67
    public function templateIdent(): string
68
    {
69
        return $this->templateIdent;
70
    }
71
72
    /**
73
     * Set the renderable view.
74
     *
75
     * @param ViewInterface|array $view The view instance to use to render.
76
     * @throws InvalidArgumentException If the view parameter is not an array or a View object.
77
     * @return self
78
     */
79
    public function setView(ViewInterface $view)
80
    {
81
        $this->view = $view;
82
        return $this;
83
    }
84
85
    /**
86
     * Retrieve the renderable view.
87
     *
88
     * @return ViewInterface The object's View instance.
89
     */
90
    public function view()
91
    {
92
        return $this->view;
93
    }
94
95
    /**
96
     * Render the template by the given identifier.
97
     *
98
     * Usually, a path to a file containing the template to be rendered at runtime.
99
     *
100
     * @param string $templateIdent The template to load, parse, and render.
101
     *     If NULL, will use the object's previously set template identifier.
102
     * @return string The rendered template.
103
     */
104
    public function render(?string $templateIdent = null): string
105
    {
106
        if ($templateIdent === null) {
107
            $templateIdent = $this->templateIdent();
108
        }
109
110
        return $this->view()->render($templateIdent, $this->viewController());
111
    }
112
113
    /**
114
     * Render the given template from string.
115
     *
116
     * @param string $templateString The template  to render from string.
117
     * @return string The rendered template.
118
     */
119
    public function renderTemplate(string $templateString): string
120
    {
121
        return $this->view()->renderTemplate($templateString, $this->viewController());
122
    }
123
124
    /**
125
     * Set a view controller for the template's context.
126
     *
127
     * @param ViewableInterface|object|array|null $controller A view controller to use when rendering.
128
     * @throws InvalidArgumentException If the controller is invalid.
129
     * @return self
130
     */
131
    public function setViewController($controller)
132
    {
133
        if (is_scalar($controller) || is_resource($controller)) {
134
            throw new InvalidArgumentException(
135
                'View controller must be an object, null or an array'
136
            );
137
        }
138
139
        $this->viewController = $controller;
0 ignored issues
show
Documentation Bug introduced by
It seems like $controller can also be of type array. However, the property $viewController is declared as type object<Charcoal\View\ViewableInterface>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
140
141
        return $this;
142
    }
143
144
    /**
145
     * Retrieve a view controller for the template's context.
146
     *
147
     * If no controller has been defined, it will return itself.
148
     *
149
     * @return mixed
150
     */
151
    public function viewController()
152
    {
153
        if ($this->viewController === null) {
154
            return $this;
155
        }
156
157
        return $this->viewController;
158
    }
159
160
    /**
161
     * @param string      $varName       The name of the variable to set this template unto.
162
     * @param string|null $templateIdent The "dynamic template" to set. null to clear.
163
     * @return void
164
     */
165
    public function setDynamicTemplate(string $varName, ?string $templateIdent): void
166
    {
167
        $this->view()->setDynamicTemplate($varName, $templateIdent);
168
    }
169
}
170