handleError accesses the super-global variable $_POST. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_SERVER. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_SERVER. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_GET. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_SERVER. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_SERVER. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_GET. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
handleError accesses the super-global variable $_POST. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
Method __construct
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct($message, $code = 500, \Throwable $previous = null)
{
$message = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $message), PHP_EOL);
if (!empty($previous)) {
parent::__construct($message, $code, $previous);
Method handleError
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
Function handleError
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function __construct
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($message, $code = 500, \Throwable $previous = null)
{
$message = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $message), PHP_EOL);
if (!empty($previous)) {
parent::__construct($message, $code, $previous);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid using static access to class '\App\Config' in method '__construct'. Open
if (!\App\Config::debug('apiShowExceptionMessages')) {
- 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 'Api\Core\Request' in method '__construct'. Open
$response->setRequest(Request::init());
- 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 '__construct'. Open
if (\App\Config::debug('apiShowExceptionBacktrace')) {
- 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 '__construct'. Open
if (\App\Config::debug('apiShowExceptionReasonPhrase')) {
- 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 '95', column '8'). Open
public function handleError(): void
{
if (\App\Config::debug('apiLogException')) {
$request = Request::init();
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
Avoid using static access to class '\App\Debuger' in method '__construct'. Open
$body['error']['backtrace'] = \App\Debuger::getBacktrace();
- 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 'Api\Core\Response' in method '__construct'. Open
$response = Response::getInstance();
- 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 'handleError'. Open
if (\App\Config::debug('apiLogException')) {
- 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\RequestUtil' in method 'handleError'. Open
$error .= '============ Request ' . \App\RequestUtil::requestId() . ' ====== ' . date('Y-m-d H:i:s') . " ======\n";
- 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\Request' in method 'handleError'. Open
$error .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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 'Api\Core\Request' in method 'handleError'. Open
$request = Request::init();
- 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
Define a constant instead of duplicating this literal "error" 5 times. Open
'error' => [
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($this->code)) {
- 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
$response->setRequest(Request::init());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function handleError(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= '============ stacktrace: ' . PHP_EOL . $this->getTraceAsString() . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= '----------- Request data -----------' . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= "----------- _POST -----------\n";
- 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
$body['error']['line'] = $this->getLine();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Handle error function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= "file: {$this->getFile()} ({$this->getLine()})\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($request->getHeaders() as $key => $header) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($_POST) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
file_put_contents(ROOT_DIRECTORY . '/cache/logs/webserviceErrors.log', '============ Error exception ====== ' . date('Y-m-d H:i:s') . ' ======'
- 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
$response->setBody($body);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= '============ Request ' . \App\RequestUtil::requestId() . ' ====== ' . date('Y-m-d H:i:s') . " ======\n";
- 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 (\App\Config::debug('apiShowExceptionBacktrace')) {
- 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
$error .= 'PATH_INFO: ' . ($_SERVER['PATH_INFO'] ?? '') . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __construct($message, $code = 500, \Throwable $previous = null)
- 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
'status' => 0,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'message' => $message,
- 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 (!empty($previous)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$request = Request::init();
- 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
$this->file = $previous->getFile();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\Config::debug('apiShowExceptionMessages')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$body = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response = Response::getInstance();
- 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 (\App\Config::debug('apiLogException')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($_GET) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->line = $previous->getLine();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = 'Internal Server Error';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$body['error']['previous'] = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $previous->__toString()), PHP_EOL);
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
$body['error']['previous'] = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $previous->__toString()), PHP_EOL);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error = "code: {$this->getCode()} | message: {$this->getMessage()}\n";
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'error' => [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$body['error']['file'] = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $this->getFile()), PHP_EOL);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$body['error']['backtrace'] = \App\Debuger::getBacktrace();
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
$error .= '============ Request ' . \App\RequestUtil::requestId() . ' ====== ' . date('Y-m-d H:i:s') . " ======\n";
- 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 (\App\Config::debug('apiShowExceptionReasonPhrase')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->send();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= 'REQUEST_URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= "----------- _GET -----------\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= print_r($_POST, true) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= "----------- Request payload -----------\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= print_r($payload, true) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->message = $message;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->code = $code;
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$body['error']['file'] = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $this->getFile()), PHP_EOL);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($payload = file_get_contents('php://input')) {
- Exclude checks
Line exceeds 120 characters; contains 155 characters Open
file_put_contents(ROOT_DIRECTORY . '/cache/logs/webserviceErrors.log', '============ Error exception ====== ' . date('Y-m-d H:i:s') . ' ======'
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = rtrim(str_replace(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR, '', $message), PHP_EOL);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($previous)) {
- 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
$error .= $key . ': ' . $header . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= print_r($_GET, true) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($this->message)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setReasonPhrase($this->message);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= print_r($request->getAllRaw(), true) . PHP_EOL;
- 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
'code' => $code,
- 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
$error .= 'QUERY_STRING: ' . $_SERVER['QUERY_STRING'] . PHP_EOL;
- 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
$response->setStatus($code);
- 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
parent::__construct($message, $code, $previous);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$error .= '----------- Headers -----------' . PHP_EOL;
- 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
. PHP_EOL . $error . PHP_EOL, FILE_APPEND);
- Exclude checks