HuasoFoundries/jpgraph

View on GitHub
src/util/RGB.php

Summary

Maintainability
F
1 mo
Test Coverage

Showing 42 of 42 total issues

Method __construct has 443 lines of code (exceeds 25 allowed). Consider refactoring.
Open

public function __construct($aImg = null)
{
$this->img = $aImg;
 
// Conversion array between color names and RGB
Severity: Major
Found in src/util/RGB.php - About 2 days to fix

    File RGB.php has 551 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
     
    /**
    * JPGraph v4.0.3
    */
    Severity: Major
    Found in src/util/RGB.php - About 1 day to fix

      Function Color has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

      public function Color($aColor)
      {
      if (is_string($aColor)) {
      $matches = [];
      // this regex will parse a color string and fill the $matches array as such:
      Severity: Minor
      Found in src/util/RGB.php - About 2 hrs to fix

      Method Color has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      public function Color($aColor)
      {
      if (is_string($aColor)) {
      $matches = [];
      // this regex will parse a color string and fill the $matches array as such:
      Severity: Minor
      Found in src/util/RGB.php - About 1 hr to fix

        Function tryHexConversion has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        public static function tryHexConversion($aColor)
        {
        if (is_array($aColor)) {
        if (safe_count($aColor) == 3) {
        if (is_numeric($aColor[0]) && is_numeric($aColor[1]) && is_numeric($aColor[2])) {
        Severity: Minor
        Found in src/util/RGB.php - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

        if (($aColor[0] >= 0 && $aColor[0] <= 255) &&
        ($aColor[1] >= 0 && $aColor[1] <= 255) &&
        ($aColor[2] >= 0 && $aColor[2] <= 255)) {
        return sprintf('#%02x%02x%02x', $aColor[0], $aColor[1], $aColor[2]);
        }
        Severity: Major
        Found in src/util/RGB.php - About 40 mins to fix

          Avoid too many return statements within this method.
          Open

          return [$sat, round($sat - $sat * ($aVal - 0.75) / $a), 0];
          Severity: Major
          Found in src/util/RGB.php - About 30 mins to fix

            The method Color() has an NPath complexity of 1283. The configured NPath complexity threshold is 200.
            Open

            public function Color($aColor)
            {
            if (is_string($aColor)) {
            $matches = [];
            // this regex will parse a color string and fill the $matches array as such:
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            public function __construct($aImg = null)
            {
            $this->img = $aImg;
             
            // Conversion array between color names and RGB
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            The method Color() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
            Open

            public function Color($aColor)
            {
            if (is_string($aColor)) {
            $matches = [];
            // this regex will parse a color string and fill the $matches array as such:
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            The method tryHexConversion() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
            Open

            public static function tryHexConversion($aColor)
            {
            if (is_array($aColor)) {
            if (safe_count($aColor) == 3) {
            if (is_numeric($aColor[0]) && is_numeric($aColor[1]) && is_numeric($aColor[2])) {
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            } else {
            JpGraphError::RaiseL(25079, $aColor, safe_count($aColor)); //(" Unknown color specification: $aColor , size=". safe_count($aColor));
            }
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            } else {
            if (!isset($this->rgb_table[$matches[5]])) {
            JpGraphError::RaiseL(25078, $aColor); //(" Unknown color: $aColor");
            }
            $r = $this->rgb_table[$matches[5]][0];
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Avoid using static access to class 'Amenadiel\JpGraph\Util\JpGraphError' in method 'Color'.
            Open

            JpGraphError::RaiseL(25078, $aColor); //(" Unknown color: $aColor");
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Avoid using static access to class 'Amenadiel\JpGraph\Util\JpGraphError' in method 'Color'.
            Open

            JpGraphError::RaiseL(25077); //('Adjustment factor for color must be > 0');
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Avoid using static access to class 'Amenadiel\JpGraph\Util\JpGraphError' in method 'Color'.
            Open

            JpGraphError::RaiseL(25079, $aColor, safe_count($aColor)); //(" Unknown color specification: $aColor , size=". safe_count($aColor));
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Avoid using static access to class 'Amenadiel\JpGraph\Util\JpGraphError' in method 'Color'.
            Open

            JpGraphError::RaiseL(25078, $aColor); //(" Unknown color: $aColor");
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Avoid using static access to class 'Amenadiel\JpGraph\Util\JpGraphError' in method 'Allocate'.
            Open

            JpGraphError::RaiseL(25080); //('Alpha parameter for color must be between 0.0 and 1.0');
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            public function __construct($aImg = null)
            {
            $this->img = $aImg;
             
            // Conversion array between color names and RGB
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 1 mo to fix
            src/image/RGB.php on lines 30..477

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            if (empty($matches[5])) {
            $r = strlen($matches[2]) == 1 ? $matches[2] . $matches[2] : $matches[2];
            $g = strlen($matches[3]) == 1 ? $matches[3] . $matches[3] : $matches[3];
            $b = strlen($matches[4]) == 1 ? $matches[4] . $matches[4] : $matches[4];
            $r = hexdec($r);
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 1 day to fix
            src/image/RGB.php on lines 509..523

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            public static function GetSpectrum($aVal, $aDynamicRange = 1.0)
            {
            if ($aVal < 0 || $aVal > 1.0001) {
            return [0, 0, 0]; // Invalid case - just return black
            }
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 7 hrs to fix
            src/image/RGB.php on lines 618..637

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            public static function tryHexConversion($aColor)
            {
            if (is_array($aColor)) {
            if (safe_count($aColor) == 3) {
            if (is_numeric($aColor[0]) && is_numeric($aColor[1]) && is_numeric($aColor[2])) {
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 5 hrs to fix
            src/image/RGB.php on lines 594..609

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            public function Allocate($aColor, $aAlpha = 0.0)
            {
            list($r, $g, $b, $a) = $this->color($aColor);
            // If alpha is specified in the color string then this
            // takes precedence over the second argument
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 1 hr to fix
            src/image/RGB.php on lines 574..587

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            if ($adj > 1) {
            $m = ($adj - 1.0) * (255 - min(255, min($r, min($g, $b))));
             
            return [min(255, $r + $m), min(255, $g + $m), min(255, $b + $m), $alpha];
            }
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 1 hr to fix
            src/image/RGB.php on lines 541..545

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

            if ($adj < 1) {
            $m = ($adj - 1.0) * max(255, max($r, max($g, $b)));
             
            return [max(0, $r + $m), max(0, $g + $m), max(0, $b + $m), $alpha];
            }
            Severity: Major
            Found in src/util/RGB.php and 1 other location - About 1 hr to fix
            src/image/RGB.php on lines 546..550

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

            $c1 = $this->Color($aCol1);
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            $m = ($adj - 1.0) * (255 - min(255, min($r, min($g, $b))));
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            $c2 = $this->Color($aCol2);
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            $g = strlen($matches[3]) == 1 ? $matches[3] . $matches[3] : $matches[3];
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            list($r, $g, $b, $a) = $this->color($aColor);
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            $a = 0.25;
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            $r = strlen($matches[2]) == 1 ? $matches[2] . $matches[2] : $matches[2];
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            list($r, $g, $b, $a) = $this->color($aColor);
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            list($r, $g, $b, $a) = $this->color($aColor);
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            list($r, $g, $b, $a) = $this->color($aColor);
            Severity: Minor
            Found in src/util/RGB.php by phpmd

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

            $b = strlen($matches[4]) == 1 ? $matches[4] . $matches[4] : $matches[4];
            Severity: Minor
            Found in src/util/RGB.php by phpmd

            Method name "RGB::GetSpectrum" is not in camel caps format
            Open

            public static function GetSpectrum($aVal, $aDynamicRange = 1.0)
            Severity: Minor
            Found in src/util/RGB.php by phpcodesniffer

            Method name "RGB::Color" is not in camel caps format
            Open

            public function Color($aColor)
            Severity: Minor
            Found in src/util/RGB.php by phpcodesniffer

            Method name "RGB::Allocate" is not in camel caps format
            Open

            public function Allocate($aColor, $aAlpha = 0.0)
            Severity: Minor
            Found in src/util/RGB.php by phpcodesniffer

            Method name "RGB::Equal" is not in camel caps format
            Open

            public function Equal($aCol1, $aCol2)
            Severity: Minor
            Found in src/util/RGB.php by phpcodesniffer

            Line exceeds 120 characters; contains 144 characters
            Open

            JpGraphError::RaiseL(25079, $aColor, safe_count($aColor)); //(" Unknown color specification: $aColor , size=". safe_count($aColor));
            Severity: Minor
            Found in src/util/RGB.php by phpcodesniffer

            Line exceeds 120 characters; contains 122 characters
            Open

            // 1: a hex string preceded by a hash, can be 3 characters (#fff) or 6 (#ffffff) (4 or 5 also accepted but...)
            Severity: Minor
            Found in src/util/RGB.php by phpcodesniffer

            There are no issues that match your filters.

            Category
            Status