VSVverkeerskunde/gvq-api

View on GitHub
src/Contest/Controllers/ContestViewController.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method contest has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function contest(Request $request, string $quizId): Response
    {
        try {
            $quiz = $this->quizRepository->getById(Uuid::fromString($quizId));

Severity: Major
Found in src/Contest/Controllers/ContestViewController.php - About 2 hrs to fix

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

            Year $year,
            ContestService $contestService,
            UuidFactoryInterface $uuidFactory,
            QuizRepository $quizRepository,
            TieBreakerRepository $tieBreakerRepository,
    Severity: Major
    Found in src/Contest/Controllers/ContestViewController.php - About 1 hr to fix

      Function contest has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public function contest(Request $request, string $quizId): Response
          {
              try {
                  $quiz = $this->quizRepository->getById(Uuid::fromString($quizId));
      
      
      Severity: Minor
      Found in src/Contest/Controllers/ContestViewController.php - About 55 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

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

          private function getTieBreakerByLocaleAndChannel(string $locale, QuizChannel $channel): array
          {
              if (!$channel->equals(new QuizChannel(QuizChannel::LEAGUE))) {
                  $channel = new QuizChannel(QuizChannel::INDIVIDUAL);
              }
      Severity: Minor
      Found in src/Contest/Controllers/ContestViewController.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

      Avoid too many return statements within this method.
      Open

              return $this->render(
                  'contest/contest.html.twig',
                  [
                      'score' => $score,
                      'totalQuestions' => $totalQuestions,
      Severity: Major
      Found in src/Contest/Controllers/ContestViewController.php - About 30 mins to fix

        The method __construct has 10 parameters. Consider reducing the number of parameters to less than 10.
        Open

            public function __construct(
                Year $year,
                ContestService $contestService,
                UuidFactoryInterface $uuidFactory,
                QuizRepository $quizRepository,

        This function has 10 parameters, which is greater than the 7 authorized.
        Open

            public function __construct(
                Year $year,
                ContestService $contestService,
                UuidFactoryInterface $uuidFactory,
                QuizRepository $quizRepository,

        A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

        Noncompliant Code Example

        With a maximum number of 4 parameters:

        function doSomething($param1, $param2, $param3, $param4, $param5) {
        ...
        }
        

        Compliant Solution

        function doSomething($param1, $param2, $param3, $param4) {
        ...
        }
        

        Reduce the number of returns of this function 5, down to the maximum allowed 3.
        Open

            public function contest(Request $request, string $quizId): Response

        Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

        Noncompliant Code Example

        With the default threshold of 3:

        function myFunction(){ // Noncompliant as there are 4 return statements
          if (condition1) {
            return true;
          } else {
            if (condition2) {
              return false;
            } else {
              return true;
            }
          }
          return false;
        }
        

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

        class ContestViewController extends AbstractController
        {
            /**
             * @var Year
             */

        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

        Missing class import via use statement (line '237', column '20').
        Open

                $now = new \DateTime();

        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 '218', column '20').
        Open

                $now = new \DateTime();

        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 '\Ramsey\Uuid\Uuid' in method 'contest'.
        Open

                        Uuid::fromString($quizId)

        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 '\Ramsey\Uuid\Uuid' in method 'contest'.
        Open

                if ($this->contestService->hasParticipatedBefore($this->year, Uuid::fromString($quizId))) {

        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 '\Ramsey\Uuid\Uuid' in method 'contest'.
        Open

                    Uuid::fromString($quizId)

        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 '\Ramsey\Uuid\Uuid' in method 'exportCupTeam'.
        Open

                $teamId = Uuid::fromString($teamId);

        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 '\Ramsey\Uuid\Uuid' in method 'contest'.
        Open

                    $quiz = $this->quizRepository->getById(Uuid::fromString($quizId));

        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 contest() contains an exit expression.
        Open

                    exit;

        ExitExpression

        Since: 0.2

        An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.

        Example

        class Foo {
            public function bar($param)  {
                if ($param === 42) {
                    exit(23);
                }
            }
        }

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

        Avoid excessively long variable names like $questionResultRepository. Keep variable name length under 20.
        Open

                QuestionResultRepository $questionResultRepository

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Avoid excessively long variable names like $questionResultRepository. Keep variable name length under 20.
        Open

            private $questionResultRepository;

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Empty lines are not allowed in multi-line function calls
        Open

        
        

        The variable $privacy_pdf is not named in camelCase.
        Open

            public function contest(Request $request, string $quizId): Response
            {
                try {
                    $quiz = $this->quizRepository->getById(Uuid::fromString($quizId));
        
        

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $privacy_pdf is not named in camelCase.
        Open

            public function contest(Request $request, string $quizId): Response
            {
                try {
                    $quiz = $this->quizRepository->getById(Uuid::fromString($quizId));
        
        

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        There are no issues that match your filters.

        Category
        Status