YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/Core/Response.php

Summary

Maintainability
C
7 hrs
Test Coverage
C
75%

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;
Severity: Minor
Found in api/webservice/Core/Response.php by phpmd

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;
Severity: Minor
Found in api/webservice/Core/Response.php by phpmd

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;
Severity: Minor
Found in api/webservice/Core/Response.php by phpmd

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;
Severity: Minor
Found in api/webservice/Core/Response.php by phpmd

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;
Severity: Minor
Found in api/webservice/Core/Response.php - About 5 hrs to fix

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;
Severity: Major
Found in api/webservice/Core/Response.php - About 2 hrs to fix

    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;
    Severity: Minor
    Found in api/webservice/Core/Response.php - About 25 mins to fix

    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;
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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;
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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()
    Severity: Critical
    Found in api/webservice/Core/Response.php by sonar-php

    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>');
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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";
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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);
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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;
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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;
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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"));
                }
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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());
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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) {
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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);
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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')) {
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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'));
    Severity: Minor
    Found in api/webservice/Core/Response.php by phpmd

    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) {
    Severity: Critical
    Found in api/webservice/Core/Response.php by sonar-php

    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);
    Severity: Minor
    Found in api/webservice/Core/Response.php by phan

    Call to method addChild from undeclared class \SimpleXMLElement
    Open

                    $xmlData->addChild("$key", htmlspecialchars("$value"));
    Severity: Critical
    Found in api/webservice/Core/Response.php by phan

    Returning type false but getInstance() is declared to return \Api\Core\Response
    Open

            return static::$instance;
    Severity: Minor
    Found in api/webservice/Core/Response.php by phan

    Call to method __construct from undeclared class \SimpleXMLElement
    Open

            $xml = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');
    Severity: Critical
    Found in api/webservice/Core/Response.php by phan

    Assigning \Api\Core\Response to property but \Api\Core\Response::$instance is false
    Open

                static::$instance = new self();
    Severity: Minor
    Found in api/webservice/Core/Response.php by phan

    Parameter $xmlData has undeclared type \SimpleXMLElement
    Open

        public function toXml($data, \SimpleXMLElement &$xmlData)
    Severity: Minor
    Found in api/webservice/Core/Response.php by phan

    Call to method asXML from undeclared class \SimpleXMLElement
    Open

            return $xml->asXML();
    Severity: Critical
    Found in api/webservice/Core/Response.php by phan

    Call to method addChild from undeclared class \SimpleXMLElement
    Open

                    $subnode = $xmlData->addChild($key);
    Severity: Critical
    Found in api/webservice/Core/Response.php by phan

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Access control allow headers.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $acceptableHeaders = ['x-api-key', 'x-encrypted', 'x-token'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var string[]

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $body;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $request;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var \Api\Core\Request

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * File instance.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var \App\Fields\File

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Request instance.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $file;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected static $instance = false;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Access control allow methods.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $acceptableMethods = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Headers.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var string[]

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param string $key

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setStatus(int $status): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->status = $status;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $statusCodes = [

    Spaces must be used to indent lines; tabs are not allowed
    Open

                404 => 'Not Found',

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (200 !== $this->status || 'data' !== $this->responseType) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $requestContentType = $this->request->contentType;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var array

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param array $body

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setAcceptableMethods(array $methods)

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->acceptableMethods = array_merge($this->acceptableMethods, $methods);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (isset($this->reasonPhrase)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                500 => 'Internal Server Error',

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public static function getInstance(): self

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

                403 => 'Forbidden',

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $reasonPhrase;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function addHeader(string $key, $value): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->body = $body;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set file instance.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->request = $request;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set acceptable methods.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set acceptable headers.

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return static::$instance;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set status code.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setReasonPhrase(string $reasonPhrase): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setFile(\App\Fields\File $file): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set reason phrase.

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set body data.

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->responseType = 'file';

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param string[] $methods

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $requestContentType = strtolower(\App\Request::_getServer('HTTP_ACCEPT'));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                echo $this->encodeXml($this->body);

    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";

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $status = 200;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return self

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->responseType = 'data';

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $encryptDataTransfer = 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                if (!$headersSent) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            header('Content-length: ' . $this->file->getSize());

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $encrypted;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $log .= 'REQUEST_METHOD: ' . \App\Request::getRequestMethod() . PHP_EOL;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                file_put_contents('cache/logs/webserviceDebug.log', $log, FILE_APPEND);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $xml->asXML();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $xmlData->addChild("$key", htmlspecialchars("$value"));

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var string Reason phrase.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setBody(array $body): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            if (!$headersSent) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!static::$instance) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param int $status

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $log .= 'QUERY_STRING: ' . $_SERVER['QUERY_STRING'] . PHP_EOL;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $log .= "----------- Response data -----------\n";

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param \App\Fields\File $file

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->file = $file;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                401 => 'Unauthorized',

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $encryptDataTransfer = \App\Config::api('ENCRYPT_DATA_TRANSFER') ? 1 : 0;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (empty($requestContentType) || '*/*' === $requestContentType) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                header("Content-type: $requestContentType");

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Encode json data output.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function encodeXml($responseData)

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->toXml($responseData, $xml);

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var string Response data type.

    Spaces must be used to indent lines; tabs are not allowed
    Open

                static::$instance = new self();

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Add header.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param string $reasonPhrase

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $headers = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setRequest(Request $request): void

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param mixed  $value

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                200 => 'OK',

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $log .= 'IP: ' . $_SERVER['REMOTE_ADDR'] . PHP_EOL;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return string

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Set request.

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $subnode = $xmlData->addChild($key);

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param \Api\Core\Request $request

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                header('Access-Control-Allow-Methods: ' . implode(', ', $this->acceptableMethods));

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    case 'file':

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        break;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param string[] $headers

    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);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->acceptableHeaders = array_merge($this->acceptableHeaders, $headers);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                return str_ireplace(["\r\n", "\r", "\n"], ' ', $this->reasonPhrase);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($encryptDataTransfer) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                switch ($this->responseType) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                    header('Content-disposition: attachment; filename="api.xml"');

    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);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function debugResponse()

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $log .= 'REQUEST_URI: ' . $_SERVER['REQUEST_URI'] . PHP_EOL;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @var int Response status code.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Get instance.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                foreach ($this->headers as $key => $header) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                    header('Content-disposition: attachment; filename="api.json"');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->debugResponse();

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function encryptData($data)

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $xml = new \SimpleXMLElement('<?xml version="1.0"?><data></data>');

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function toXml($data, \SimpleXMLElement &$xmlData)

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function setAcceptableHeaders(array $headers)

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return string

    Spaces must be used to indent lines; tabs are not allowed
    Open

                405 => 'Method Not Allowed',

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return json_encode($responseData, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (!$headersSent) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @return void

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            return $statusCodes[$this->status] ?? $statusCodes[500];

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function send()

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $headersSent = headers_sent();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                header('Content-disposition: attachment; filename="api.json"');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                if (!$headersSent) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                echo $this->encodeJson($this->body);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Debug response function.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                } else {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        protected $responseType;

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->headers[$key] = $value;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $this->reasonPhrase = $reasonPhrase;

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /**

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * Get reason phrase.

    Spaces must be used to indent lines; tabs are not allowed
    Open

        private function getReasonPhrase(): string

    Spaces must be used to indent lines; tabs are not allowed
    Open

                header(\App\Request::_getServer('SERVER_PROTOCOL') . ' ' . $this->status . ' ' . $this->getReasonPhrase());

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    header(\strtolower($key) . ': ' . $header);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if (isset($this->file) && file_exists($this->file->getPath())) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            header('Content-transfer-encoding: binary');

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

            foreach ($data as $key => $value) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            readfile($this->file->getPath());

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if (\App\Config::debug('apiLogAllRequests')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

         */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if (\is_array($value)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                header('Access-Control-Allow-Origin: *');

    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));

    Spaces must be used to indent lines; tabs are not allowed
    Open

                header('Encrypted: ' . $encryptDataTransfer);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if (!empty($this->body)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    case 'data':

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function encodeJson($responseData): string

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Line exceeds 120 characters; contains 158 characters
    Open

                header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, ' . implode(', ', $this->acceptableHeaders));

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            if (false !== strpos($requestContentType, 'application/xml')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        break;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            header('Content-type: ' . $this->file->getMimeType());

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            header('Content-disposition: attachment; filename="' . $this->file->getName() . '"');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Line exceeds 120 characters; contains 137 characters
    Open

                $log = '============ Request ' . \App\RequestUtil::requestId() . ' (Response) ======  ' . date('Y-m-d H:i:s') . "  ======\n";

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if ($this->body) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $log .= print_r($this->body, true) . PHP_EOL;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         *

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $this->toXml($value, $subnode);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    echo $this->encryptData($this->body);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if (!empty($this->body)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $log .= 'PATH_INFO: ' . ($_SERVER['PATH_INFO'] ?? '') . PHP_EOL;

    Spaces must be used to indent lines; tabs are not allowed
    Open

         * @param array $responseData

    Spaces must be used to indent lines; tabs are not allowed
    Open

                if (is_numeric($key)) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $key = 'item' . $key;

    There are no issues that match your filters.

    Category
    Status