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.

  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/Config.php (2 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
declare(strict_types=1);
4
5
namespace Nymfonya\Component;
6
7
use Nymfonya\Component\Interfaces\IConfig;
8
9
/**
10
 * Nymfonya\Component\Config
11
 *
12
 * is a config manager
13
 *
14
 * @author pierrefromager
15
 */
16
17
class Config implements IConfig
18
{
19
20
    protected $path;
21
    protected $env;
22
    protected $settings;
23
24
    /**
25
     * instanciate
26
     *
27
     * @param string $env
28
     */
29 10
    public function __construct(string $env, string $path)
30
    {
31 10
        $this->path = $path;
32 10
        $this->setEnv($env);
33 10
        $this->load();
34 10
        return $this;
0 ignored issues
show
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
35
    }
36
37
    /**
38
     * set config environment
39
     *
40
     * @param string $env
41
     * @return Config
42
     */
43 10
    public function setEnv(string $env = self::ENV_DEV): Config
44
    {
45 10
        $this->env = $env;
46 10
        return $this;
47
    }
48
49
    /**
50
     * returns env
51
     *
52
     * @return string
53
     */
54 1
    public function getEnv(): string
55
    {
56 1
        return $this->env;
57
    }
58
59
    /**
60
     * set config path
61
     *
62
     * @param string $path
63
     * @return Config
64
     */
65 2
    public function setPath(string $path): Config
66
    {
67 2
        $this->path = $path;
68 2
        return $this;
69
    }
70
71
    /**
72
     * returns config path
73
     *
74
     * @return string
75
     */
76 1
    public function getPath(): string
77
    {
78 1
        return $this->path;
79
    }
80
81
    /**
82
     * return config array for a main entry key
83
     *
84
     * @param string $key
85
     * @return array
86
     */
87 1
    public function getSettings(string $key = ''): array
88
    {
89 1
        return ($key) ? $this->settings[$key] : $this->settings;
90
    }
91
92
    /**
93
     * return true if config main entry for a key exists
94
     *
95
     * @param string $key
96
     * @return boolean
97
     */
98 1
    public function hasEntry(string $key): bool
99
    {
100 1
        return isset($this->settings[$key]);
101
    }
102
103
    /**
104
     * load config for a given env
105
     *
106
     * @return Config
107
     */
108 10
    public function load(): Config
109
    {
110 10
        $filename = realpath($this->getFilename());
111 10
        if (false === $this->check($filename)) {
112
            throw new \Exception(
113
                sprintf(
114
                    self::CONFIG_ERROR_MISSING . '%s on %s',
115
                    $this->env,
116
                    $this->path
117
                )
118
            );
119
        }
120 10
        $this->settings = require $this->getFilename();
121 10
        return $this;
122
    }
123
124
    /**
125
     * getFilename
126
     *
127
     * @return string
128
     */
129 1
    protected function getFilename(): string
130
    {
131 1
        return $this->path . $this->env . '.php';
132
    }
133
134
    /**
135
     * check
136
     *
137
     * @param string $filename
138
     * @return boolean
139
     */
140 1
    protected function check($filename): bool
0 ignored issues
show
function check() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
141
    {
142 1
        return (in_array($this->env, $this->getAllowedEnv())
143 1
            && file_exists($filename));
144
    }
145
146
    /**
147
     * getAllowedEnv
148
     *
149
     * @return array
150
     */
151 1
    protected function getAllowedEnv(): array
152
    {
153
        return [
154 1
            self::ENV_DEV, self::ENV_INT, self::ENV_PROD,
155 1
            self::ENV_TEST, self::ENV_CLI
156
        ];
157
    }
158
}
159