src/Service/StanfordFieldsBookManager.php
The class StanfordFieldsBookManager has 18 public methods. Consider refactoring StanfordFieldsBookManager to keep number of public methods under 10. Wontfix
Wontfix
class StanfordFieldsBookManager implements BookManagerInterface {
use StringTranslationTrait;
/**
- Read upRead up
- Exclude checks
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
Wontfix
class StanfordFieldsBookManager implements BookManagerInterface {
use StringTranslationTrait;
/**
Method addFormElements
has 70 lines of code (exceeds 40 allowed). Consider refactoring. Wontfix
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()
Function updateOutline
has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring. Wontfix
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
- Read upRead up
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
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()
- Exclude checks
syntax error, unexpected 'protected' (T_PROTECTED), expecting variable (T_VARIABLE)
Invalid
Invalid
public function __construct(protected BookManagerInterface $bookManager, protected ConfigFactoryInterface $configFactory, protected EventDispatcherInterface $eventDispatcher, protected EntityTypeManagerInterface $entityTypeManager) {
- Exclude checks
Expected 1 space after "|"; 0 found Invalid
Invalid
protected function getSiblingBookItems(int $parent_id, int|string $current_nid): array {
- Exclude checks
Variable $nid is undefined. Invalid
Invalid
$weights[$nid] = $weight;
- Exclude checks
Variable $nid is undefined. Invalid
Invalid
[, $nid] = explode(':', $key);
- Exclude checks
Expected 1 space before "|"; 0 found Invalid
Invalid
protected function getSiblingBookItems(int $parent_id, int|string $current_nid): array {
- Exclude checks