debugRequest accesses the super-global variable $_SERVER. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_GET. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_SERVER. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_POST. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_SERVER. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_SERVER. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_GET. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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
debugRequest accesses the super-global variable $_POST. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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 preProcess
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function preProcess(): bool
{
register_shutdown_function(function () {
if ($error = error_get_last()) {
$this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
Method debugRequest
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
Method process
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(): void
{
$handlerClass = $this->getActionClassName();
$this->request->loadData();
$this->debugRequest();
Function debugRequest
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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 getActionClassName
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function getActionClassName(): string
{
$type = $this->request->getByType('_container', 'Standard');
$this->request->delete('_container');
$actionName = $this->request->getByType('action', 'Alnum');
- 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 undefined variables such as '$listTables' which will lead to PHP notices. Open
$this->app['tables'] = Core\Containers::$listTables[$this->app['type']] ?? [];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
The class Controller has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open
class Controller
{
/** @var \self */
private static $instance;
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Avoid assigning values to variables in if clauses and the like (line '75', column '8'). Open
public function preProcess(): bool
{
register_shutdown_function(function () {
if ($error = error_get_last()) {
$this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
- 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\Log' in method 'errorHandler'. Open
\App\Log::error($no . ': ' . $str . ' in ' . $file . ', line ' . $line);
- 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
$this->response = Core\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 'Api\Core\Request' in method '__construct'. Open
$this->request = Core\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\Request' in method '__construct'. Open
$this->method = \App\Request::getRequestMethod();
- 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 'debugRequest'. Open
$log .= '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 '\App\RequestUtil' in method 'debugRequest'. Open
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . 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 'Api\Core\Auth' in method 'preProcess'. Open
Core\Auth::init($this);
- 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 'preProcess'. Open
if (!empty($this->app['ips']) && !\in_array(\App\RequestUtil::getRemoteIP(true), array_map('trim', explode(',', $this->app['ips'])))) {
- 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 '210', column '8'). Open
public function debugRequest(): void
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- 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\Config' in method 'debugRequest'. Open
if (\App\Config::debug('apiLogAllRequests')) {
- 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 "action" 3 times. Open
if ($this->request->isEmpty('action', true)) {
- 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.
Doc-block of getInstance
contains declared return type \self
which is incompatible with the return type \Api\Controller
declared in the signature Open
* @return \self
- Exclude checks
Assigning \Api\Controller
to property but \Api\Controller::$instance
is \self
Open
return self::$instance = new self();
- Exclude checks
Return type of getInstance()
is undeclared type \self
Open
public static function getInstance(): self
- Exclude checks
Call to method error
from undeclared class \App\Log
Open
\App\Log::error($no . ': ' . $str . ' in ' . $file . ', line ' . $line);
- Exclude checks
Argument 1 (raw)
is 'module'
but \Api\Core\Request::getModule()
takes bool|true
defined at /code/app/Request.php:548
Open
$module = $this->request->getModule('module');
- Exclude checks
Remove the code after this "throw". Open
throw new Core\Exception('Unsupported response type: ' . $this->actionHandler->responseType, 400);
- Read upRead up
- Exclude checks
Jump statements (return
, break
, continue
, and goto
) and throw
expressions move
control flow out of the current code block. Typically, any statements in a block that come after a jump or throw
are simply wasted
keystrokes lying in wait to confuse the unwary.
Rarely, as illustrated below, code after a jump or throw
is reachable. However, such code is difficult to understand, and should be
refactored.
Noncompliant Code Example
function fun($a) { $i = 10; return $i + $a; $i++; // this is never executed } function foo($a) { if ($a == 5) { goto error; } else { // do the job } return; error: printf("don't use 5"); // this is reachable but unreadable }
Compliant Solution
function fun($a) { $i = 10; return $i + $a; } function foo($a) { if ($a == 5) { handleError(); } else { // do the job } return; }
See
- MISRA C:2004, 14.1 - There shall be no unreachable code
- MISRA C++:2008, 0-1-1 - A project shall not contain unreachable code
- MISRA C++:2008, 0-1-9 - There shall be no dead code
- MISRA C:2012, 2.1 - A project shall not contain unreachable code
- MISRA C:2012, 2.2 - There shall be no dead code
- MITRE, CWE-561 - Dead Code
- CERT, MSC56-J. - Detect and remove superfluous code and values
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC07-CPP. - Detect and remove dead code
Avoid variables with short names like $no. Configured minimum length is 3. Open
public static function errorHandler(int $no, string $str, string $file, int $line): void
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $e. Configured minimum length is 3. Open
public function handleError(\Throwable $e): void
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used to indent lines; tabs are not allowed Open
public $request;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Construct.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var array Headers. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var array Current server details (w_#__servers). */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response = Core\Response::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function __construct()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->request = Core\Request::init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var \self */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private $actionHandler;
- 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 getInstance(): self
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return self::$instance;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return self::$instance = new self();
- 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 $app;
- 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 bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Request method. */
- 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
$this->headers = $this->request->getHeaders();
- 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->response->setAcceptableMethods($this->actionHandler->allowedMethod);
- 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
$actionName = $this->request->getByType('action', 'Alnum');
- 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 function debugRequest(): void
- 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 \Api\Core\Request Request instance. */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \self
- 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
$this->app['tables'] = Core\Containers::$listTables[$this->app['type']] ?? [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response->setAcceptableHeaders($this->actionHandler->allowedHeaders);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->actionHandler->preProcess();
- 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
$this->response->send();
- 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
$log .= '----------- Headers -----------' . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
file_put_contents(ROOT_DIRECTORY . '/cache/logs/webserviceDebug.log', $log, FILE_APPEND);
- 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 (isset(self::$instance)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Core\Auth::init($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
$this->request->loadData();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$return = \call_user_func([$this->actionHandler, strtolower($this->method)]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'status' => 1,
- 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
$log .= print_r($this->request->getAllRaw(), true) . PHP_EOL;
- 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
private static $instance;
- 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 function preProcess(): bool
- 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 (null !== $return) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'data':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'result' => $return,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = "Api\\$type\\$module\\$actionName";
- 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
$log .= print_r($payload, true) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response->setRequest($this->request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->method = \App\Request::getRequestMethod();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return true;
- 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
Line exceeds 120 characters; contains 139 characters Open
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= "----------- _GET -----------\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $response;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $method;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $headers;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Pre process function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response->setAcceptableHeaders($handler->allowedHeaders);
- 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 ($this->actionHandler->responseType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response->setBody([
- 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 (class_exists($className)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = "Api\\$type\\BaseAction\\$actionName";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($this->request->getHeaders() as $key => $header) {
- 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
* Get controller instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($error = error_get_last()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handlerClass = $this->getActionClassName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Process::$processType = $this->app['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
* Post process function.
- 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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->request->delete('_container');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (class_exists($className)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Config::debug('apiLogAllRequests')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= 'REQUEST_URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= print_r($_GET, true) . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var \Api\Core\Response Response instance. */
- 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 postProcess(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \Api\Core\Exception
- 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
$module = $this->request->getModule('module');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = "Api\\$type\\BaseModule\\$actionName";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= '----------- Request data -----------' . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \Api\Core\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('OPTIONS' === $this->method) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handler = new $handlerClass();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response->setAcceptableMethods($handler->allowedMethod);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get action class name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $className;
- 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
throw new Core\Exception('No action found', 405);
- 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
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Controller) ====== ' . date('Y-m-d H:i:s') . " ======\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new Core\Exception('Web service - Applications: Unauthorized', 401);
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
if (!empty($this->app['ips']) && !\in_array(\App\RequestUtil::getRemoteIP(true), array_map('trim', explode(',', $this->app['ips'])))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new Core\Exception('Illegal IP address', 401);
- 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->actionHandler->controller = $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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($module) {
- 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
$log .= 'PATH_INFO: ' . ($_SERVER['PATH_INFO'] ?? '') . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= print_r($_POST, 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
$log .= "----------- Request payload -----------\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'error_method' => $this->request->getServer('REQUEST_URI'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($no, [E_ERROR, E_WARNING, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var Core\BaseAction */
- 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
$this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new Core\Exception('No action', 404);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$handlerClass = $this->getActionClassName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->actionHandler = new $handlerClass();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->actionHandler->checkAction();
- 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 $className;
- 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
$log .= 'QUERY_STRING: ' . $_SERVER['QUERY_STRING'] . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function errorHandler(int $no, string $str, string $file, int $line): void
- 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 false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \Api\Core\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->debugRequest();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$module && class_exists($className)) {
- 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
$log .= "----------- _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
* @param string $str
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
register_shutdown_function(function () {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($this->app)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->request->isEmpty('action', true)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getActionClassName(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $className;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Debug request function.
- 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 $file
- 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
set_error_handler([$this, 'errorHandler']);
- 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($this->app['ips']) && !\in_array(\App\RequestUtil::getRemoteIP(true), array_map('trim', explode(',', $this->app['ips'])))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Process::$processName = $this->request->getByType('action', \App\Purifier::ALNUM);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process function.
- 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
*/
- 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 'file':
- 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
$type = $this->request->getByType('_container', 'Standard');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($payload = 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
$this->actionHandler->updateUser([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->response->setFile($return);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new Core\Exception('Unsupported response type: ' . $this->actionHandler->responseType, 400);
- 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
$log .= "$key : $header\n";
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function handleError(\Throwable $e): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'custom_params' => [
- 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
* @throws \Api\Core\Exception
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($this->actionHandler)) {
- 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 void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'last_error' => $e->getMessage(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'error_time' => date('Y-m-d H:i:s'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $no
- 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
* Exception error handler function..
- 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
\App\Log::error($no . ': ' . $str . ' in ' . $file . ', line ' . $line);
- 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 \Throwable $e
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->actionHandler->updateSession();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @see https://secure.php.net/manual/en/function.set-error-handler.php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $line
- 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 void
- 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