Issues (125)

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/Converter.php (4 issues)

Labels
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 Basis;
4
5
use Carbon\Carbon;
6
use Exception;
7
use stdClass;
8
use Tarantool\Mapper\Entity;
9
10
class Converter
11
{
12 56
    public function isTuple($array)
13
    {
14 56
        if (is_object($array)) {
15 1
            $array = get_object_vars($array);
16
        }
17 56
        if (!is_array($array)) {
18 7
            return false;
19
        }
20 56
        if (!count($array)) {
21 56
            return true;
22
        }
23 56
        if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
24 56
            return array_key_last($array) === count($array) - 1;
25
        }
26
        return array_values($array) == $array;
27
    }
28
29 56
    public function toObject($data)
30
    {
31 56
        if (is_array($data)) {
32 56
            if ($this->isTuple($data)) {
33 56
                return $this->convertArrayToObject($data);
34
            }
35
        }
36
37 56
        if (is_object($data)) {
38 5
            if ($data instanceof Entity) {
39
                // keep instance
40 3
                return $data;
41
            }
42
43 2
            $tmp = $data;
44 2
            $data = [];
45 2
            foreach ($tmp as $k => $v) {
46 2
                $data[$k] = $v;
47
            }
48
        }
49
50 56
        $data = (object) $data;
51
52 56
        foreach ($data as $k => $v) {
53 56
            if (is_array($v) && $this->isTuple($v)) {
54 56
                $data->$k = $this->convertArrayToObject($v);
55 56
            } elseif (is_array($v) || is_object($v)) {
56 10
                $data->$k = $this->toObject($v);
57
            }
58
        }
59
60 56
        return $data;
61
    }
62
63 56
    public function convertArrayToObject($data)
64
    {
65 56
        $result = [];
66 56
        foreach ($data as $k => $v) {
67 7
            if ($this->isTuple($v)) {
68
                $result[$k] = $this->convertArrayToObject($v);
69 7
            } elseif (is_object($v) || is_array($v)) {
70
                $result[$k] = $this->toObject($v);
71
            } else {
72 7
                $result[$k] = $v;
73
            }
74
        }
75 56
        return $result;
76
    }
77
78 11
    public function toArray($data) : array
79
    {
80 11
        if (!$data) {
81 2
            return [];
82
        }
83
84 11
        if (is_object($data)) {
85 9
            $data = get_object_vars($data);
86
        }
87
88 11
        foreach ($data as $k => $v) {
89 11
            if (is_array($v) || is_object($v)) {
90 4
                $data[$k] = $this->toArray($v);
91
            }
92
        }
93
94 11
        return $data;
95
    }
96
97
    private $underscores = [];
98
99 1
    public function toUnderscore(string $input) : string
100
    {
101 1
        if (!array_key_exists($input, $this->underscores)) {
102 1
            preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches);
103 1
            $ret = $matches[0];
104 1
            foreach ($ret as &$match) {
105 1
                $match = $match == strtoupper($match) ? strtolower($match) : lcfirst($match);
106
            }
107 1
            $this->underscores[$input] = implode('_', $ret);
108
        }
109 1
        return $this->underscores[$input];
110
    }
111
112
    private $camelcased = [];
113
114 1
    public function toCamelCase(string $string, bool $capitalize = false) : string
115
    {
116 1
        $capitalize = $capitalize ? 1 : 0;
117
118 1
        if (!array_key_exists($capitalize, $this->camelcased)) {
119 1
            $this->camelcased[$capitalize] = [];
120
        }
121
122 1
        if (!array_key_exists($string, $this->camelcased[$capitalize])) {
123 1
            $chain = explode('_', $string);
124 1
            foreach ($chain as $index => $word) {
125 1
                $chain[$index] = $index || $capitalize ? ucfirst($word) : $word;
126
            }
127
128 1
            $this->camelcased[$capitalize][$string] = implode('', $chain);
129
        }
130
131 1
        return $this->camelcased[$capitalize][$string];
132
    }
133
134
135
    private $dates = [];
136
137 1
    public function getDate($string)
138
    {
139 1
        $key = $string;
140 1
        if (func_num_args() == 3) {
141 1
            $key = implode('.', func_get_args());
142
        }
143
144 1
        if (Carbon::hasTestNow() || !array_key_exists($key, $this->dates)) {
145 1
            if (strlen($string) == 8 && is_numeric($string)) {
146 1
                $value = Carbon::createFromFormat('Ymd', $string)->setTime(0, 0, 0);
0 ignored issues
show
The method setTime does only exist in Carbon\CarbonInterface, but not in Carbon\Traits\Creator.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
147 1
            } elseif (func_num_args() == 3) {
148 1
                [$year, $month, $day] = func_get_args();
0 ignored issues
show
The variable $year does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $month does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $day does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
149 1
                $value = Carbon::createFromDate($year, $month, $day)->setTime(0, 0, 0);
150
            } else {
151 1
                $value = Carbon::parse($string);
152
            }
153 1
            if (Carbon::hasTestNow()) {
154 1
                return $value;
155
            }
156 1
            $this->dates[$key] = $value;
157
        }
158 1
        return $this->dates[$key]->copy();
159
    }
160
161 1
    public function getTimestamp($string)
162
    {
163 1
        return $this->getDate($string)->timestamp;
164
    }
165
166 1
    public function getPluralForm($n, $forms)
167
    {
168 1
        return is_float($n)?$forms[1]:($n%10==1&&$n%100!=11?$forms[0]:($n%10>=2&&$n%10<=4&&($n%100<10||$n%100>=20)?$forms[1]:$forms[2]));
169
    }
170
}
171