AJenbo/agcms

View on GitHub
application/inc/Routes.php

Summary

Maintainability
B
5 hrs
Test Coverage
A
99%

Method load has 139 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function load(Application $app): void
    {
        $app->middleware([Utf8Url::class, Auth::class]);
        if ($app->environment('develop')) {
            $app->middleware(Placekitten::class);
Severity: Major
Found in application/inc/Routes.php - About 5 hrs to fix

    The method load() has 185 lines of code. Current threshold is set to 100. Avoid really long methods.
    Open

        public static function load(Application $app): void
        {
            $app->middleware([Utf8Url::class, Auth::class]);
            if ($app->environment('develop')) {
                $app->middleware(Placekitten::class);
    Severity: Minor
    Found in application/inc/Routes.php by phpmd

    This function "load" has 184 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
    Open

        public static function load(Application $app): void
    Severity: Major
    Found in application/inc/Routes.php by sonar-php

    A function that grows too large tends to aggregate too many responsibilities.

    Such functions inevitably become harder to understand and therefore harder to maintain.

    Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

    Those smaller functions will not only be easier to understand, but also probably easier to test.

    The class Routes has a coupling between objects value of 26. Consider to reduce the number of dependencies under 13.
    Open

    class Routes
    {
        public static function load(Application $app): void
        {
            $app->middleware([Utf8Url::class, Auth::class]);
    Severity: Minor
    Found in application/inc/Routes.php by phpmd

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

    Define a constant instead of duplicating this literal "/admin/users/(\d+)/" 3 times.
    Open

            $app->addRoute('GET', '/admin/users/(\d+)/', UserController::class, 'editUser');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/addressbook/(\d+)/" 3 times.
    Open

            $app->addRoute('GET', '/admin/addressbook/(\d+)/', AddressbookController::class, 'editContact');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "update" 9 times.
    Open

            $app->addRoute('PUT', '/admin/categories/([-\d]+)/', CategoryController::class, 'update');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/explorer/files/(\d+)/" 3 times.
    Open

            $app->addRoute('GET', '/admin/explorer/files/(\d+)/', ExplorerController::class, 'fileView');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "address" 3 times.
    Open

            $app->addRoute('GET', '/ajax/address/([0-9+\s]+)', Ajax::class, 'address');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "index" 19 times.
    Open

            $app->addRoute('GET', '/search/', Search::class, 'index');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/brands/(\d+)/" 3 times.
    Open

            $app->addRoute('GET', '/admin/brands/(\d+)/', BrandController::class, 'editPage');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "delete" 6 times.
    Open

            $app->addRoute('DELETE', '/admin/page/(\d+)/', PageController::class, 'delete');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/requirement/(\d+)/" 3 times.
    Open

            $app->addRoute('GET', '/admin/requirement/(\d+)/', RequirementController::class, 'editPage');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/page/(\d+)/" 3 times.
    Open

            $app->addRoute('GET', '/admin/page/(\d+)/', PageController::class, 'index');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "create" 9 times.
    Open

            $app->addRoute('POST', '/admin/tables/', TableController::class, 'create');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/invoices/payments/(\d+)/" 3 times.
    Open

            $app->addRoute('POST', '/admin/invoices/payments/(\d+)/', InvoiceController::class, 'capturePayment');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/explorer/folders/" 4 times.
    Open

            $app->addRoute('POST', '/admin/explorer/folders/', ExplorerController::class, 'folderCreate');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "editPage" 3 times.
    Open

            $app->addRoute('GET', '/admin/requirement/', RequirementController::class, 'editPage');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "DELETE" 14 times.
    Open

            $app->addRoute('DELETE', '/admin/page/(\d+)/categories/([-\d]+)/', PageController::class, 'removeFromCategory');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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 "/admin/explorer/files/(\d+)/image/" 3 times.
    Open

            $app->addRoute('POST', '/admin/explorer/files/(\d+)/image/', ExplorerController::class, 'imageSaveThumb');
    Severity: Critical
    Found in application/inc/Routes.php by sonar-php

    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.

    Line exceeds 120 characters; contains 127 characters
    Open

            $app->addRoute('DELETE', '/admin/maintenance/files/missing/', MaintenanceController::class, 'removeNoneExistingFiles');
    Severity: Minor
    Found in application/inc/Routes.php by phpcodesniffer

    Line exceeds 120 characters; contains 122 characters
    Open

            $app->addRoute('DELETE', '/admin/maintenance/contacts/empty/', MaintenanceController::class, 'removeBadContacts');
    Severity: Minor
    Found in application/inc/Routes.php by phpcodesniffer

    Line exceeds 120 characters; contains 122 characters
    Open

            $app->addRoute('GET', '/admin/maintenance/pages/mismatches/', MaintenanceController::class, 'mismatchedBindings');
    Severity: Minor
    Found in application/inc/Routes.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status