SU-SWS/stanford_fields

View on GitHub
src/Service/StanfordFieldsBookManager.php

Summary

Maintainability
A
0 mins
Test Coverage
A
92%

The class StanfordFieldsBookManager has 18 public methods. Consider refactoring StanfordFieldsBookManager to keep number of public methods under 10.
Wontfix

class StanfordFieldsBookManager implements BookManagerInterface {

  use StringTranslationTrait;

  /**

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

StanfordFieldsBookManager has 27 functions (exceeds 25 allowed). Consider refactoring.
Wontfix

class StanfordFieldsBookManager implements BookManagerInterface {

  use StringTranslationTrait;

  /**
Severity: Minor
Found in src/Service/StanfordFieldsBookManager.php - About 2 hrs to fix

    Method addFormElements has 70 lines of code (exceeds 40 allowed). Consider refactoring.
    Wontfix

      public function addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE) {
        // The book module will add the book settings to all node types for admins,
        // which makes it annoying. This checks the node against the settings
        // instead of only the 'administer book outlines' permission.
        // @see book_form_node_form_alter()
    Severity: Major
    Found in src/Service/StanfordFieldsBookManager.php - About 2 hrs to fix

      Function updateOutline has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
      Wontfix

        public function updateOutline(NodeInterface $node) {
          if (isset($node->book['weight'])) {
      
            // Before saving the node, look at the book weight data . The weight has
            // to be an integer, but we also have to adjust the weights of the sibling
      Severity: Minor
      Found in src/Service/StanfordFieldsBookManager.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

      The method addFormElements() has 102 lines of code. Current threshold is set to 100. Avoid really long methods.
      Wontfix

        public function addFormElements(array $form, FormStateInterface $form_state, NodeInterface $node, AccountInterface $account, $collapsed = TRUE) {
          // The book module will add the book settings to all node types for admins,
          // which makes it annoying. This checks the node against the settings
          // instead of only the 'administer book outlines' permission.
          // @see book_form_node_form_alter()

      syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)
      Invalid

        public function __construct(protected BookManagerInterface $bookManager, protected ConfigFactoryInterface $configFactory, protected EventDispatcherInterface $eventDispatcher, protected EntityTypeManagerInterface $entityTypeManager) {
      Severity: Critical
      Found in src/Service/StanfordFieldsBookManager.php by phan

      Expected 1 space after "|"; 0 found
      Invalid

        protected function getSiblingBookItems(int $parent_id, int|string $current_nid): array {

      Variable $nid is undefined.
      Invalid

                $weights[$nid] = $weight;

      Variable $nid is undefined.
      Invalid

                [, $nid] = explode(':', $key);

      Expected 1 space before "|"; 0 found
      Invalid

        protected function getSiblingBookItems(int $parent_id, int|string $current_nid): array {

      There are no issues that match your filters.

      Category
      Status