SU-SWS/stanford_fields

View on GitHub
src/Plugin/Field/FieldWidget/LocalistUrlWidget.php

Summary

Maintainability
A
0 mins
Test Coverage
A
98%

File LocalistUrlWidget.php has 288 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

<?php

namespace Drupal\stanford_fields\Plugin\Field\FieldWidget;

use Drupal\Component\Utility\NestedArray;
Severity: Minor
Found in src/Plugin/Field/FieldWidget/LocalistUrlWidget.php - About 2 hrs to fix

    Method formElement has 41 lines of code (exceeds 40 allowed). Consider refactoring.
    Wontfix

      public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
        $element = parent::formElement($items, $delta, $element, $form, $form_state);
        // Fallback to inherited link widget if the base_url is not set.
        if (!$this->getSetting('base_url')) {
          return $element;
    Severity: Minor
    Found in src/Plugin/Field/FieldWidget/LocalistUrlWidget.php - About 1 hr to fix

      Function massageFormValues has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
      Wontfix

        public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
          if (!$this->getSetting('base_url')) {
            return parent::massageFormValues($values, $form, $form_state);
          }
      
      
      Severity: Minor
      Found in src/Plugin/Field/FieldWidget/LocalistUrlWidget.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

      The class LocalistUrlWidget has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
      Wontfix

      class LocalistUrlWidget extends LinkWidget {
      
        /**
         * Http Client Service.
         *

      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

      Avoid assigning values to variables in if clauses and the like (line '356', column '9').
      Invalid

        protected function getApiData() {
          // Data was already fetched.
          if ($this->apiData) {
            return $this->apiData;
          }

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

      Suspicious array access to \Drupal\Core\Field\FieldItemListInterface
      Wontfix

          $item = $items[$delta];

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must end with a full stop
      Wontfix

         * {@inheritDoc}

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      Doc comment short description must start with a capital letter
      Wontfix

         * {@inheritDoc}

      There are no issues that match your filters.

      Category
      Status