prismicio/php-kit

View on GitHub
src/Prismic/Dom/RichText.php

Summary

Maintainability
F
3 days
Test Coverage

Function insertSpans has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    private static function insertSpans($text, array $spans, $linkResolver = null, $htmlSerializer = null)
    {
        if (empty($spans)) {
            return htmlentities($text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
        }
Severity: Minor
Found in src/Prismic/Dom/RichText.php - About 5 hrs 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 asHtml has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    public static function asHtml($richText, $linkResolver = null, $htmlSerializer = null)
    {
        $groups = [];

        foreach ($richText as $block) {
Severity: Minor
Found in src/Prismic/Dom/RichText.php - About 4 hrs 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 serialize has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private static function serialize($element, $content, $linkResolver, $htmlSerializer) : string
    {
        if ($htmlSerializer) {
            $custom = $htmlSerializer($element, $content);
            if ($custom) {
Severity: Major
Found in src/Prismic/Dom/RichText.php - About 3 hrs to fix

    Method insertSpans has 64 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function insertSpans($text, array $spans, $linkResolver = null, $htmlSerializer = null)
        {
            if (empty($spans)) {
                return htmlentities($text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
            }
    Severity: Major
    Found in src/Prismic/Dom/RichText.php - About 2 hrs to fix

      Function serialize has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          private static function serialize($element, $content, $linkResolver, $htmlSerializer) : string
          {
              if ($htmlSerializer) {
                  $custom = $htmlSerializer($element, $content);
                  if ($custom) {
      Severity: Minor
      Found in src/Prismic/Dom/RichText.php - About 2 hrs 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

      File RichText.php has 255 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      <?php
      
      namespace Prismic\Dom;
      
      use Prismic\Dom\BlockGroup;
      Severity: Minor
      Found in src/Prismic/Dom/RichText.php - About 2 hrs to fix

        Method asHtml has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function asHtml($richText, $linkResolver = null, $htmlSerializer = null)
            {
                $groups = [];
        
                foreach ($richText as $block) {
        Severity: Major
        Found in src/Prismic/Dom/RichText.php - About 2 hrs to fix

          Consider simplifying this complex logical expression.
          Open

                  if ($block->type === 'heading1' ||
                      $block->type === 'heading2' ||
                      $block->type === 'heading3' ||
                      $block->type === 'heading4' ||
                      $block->type === 'heading5' ||
          Severity: Critical
          Found in src/Prismic/Dom/RichText.php - About 2 hrs to fix

            Avoid too many return statements within this method.
            Open

                            return (
                                '<p class="block-img' . (isset($element->label) ? (' ' . $element->label) : '') . '">' .
                                ($link ? '<a href="' . $link . '"' . $targetCode . '>' . $img . '</a>' : $img) .
                                '</p>'
                            );
            Severity: Major
            Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return '<pre' . $classCode . '>' . $content . '</pre>';
              Severity: Major
              Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return nl2br('<p' . $classCode . '>' . $content . '</p>');
                Severity: Major
                Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return nl2br('<h6' . $classCode . '>' . $content . '</h6>');
                  Severity: Major
                  Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return nl2br('<h5' . $classCode . '>' . $content . '</h5>');
                    Severity: Major
                    Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                          return $content;
                      Severity: Major
                      Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                            return sprintf(
                                                '<div data-oembed="%s" data-oembed-type="%s"%s>%s</div>',
                                                $element->oembed->embed_url,
                                                strtolower($element->oembed->type),
                                                $providerAttr,
                        Severity: Major
                        Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return nl2br('<h4' . $classCode . '>' . $content . '</h4>');
                          Severity: Major
                          Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return $html;
                            Severity: Major
                            Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return nl2br('<li' . $classCode . '>' . $content . '</li>');
                              Severity: Major
                              Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return '';
                                Severity: Major
                                Found in src/Prismic/Dom/RichText.php - About 30 mins to fix

                                  There are no issues that match your filters.

                                  Category
                                  Status