kpumuk/codecolorer

View on GitHub

Showing 289 of 289 total issues

Method addContainer has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function addContainer($html, $options, $numLines)
    {
        $customCSSClass = empty($options['class']) ? '' : ' ' . $options['class'];
        if ($options['inline']) {
            $theme = empty($options['inline_theme']) ? 'default' : $options['inline_theme'];
Severity: Minor
Found in codecolorer-core.php - About 1 hr to fix

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class CodeColorer
    Severity: Minor
    Found in codecolorer-core.php by phpcodesniffer

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class CodeColorerOptions
    Severity: Minor
    Found in codecolorer-options.php by phpcodesniffer

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class CodeColorerAdmin
    Severity: Minor
    Found in codecolorer-admin.php by phpcodesniffer

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class CodeColorerLoader
    Severity: Minor
    Found in codecolorer.php by phpcodesniffer

    Function parseOptions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function parseOptions($opts, $suffix = '')
        {
            $opts = str_replace(array("\\\"", "\\\'"), array ("\"", "\'"), $opts);
            preg_match_all('#([a-z_-]*?)\s*=\s*(["\'])(.*?)\2#i', $opts, $matches, PREG_SET_ORDER);
            $options = array();
    Severity: Minor
    Found in codecolorer-options.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

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 36 and the first side effect is on line 33.
    Open

    <?php
    Severity: Minor
    Found in codecolorer.php by phpcodesniffer

    Avoid variables with short names like $to. Configured minimum length is 3.
    Open

                    list($from, $to) = array_pad(explode('-', $v, 2), 2, null);
    Severity: Minor
    Found in codecolorer-core.php by phpmd

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

    Method performHighlightCodeBlock has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        private function performHighlightCodeBlock($text, $opts, $content, $suffix = '', $before = '', $after = '')
    Severity: Minor
    Found in codecolorer-core.php - About 45 mins to fix

      Missing class import via use statement (line '217', column '32').
      Open

                  $this->geshi = new GeSHi();
      Severity: Minor
      Found in codecolorer-core.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 '376', column '38').
      Open

                  $this->optionsPage = new CodeColorerAdmin($this);
      Severity: Minor
      Found in codecolorer-core.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

      The method getBlockID has a boolean flag argument $comment, which is a certain sign of a Single Responsibility Principle violation.
      Open

          private function getBlockID($content, $comment = false, $before = '<div>', $after = '</div>')
      Severity: Minor
      Found in codecolorer-core.php by phpmd

      BooleanArgumentFlag

      Since: 1.4.0

      A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

      Example

      class Foo {
          public function bar($flag = true) {
          }
      }

      Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

      Missing class import via use statement (line '405', column '29').
      Open

                  $instance = new CodeColorer();
      Severity: Minor
      Found in codecolorer-core.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

      Function getOptionsPage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          private function getOptionsPage()
          {
              if (!$this->optionsPage) {
                  if (!class_exists('CodeColorerAdmin')) {
                      $path = dirname(__FILE__);
      Severity: Minor
      Found in codecolorer-core.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 getInstance uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $instance->geshiExternal = true;
                  }
      Severity: Minor
      Found in codecolorer-core.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      Avoid using static access to class 'CodeColorer' in method 'callBeforeProtectComment'.
      Open

              $codecolorer = &CodeColorer::getInstance();
      Severity: Minor
      Found in codecolorer.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

      The method performHighlightGeshi uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      $table .= 'class="line-numbers"';
                  }
      Severity: Minor
      Found in codecolorer-core.php by phpmd

      ElseExpression

      Since: 1.4.0

      An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($flag) {
                  // one branch
              } else {
                  // another branch
              }
          }
      }

      Source https://phpmd.org/rules/cleancode.html#elseexpression

      The method populateDefaultValues() has 128 lines of code. Current threshold is set to 100. Avoid really long methods.
      Open

          protected static function populateDefaultValues($options)
          {
              if (!$options) {
                  $options = array();
              }
      Severity: Minor
      Found in codecolorer-options.php by phpmd

      Avoid using static access to class 'CodeColorerOptions' in method 'performHighlightGeshi'.
      Open

                      $table .= 'style="' . CodeColorerOptions::feedLineNumbersStyle() . '"';
      Severity: Minor
      Found in codecolorer-core.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

      The method show() has 125 lines of code. Current threshold is set to 100. Avoid really long methods.
      Open

          public function show()
          {
              ?>
      
              <div class="wrap">
      Severity: Minor
      Found in codecolorer-admin.php by phpmd
      Severity
      Category
      Status
      Source
      Language