VSVverkeerskunde/gvq-api

View on GitHub
src/Company/Controllers/CompanyViewController.php

Summary

Maintainability
A
3 hrs
Test Coverage

Method edit has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function edit(Request $request, string $id): Response
    {
        $companies = $this->getCompaniesForUser();

        $company = $this->getActiveCompany($companies, $id);
Severity: Minor
Found in src/Company/Controllers/CompanyViewController.php - About 1 hr to fix

    Method add has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function add(Request $request): Response
        {
            $form = $this->createCompanyForm(null, $request->getLocale() == 'nl');
            $form->handleRequest($request);
    
    
    Severity: Minor
    Found in src/Company/Controllers/CompanyViewController.php - About 1 hr to fix

      Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              UuidFactoryInterface $uuidFactory,
              UserRepository $userRepository,
              CompanyRepository $companyRepository,
              SerializerInterface $serializer,
              TranslatorInterface $translator,
      Severity: Minor
      Found in src/Company/Controllers/CompanyViewController.php - About 45 mins to fix

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

        class CompanyViewController extends CompanyAwareController
        {
            /**
             * @var UuidFactoryInterface
             */

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

                    return $this->redirectToRoute('companies_view_index');

        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.

        Avoid variables with short names like $id. Configured minimum length is 3.
        Open

            public function edit(Request $request, string $id): Response

        ShortVariable

        Since: 0.2

        Detects when a field, local, or parameter has a very short name.

        Example

        class Something {
            private $q = 15; // VIOLATION - Field
            public static function main( array $as ) { // VIOLATION - Formal
                $r = 20 + $this->q; // VIOLATION - Local
                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                    $r += $this->q;
                }
            }
        }

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

        Opening brace should be on a new line
        Open

            public function listAsJson(Request $request) {

        There are no issues that match your filters.

        Category
        Status