NatLibFi/Skosmos

View on GitHub
src/controller/WebController.php

Summary

Maintainability
D
2 days
Test Coverage
F
19%

File WebController.php has 381 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * Importing the dependencies.
 */
Severity: Minor
Found in src/controller/WebController.php - About 5 hrs to fix

    The class WebController has an overall complexity of 63 which is very high. The configured complexity threshold is 50.
    Open

    class WebController extends Controller
    {
        /**
         * Provides access to the templating engine.
         * @property object $twig the twig templating engine.
    Severity: Minor
    Found in src/controller/WebController.php by phpmd

    The class WebController has 11 public methods. Consider refactoring WebController to keep number of public methods under 10.
    Open

    class WebController extends Controller
    {
        /**
         * Provides access to the templating engine.
         * @property object $twig the twig templating engine.
    Severity: Minor
    Found in src/controller/WebController.php by phpmd

    TooManyPublicMethods

    Since: 0.1

    A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

    By default it ignores methods starting with 'get' or 'set'.

    Example

    Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

    Method invokeVocabularySearch has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function invokeVocabularySearch($request)
        {
            $template = $this->twig->load('vocab-search.twig');
            $this->model->setLocale($request->getLang());
            $vocab = $request->getVocab();
    Severity: Major
    Found in src/controller/WebController.php - About 2 hrs to fix

      Method invokeGlobalSearch has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function invokeGlobalSearch($request)
          {
              $lang = $request->getLang();
              $template = $this->twig->load('global-search.twig');
              $this->model->setLocale($request->getLang());
      Severity: Major
      Found in src/controller/WebController.php - About 2 hrs to fix

        Function invokeGlobalSearch has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function invokeGlobalSearch($request)
            {
                $lang = $request->getLang();
                $template = $this->twig->load('global-search.twig');
                $this->model->setLocale($request->getLang());
        Severity: Minor
        Found in src/controller/WebController.php - About 1 hr 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 sendFeedback has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function sendFeedback($request, $message, $messageSubject, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null)
            {
                $toAddress = ($toMail) ? $toMail : $this->model->getConfig()->getFeedbackAddress();
                $messageSubject = "[" . $this->model->getConfig()->getServiceName() . "] " . $messageSubject;
                if ($fromVocab !== null && $fromVocab !== '') {
        Severity: Minor
        Found in src/controller/WebController.php - About 1 hr to fix

          Method invokeVocabularyConcept has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function invokeVocabularyConcept(Request $request)
              {
                  $lang = $request->getLang();
                  $this->model->setLocale($request->getLang());
                  $vocab = $request->getVocab();
          Severity: Minor
          Found in src/controller/WebController.php - About 1 hr to fix

            Method invokeFeedbackForm has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function invokeFeedbackForm($request)
                {
                    $template = $this->twig->load('feedback.twig');
                    $this->model->setLocale($request->getLang());
                    $vocabList = $this->model->getVocabularyList(false);
            Severity: Minor
            Found in src/controller/WebController.php - About 1 hr to fix

              Method sendFeedback has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function sendFeedback($request, $message, $messageSubject, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null)
              Severity: Major
              Found in src/controller/WebController.php - About 50 mins to fix

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

                    public function sendFeedback($request, $message, $messageSubject, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null)
                    {
                        $toAddress = ($toMail) ? $toMail : $this->model->getConfig()->getFeedbackAddress();
                        $messageSubject = "[" . $this->model->getConfig()->getServiceName() . "] " . $messageSubject;
                        if ($fromVocab !== null && $fromVocab !== '') {
                Severity: Minor
                Found in src/controller/WebController.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

                Function guessLanguage has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function guessLanguage($request, $vocid = null)
                    {
                        // 1. select language based on SKOSMOS_LANGUAGE cookie
                        $languageCookie = $request->getCookie('SKOSMOS_LANGUAGE');
                        if ($languageCookie) {
                Severity: Minor
                Found in src/controller/WebController.php - About 35 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 invokeVocabularySearch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function invokeVocabularySearch($request)
                    {
                        $template = $this->twig->load('vocab-search.twig');
                        $this->model->setLocale($request->getLang());
                        $vocab = $request->getVocab();
                Severity: Minor
                Found in src/controller/WebController.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 sendFeedback() has an NPath complexity of 288. The configured NPath complexity threshold is 200.
                Open

                    public function sendFeedback($request, $message, $messageSubject, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null)
                    {
                        $toAddress = ($toMail) ? $toMail : $this->model->getConfig()->getFeedbackAddress();
                        $messageSubject = "[" . $this->model->getConfig()->getServiceName() . "] " . $messageSubject;
                        if ($fromVocab !== null && $fromVocab !== '') {
                Severity: Minor
                Found in src/controller/WebController.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 sendFeedback() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                Open

                    public function sendFeedback($request, $message, $messageSubject, $fromName = null, $fromEmail = null, $fromVocab = null, $toMail = null)
                    {
                        $toAddress = ($toMail) ? $toMail : $this->model->getConfig()->getFeedbackAddress();
                        $messageSubject = "[" . $this->model->getConfig()->getServiceName() . "] " . $messageSubject;
                        if ($fromVocab !== null && $fromVocab !== '') {
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '428', column '27').
                Open

                        $parameters = new ConceptSearchParameters($request, $this->model->getConfig());
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '56', column '27').
                Open

                        $langFilter = new \Twig\TwigFilter('lang_name', function ($langcode, $lang) {
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '53', column '39').
                Open

                        $this->twig->addExtension(new LinkUrlExtension($model));
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '42', column '27').
                Open

                        $this->twig = new \Twig\Environment($loader, array('cache' => $tmpDir,'auto_reload' => true));
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '65', column '31').
                Open

                        $this->honeypot = new \Honeypot();
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '337', column '27').
                Open

                        $parameters = new ConceptSearchParameters($request, $this->model->getConfig());
                Severity: Minor
                Found in src/controller/WebController.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

                Missing class import via use statement (line '99', column '33').
                Open

                        $this->negotiator = new \Negotiation\LanguageNegotiator();
                Severity: Minor
                Found in src/controller/WebController.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

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

                        $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../view');
                Severity: Minor
                Found in src/controller/WebController.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 '\Punic\Language' in method '__construct'.
                Open

                            return Language::getName($langcode, $lang);
                Severity: Minor
                Found in src/controller/WebController.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 unused local variables such as '$lang'.
                Open

                        $lang = $request->getLang();
                Severity: Minor
                Found in src/controller/WebController.php by phpmd

                UnusedLocalVariable

                Since: 0.2

                Detects when a local variable is declared and/or assigned, but not used.

                Example

                class Foo {
                    public function doSomething()
                    {
                        $i = 5; // Unused
                    }
                }

                Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

                Avoid unused local variables such as '$lang'.
                Open

                        $lang = $request->getLang();
                Severity: Minor
                Found in src/controller/WebController.php by phpmd

                UnusedLocalVariable

                Since: 0.2

                Detects when a local variable is declared and/or assigned, but not used.

                Example

                class Foo {
                    public function doSomething()
                    {
                        $i = 5; // Unused
                    }
                }

                Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

                There are no issues that match your filters.

                Category
                Status