YetiForceCompany/YetiForceCRM

View on GitHub
modules/OpenStreetMap/files/TileLayer.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
38%

Method get has 46 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function get(App\Request $request)
    {
        if (!\App\RequestUtil::isNetConnection()) {
            $this->error();
            return false;
Severity: Minor
Found in modules/OpenStreetMap/files/TileLayer.php - About 1 hr to fix

    Function get has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get(App\Request $request)
        {
            if (!\App\RequestUtil::isNetConnection()) {
                $this->error();
                return false;
    Severity: Minor
    Found in modules/OpenStreetMap/files/TileLayer.php - About 45 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

    Missing class import via use statement (line '19', column '23').
    Open

                throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

    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

    Missing class import via use statement (line '60', column '30').
    Open

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);

    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\YetiForce\Register' in method 'get'.
    Open

            $product = \App\YetiForce\Register::getProduct('YetiForceMap');

    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\Fields\File' in method 'error'.
    Open

            header('content-type: ' . \App\Fields\File::getMimeContentType($fileName));

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\RequestUtil' in method 'get'.
    Open

            if (!\App\RequestUtil::isNetConnection()) {

    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\YetiForce\Register' in method 'get'.
    Open

                    'InsKey' => \App\YetiForce\Register::getInstanceKey()

    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\Log' in method 'get'.
    Open

                \App\Log::error($url . ' | Error: ' . $ex->getMessage(), __CLASS__);

    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\Log' in method 'get'.
    Open

                    \App\Log::error($url . ' | Error: ' . $response->getReasonPhrase(), __CLASS__);

    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 get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $options['auth'] = [$product['params']['login'], $product['params']['pass']];
            }

    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\RequestHttp' in method 'get'.
    Open

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);

    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\Log' in method 'get'.
    Open

                \App\Log::endProfile("GET|TileLayer::get|{$url}", __NAMESPACE__);

    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\Privilege' in method 'getCheckPermission'.
    Open

            if (!\App\Privilege::isPermitted('OpenStreetMap')) {

    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\Log' in method 'get'.
    Open

                \App\Log::beginProfile("GET|TileLayer::get|{$url}", __NAMESPACE__);

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Define a constant instead of duplicating this literal "token" 3 times.
    Open

            if ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token'])) {

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "Integer" 3 times.
    Open

                $request->getByType('z', 'Integer'),

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "params" 7 times.
    Open

            if ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token'])) {

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Call to method error from undeclared class \App\Log
    Open

                \App\Log::error($url . ' | Error: ' . $ex->getMessage(), __CLASS__);
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method getProduct from undeclared class \App\YetiForce\Register
    Open

            $product = \App\YetiForce\Register::getProduct('YetiForceMap');
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method error from undeclared class \App\Log
    Open

                    \App\Log::error($url . ' | Error: ' . $response->getReasonPhrase(), __CLASS__);
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method request from undeclared class \GuzzleHttp\Client
    Open

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method __construct from undeclared class \GuzzleHttp\Client
    Open

                $response = (new \GuzzleHttp\Client(\App\RequestHttp::getOptions()))->request('GET', $url, $options);
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method endProfile from undeclared class \App\Log
    Open

                \App\Log::endProfile("GET|TileLayer::get|{$url}", __NAMESPACE__);
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method beginProfile from undeclared class \App\Log
    Open

                \App\Log::beginProfile("GET|TileLayer::get|{$url}", __NAMESPACE__);
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Call to method getInstanceKey from undeclared class \App\YetiForce\Register
    Open

                    'InsKey' => \App\YetiForce\Register::getInstanceKey()
    Severity: Critical
    Found in modules/OpenStreetMap/files/TileLayer.php by phan

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class OpenStreetMap_TileLayer_File extends Vtiger_Basic_File

    The class OpenStreetMap_TileLayer_File is not named in CamelCase.
    Open

    class OpenStreetMap_TileLayer_File extends Vtiger_Basic_File
    {
        /** {@inheritdoc} */
        public function getCheckPermission(App\Request $request)
        {

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    The 'get()' method which returns a boolean should be named 'is...()' or 'has...()'
    Open

        public function get(App\Request $request)
        {
            if (!\App\RequestUtil::isNetConnection()) {
                $this->error();
                return false;

    BooleanGetMethodName

    Since: 0.2

    Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.

    Example

    class Foo {
        /**
         * @return boolean
         */
        public function getFoo() {} // bad
        /**
         * @return bool
         */
        public function isFoo(); // ok
        /**
         * @return boolean
         */
        public function getFoo($bar); // ok, unless checkParameterizedMethods=true
    }

    Source https://phpmd.org/rules/naming.html#booleangetmethodname

    Line exceeds 120 characters; contains 126 characters
    Open

            if ((empty($product['params']['login']) || empty($product['params']['pass'])) && empty($product['params']['token'])) {

    Class name "OpenStreetMap_TileLayer_File" is not in camel caps format
    Open

    class OpenStreetMap_TileLayer_File extends Vtiger_Basic_File

    There are no issues that match your filters.

    Category
    Status