init accesses the super-global variable $_SERVER. Open
public static function init($request = false)
{
if (!static::$request) {
static::$request = new self($request ?: $_REQUEST);
static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
init accesses the super-global variable $_REQUEST. Open
public static function init($request = false)
{
if (!static::$request) {
static::$request = new self($request ?: $_REQUEST);
static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Missing class import via use statement (line '135', column '14'). Open
throw new \App\Exceptions\AppException('Private Key failed');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method init has a boolean flag argument $request, which is a certain sign of a Single Responsibility Principle violation. Open
public static function init($request = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class '\App\Utils' in method 'loadData'. Open
$this->rawValues = \App\Utils::merge($this->contentParse($content), $this->rawValues);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Config' in method 'loadData'. Open
if (\App\Config::api('ENCRYPT_DATA_TRANSFER') && $encrypted && 1 === (int) $encrypted) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Config' in method 'decryptData'. Open
$privateKey = 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PRIVATE_KEY');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid assigning values to variables in if clauses and the like (line '134', column '8'). Open
public function decryptData(string $data): string
{
$privateKey = 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PRIVATE_KEY');
if (!$privateKey = openssl_pkey_get_private($privateKey)) {
throw new \App\Exceptions\AppException('Private Key failed');
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Rename "$content" which has the same name as the field declared at line 24. Open
$content = file_get_contents('php://input');
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Add a "case default" clause to this "switch" statement. Open
switch ($type) {
- Read upRead up
- Exclude checks
The requirement for a final case default
clause is defensive programming. The clause should either take appropriate action, or contain
a suitable comment as to why no action is taken. Even when the switch
covers all current values of an enum
, a default case
should still be used because there is no guarantee that the enum
won't be extended.
Noncompliant Code Example
switch ($param) { //missing default clause case 0: do_something(); break; case 1: do_something_else(); break; } switch ($param) { default: // default clause should be the last one error(); break; case 0: do_something(); break; case 1: do_something_else(); break; }
Compliant Solution
switch ($param) { case 0: do_something(); break; case 1: do_something_else(); break; default: error(); break; }
See
- MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
- MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
- MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
- MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
- MISRA C:2012, 16.1 - All switch statements shall be well-formed
- MISRA C:2012, 16.4 - Every switch statement shall have a default label
- MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
- MITRE, CWE-478 - Missing Default Case in Switch Statement
- CERT, MSC01-C. - Strive for logical completeness
- CERT, MSC01-CPP. - Strive for logical completeness
Argument 2 (assoc)
is 1
but \json_decode()
takes bool
Open
$return = json_decode($content, 1);
- Exclude checks
Assigning ?array|?array{}|?bool|?float|?int|?string
to property but \Api\Core\Request->content
is array
Open
return $this->content = $return;
- Exclude checks
Call to method parse
from undeclared class \Notihnio\MultipartFormDataParser\MultipartFormDataParser
Open
$return = \Notihnio\MultipartFormDataParser\MultipartFormDataParser::parse()->params;
- Exclude checks
Returning type ?array|?array{}|?bool|?float|?int|?string
but contentParse()
is declared to return array
Open
return $this->content = $return;
- Exclude checks
Argument 1 (key)
is resource
but \openssl_pkey_get_private()
takes string
Open
$privateKey = openssl_pkey_get_private($privateKey);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-header-fields' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool|array $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($type) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return array_map('\App\Purifier::purify', array_keys($this->content));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$privateKey = 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PRIVATE_KEY');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $contentType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-parent-id' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$request->contentType = static::$request->getHeader('accept');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return static::$request;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$encrypted = $this->getHeader('encrypted');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = file_get_contents('php://input');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'json':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'x-www-form-urlencoded':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
openssl_private_decrypt($data, $decrypted, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-row-limit' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return $this
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('GET' === self::getRequestMethod()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-unit-price' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-unit-gross' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$type = explode('/', (explode(';', $type)[0]));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'encrypted' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-token' => \App\Purifier::ALNUM,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-row-offset' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Static instance initialization.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!static::$request) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'form-data':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var array List of headings and sanitization methods. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $headersPurifierMap = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Load data from request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($content)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Parsing the content of the request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-only-column' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-cv-id' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->rawValues = \App\Utils::merge($this->contentParse($content), $this->rawValues);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->content = $return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function init($request = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function loadData(): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var array The content of the request. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Config::api('ENCRYPT_DATA_TRANSFER') && $encrypted && 1 === (int) $encrypted) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $content
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($type)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get key of the content request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Decrypt content of the request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Requested content type. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty(static::$request->contentType)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function decryptData(string $data): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('Private Key failed');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-product-bundles' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-start-with' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-row-count' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = $this->decryptData($content);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function contentParse(string $content): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$type = $this->contentType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'authorization' => \App\Purifier::ALNUM_EXTENDED,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$request = new self($request ?: $_REQUEST);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$type = array_pop($type);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = json_decode($content, 1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-raw-data' => \App\Purifier::INTEGER,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$privateKey = openssl_pkey_get_private($privateKey);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'x-api-key' => \App\Purifier::ALNUM,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getContentKeys(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $decrypted;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $content = [];
- Exclude checks
Line exceeds 120 characters; contains 168 characters Open
static::$request->contentType = isset($_SERVER['CONTENT_TYPE']) ? static::$request->getServer('CONTENT_TYPE') : static::$request->getHeader('content-type');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = \Notihnio\MultipartFormDataParser\MultipartFormDataParser::parse()->params;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $data
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$privateKey = openssl_pkey_get_private($privateKey)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks