debugResponse accesses the super-global variable $_SERVER. Open
public function debugResponse()
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . 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
debugResponse accesses the super-global variable $_SERVER. Open
public function debugResponse()
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . 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
debugResponse accesses the super-global variable $_SERVER. Open
public function debugResponse()
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . 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
debugResponse accesses the super-global variable $_SERVER. Open
public function debugResponse()
{
if (\App\Config::debug('apiLogAllRequests')) {
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . 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
Function send
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
public function send()
{
$encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;
if (200 !== $this->status || 'data' !== $this->responseType) {
$encryptDataTransfer = 0;
- 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
Method send
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function send()
{
$encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;
if (200 !== $this->status || 'data' !== $this->responseType) {
$encryptDataTransfer = 0;
Function toXml
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function toXml($data, \SimpleXMLElement &$xmlData)
{
foreach ($data as $key => $value) {
if (is_numeric($key)) {
$key = 'item' . $key;
- 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
The method send() has an NPath complexity of 756. The configured NPath complexity threshold is 200. Open
public function send()
{
$encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;
if (200 !== $this->status || 'data' !== $this->responseType) {
$encryptDataTransfer = 0;
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method send() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function send()
{
$encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;
if (200 !== $this->status || 'data' !== $this->responseType) {
$encryptDataTransfer = 0;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 40 to the 15 allowed. Open
public function send()
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '299', column '14'). Open
$xml = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
- 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
Avoid using static access to class '\App\RequestUtil' in method 'debugResponse'. Open
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . 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
The method send uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (!$headersSent) {
header('Content-disposition: attachment; filename="api.json"');
}
echo $this->encodeJson($this->body);
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Request' in method 'debugResponse'. 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\Config' in method 'send'. Open
$encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;
- 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
The method toXml uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$xmlData->addChild("$key", htmlspecialchars("$value"));
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Request' in method 'send'. Open
header(\App\Request::_getServer('SERVER_PROTOCOL') . ' ' . $this->status . ' ' . $this->getReasonPhrase());
- 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
The method send uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
switch ($this->responseType) {
case 'data':
if (!empty($this->body)) {
if (!$headersSent) {
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Config' in method 'encryptData'. Open
openssl_public_encrypt($data, $encrypted, 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PUBLIC_KEY'), OPENSSL_PKCS1_OAEP_PADDING);
- 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 'debugResponse'. 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
Avoid using static access to class '\App\Request' in method 'send'. Open
$requestContentType = strtolower(\App\Request::_getServer('HTTP_ACCEPT'));
- 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
Add a "case default" clause to this "switch" statement. Open
switch ($this->responseType) {
- 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 1 (data)
is array
but \openssl_public_encrypt()
takes string
Open
openssl_public_encrypt($data, $encrypted, 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PUBLIC_KEY'), OPENSSL_PKCS1_OAEP_PADDING);
- Exclude checks
Call to method addChild
from undeclared class \SimpleXMLElement
Open
$xmlData->addChild("$key", htmlspecialchars("$value"));
- Exclude checks
Returning type false
but getInstance()
is declared to return \Api\Core\Response
Open
return static::$instance;
- Exclude checks
Call to method __construct
from undeclared class \SimpleXMLElement
Open
$xml = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
- Exclude checks
Assigning \Api\Core\Response
to property but \Api\Core\Response::$instance
is false
Open
static::$instance = new self();
- Exclude checks
Parameter $xmlData
has undeclared type \SimpleXMLElement
Open
public function toXml($data, \SimpleXMLElement &$xmlData)
- Exclude checks
Call to method asXML
from undeclared class \SimpleXMLElement
Open
return $xml->asXML();
- Exclude checks
Call to method addChild
from undeclared class \SimpleXMLElement
Open
$subnode = $xmlData->addChild($key);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Access control allow headers.
- 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
protected $acceptableHeaders = ['x-api-key', 'x-encrypted', 'x-token'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string[]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $body;
- 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
protected $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
* @var \Api\Core\Request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* File instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var \App\Fields\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
* Request 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
protected $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
protected static $instance = 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
* Access control allow methods.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
protected $acceptableMethods = [];
- 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
* Headers.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string[]
- 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
* @param string $key
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setStatus(int $status): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->status = $status;
- 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
Spaces must be used to indent lines; tabs are not allowed Open
$statusCodes = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
404 => 'Not Found',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (200 !== $this->status || 'data' !== $this->responseType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$requestContentType = $this->request->contentType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var array
- 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
* @param array $body
- 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 setAcceptableMethods(array $methods)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->acceptableMethods = array_merge($this->acceptableMethods, $methods);
- 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($this->reasonPhrase)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
500 => 'Internal Server Error',
- 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
}
- 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
* @return void
- 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
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
403 => 'Forbidden',
- 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
protected $reasonPhrase;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function addHeader(string $key, $value): 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
$this->body = $body;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set file 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
$this->request = $request;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set acceptable methods.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set acceptable headers.
- 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 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
* Set status code.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setReasonPhrase(string $reasonPhrase): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setFile(\App\Fields\File $file): 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
* @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
* Set reason phrase.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Set body data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->responseType = '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
* @param string[] $methods
- 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
$requestContentType = strtolower(\App\Request::_getServer('HTTP_ACCEPT'));
- 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
echo $this->encodeXml($this->body);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . 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
protected $status = 200;
- 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
$this->responseType = '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
{
- 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
$encryptDataTransfer = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$headersSent) {
- 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
header('Content-length: ' . $this->file->getSize());
- 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 $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
$log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
file_put_contents('cache/logs/webserviceDebug.log', $log, FILE_APPEND);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $xml->asXML();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xmlData->addChild("$key", htmlspecialchars("$value"));
- 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 string Reason phrase.
- 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
public function setBody(array $body): 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
} else {
- 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 (!$headersSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $status
- 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 .= "----------- Response data -----------\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 \App\Fields\File $file
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->file = $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
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
401 => 'Unauthorized',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($requestContentType) || '*/*' === $requestContentType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header("Content-type: $requestContentType");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Encode json data output.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function encodeXml($responseData)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->toXml($responseData, $xml);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var string Response data type.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$instance = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Add header.
- 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 $reasonPhrase
- 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
protected $headers = [];
- 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
public function setRequest(Request $request): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $value
- 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
200 => 'OK',
- 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
$log .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL;
- 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
* Set request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subnode = $xmlData->addChild($key);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \Api\Core\Request $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
header('Access-Control-Allow-Methods: ' . implode(', ', $this->acceptableMethods));
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string[] $headers
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
openssl_public_encrypt($data, $encrypted, 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PUBLIC_KEY'), OPENSSL_PKCS1_OAEP_PADDING);
- 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->acceptableHeaders = array_merge($this->acceptableHeaders, $headers);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return str_ireplace(["\r\n", "\r", "\n"], ' ', $this->reasonPhrase);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($encryptDataTransfer) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($this->responseType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Content-disposition: attachment; filename="api.xml"');
- Exclude checks
Line exceeds 120 characters; contains 162 characters Open
openssl_public_encrypt($data, $encrypted, 'file://' . ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . \App\Config::api('PUBLIC_KEY'), OPENSSL_PKCS1_OAEP_PADDING);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function debugResponse()
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var int Response status 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
* Get 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
foreach ($this->headers as $key => $header) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Content-disposition: attachment; filename="api.json"');
- 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->debugResponse();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function encryptData($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
$xml = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function toXml($data, \SimpleXMLElement &$xmlData)
- 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
public function setAcceptableHeaders(array $headers)
- 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
405 => 'Method Not Allowed',
- 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 json_encode($responseData, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$headersSent) {
- 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
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 $statusCodes[$this->status] ?? $statusCodes[500];
- 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 send()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headersSent = headers_sent();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Content-disposition: attachment; filename="api.json"');
- 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 (!$headersSent) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
echo $this->encodeJson($this->body);
- 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
* Debug response 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
} else {
- 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
protected $responseType;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->headers[$key] = $value;
- 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->reasonPhrase = $reasonPhrase;
- 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
* Get reason phrase.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getReasonPhrase(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header(\App\Request::_getServer('SERVER_PROTOCOL') . ' ' . $this->status . ' ' . $this->getReasonPhrase());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header(\strtolower($key) . ': ' . $header);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($this->file) && file_exists($this->file->getPath())) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Content-transfer-encoding: binary');
- 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
foreach ($data as $key => $value) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
readfile($this->file->getPath());
- 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
*/
- 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 (\is_array($value)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Access-Control-Allow-Origin: *');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, ' . implode(', ', $this->acceptableHeaders));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Encrypted: ' . $encryptDataTransfer);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($this->body)) {
- 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
}
- 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 encodeJson($responseData): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 158 characters Open
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, ' . implode(', ', $this->acceptableHeaders));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== strpos($requestContentType, 'application/xml')) {
- 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
header('Content-type: ' . $this->file->getMimeType());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
header('Content-disposition: attachment; filename="' . $this->file->getName() . '"');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 137 characters Open
$log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ====== ' . date('Y-m-d H:i:s') . " ======\n";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->body) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$log .= print_r($this->body, 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->toXml($value, $subnode);
- 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
echo $this->encryptData($this->body);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($this->body)) {
- 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
* @param array $responseData
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (is_numeric($key)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$key = 'item' . $key;
- Exclude checks