Issues (3)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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/Callables.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EngineWorks\Templates;
6
7
use Countable;
8
9
class Callables implements Countable
10
{
11
    /**
12
     * @var array<string, callable>
13
     */
14
    private $map = [];
15
16
    /**
17
     * Add a function callable to the collection
18
     */
19 12
    public function add(string $name, callable $callable): void
20
    {
21 12
        $this->map[$name] = $callable;
22
    }
23
24
    /**
25
     * Return a callable based on the string name
26
     * If the name is not registered then return NULL
27
     */
28 3
    public function get(string $name): ?callable
29
    {
30 3
        return $this->map[$name] ?? null;
31
    }
32
33
    /**
34
     * Return TRUE if the name is registered
35
     */
36 4
    public function exists(string $name): bool
37
    {
38 4
        return isset($this->map[$name]);
39
    }
40
41
    /**
42
     * Remove a registered name from the collection
43
     */
44 2
    public function remove(string $name): void
45
    {
46 2
        unset($this->map[$name]);
47
    }
48
49
    /**
50
     * Call a function by name
51
     *
52
     * @param array<mixed> $arguments
53
     */
54 2
    public function call(string $name, array $arguments): string
55
    {
56
        /** @var callable():string|null $callable */
57 2
        $callable = $this->get($name);
58 2
        if (null === $callable) {
0 ignored issues
show
The condition null === $callable is always false.
Loading history...
59
            return '';
60
        }
61
62 2
        $return = call_user_func_array($callable, $arguments);
63
64 2
        if (is_object($return) && is_callable([$return, '__toString'])) {
65
            $return = (string) $return;
66 2
        } elseif (is_scalar($return)) {
67 2
            $return = (string) $return;
68
        }
69
70 2
        return is_string($return) ? $return : '';
71
    }
72
73
    /**
74
     * Return the names of the registered functions
75
     *
76
     * @return string[]
77
     */
78 4
    public function names(): array
79
    {
80 4
        return array_keys($this->map);
81
    }
82
83
    /**
84
     * Attach an array of plugins. Is a shortcut to call several times to attatch method
85
     * If an element of the array is not a plugin then the element is discarded without notice
86
     *
87
     * @param Plugin[] $plugins
88
     */
89 1
    public function attachAll(array $plugins): void
90
    {
91 1
        $this->attach(...$plugins);
92
    }
93
94
    /**
95
     * Attach all the functions offered by the plugin
96
     *
97
     * @param Plugin ...$plugins
98
     */
99 2
    public function attach(Plugin ...$plugins): void
100
    {
101 2
        foreach ($plugins as $plugin) {
102 2
            $this->attachPlugin($plugin);
103
        }
104
    }
105
106
    /**
107
     * Attach all the functions offered by the plugin
108
     *
109
     * @param Plugin $plugin
110
     */
111 2
    public function attachPlugin(Plugin $plugin): void
112
    {
113 2
        foreach ($plugin->getCallablesTable() as $name => $methodName) {
114
            /** @var callable():string $callable */
115 2
            $callable = [$plugin, $methodName];
116 2
            $this->add($name, $callable);
117
        }
118
    }
119
120
    /**
121
     * Detatch all the functions offered by the plugins
122
     */
123 1
    public function detach(Plugin ...$plugins): void
124
    {
125 1
        foreach ($plugins as $plugin) {
126 1
            $this->detachPlugin($plugin);
127
        }
128
    }
129
130
    /**
131
     * Detatch all the functions offered by the plugin
132
     *
133
     * @param Plugin $plugin
134
     */
135 1
    public function detachPlugin(Plugin $plugin): void
136
    {
137 1
        foreach ($plugin->getCallablesTable() as $name => $_) {
138 1
            $this->remove($name);
139
        }
140
    }
141
142 3
    public function count(): int
143
    {
144 3
        return count($this->map);
145
    }
146
}
147