Issues (2)

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/iMega/Formatter/Formatter.php (2 issues)

Severity

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 iMega\Formatter;
4
5
class Formatter
6
{
7
    protected $fields = [];
8
9 34
    public function __construct(array $meta)
10
    {
11 34
        foreach ($meta as $item) {
12 34
            if (empty($item) || !is_array($item)) {
13 4
                throw new FormatterException('Wrong type');
14
            }
15 30
            list($name, $default, $type, $error) = $item;
16 30
            if (0 !== $error) {
17 4
                throw new FormatterException('Wrong field name');
18
            }
19 26
            if (get_parent_class($type) == GenericType::class) {
20 24
                $this->fields[$name] = [$default, $type];
21 24
            } else {
22 2
                throw new FormatterException('Wrong instance');
23
            }
24 24
        }
25 24
    }
26
27 12
    public function getData($name, $value)
28
    {
29 12
        $type = $this->getType($name);
30
        try {
31 10
            return $type::getData($value);
32 2
        } catch (FormatterException $e) {
33 2
            return $type::getData($this->getDefaultValue($name));
34
        }
35
    }
36
37 10
    public function getValue($name, $value)
38
    {
39 10
        $type = $this->getType($name);
40
        try {
41 10
            return $type::getValue($value);
42 2
        } catch (FormatterException $e) {
43 2
            return $this->getDefaultValue($name);
44
        }
45
    }
46
47 2
    public function getDataCollection(array $values)
48
    {
49 2
        $ret = [];
50 2
        foreach ($this->getFileds() as $name) {
51 2
            if (array_key_exists($name, $values)) {
52 2
                $ret[$name] = $this->getData($name, $values[$name]);
53 2
            } else {
54 2
                $type = $this->getType($name);
55 2
                $ret[$name] = $type::getData($this->getDefaultValue($name));
56
            }
57 2
        }
58
59 2
        return $ret;
60
    }
61
62 2
    public function getValueCollection(array $values)
63
    {
64 2
        $ret = [];
65 2
        foreach ($this->getFileds() as $name) {
66 2
            if (array_key_exists($name, $values)) {
67 2
                $ret[$name] = $this->getValue($name, $values[$name]);
68 2
            } else {
69 2
                $ret[$name] = $this->getDefaultValue($name);
70
            }
71 2
        }
72
73 2
        return $ret;
74
    }
75
76
    /**
77
     * @return array
78
     */
79 4
    public function getFileds()
80
    {
81 4
        return array_keys($this->fields);
82
    }
83
84
    /**
85
     * @param string $name
86
     *
87
     * @return GenericType
88
     */
89 22
    protected function getField($name)
90
    {
91 22
        if (array_key_exists($name, $this->fields)) {
92 20
            return $this->fields[$name];
93
        } else {
94 2
            throw new FormatterException('Field not exists');
95
        }
96
    }
97
98 8
    protected function getDefaultValue($name)
99
    {
100 8
        list($default, $type) = $this->getField($name);
0 ignored issues
show
The assignment to $type is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
101
102 8
        return $default;
103
    }
104
105
    /**
106
     * @param $name
107
     *
108
     * @return \iMega\Formatter\Typer
109
     */
110 22
    protected function getType($name)
111
    {
112 22
        list($default, $type) = $this->getField($name);
0 ignored issues
show
The assignment to $default is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
113
114 20
        return $type;
115
    }
116
}
117