fisharebest/localization

View on GitHub

Showing 19 of 64 total issues

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

    private function readPoFile($lines)
    {
        // Strip comments
        $lines = array_filter($lines, function ($line) {
            return strpos($line, '#') !== 0;
Severity: Minor
Found in src/Translation.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

AbstractLocale has 21 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class AbstractLocale
{
    // "Source" strings, when translating numbers
    const DECIMAL  = '.'; // The default decimal mark
    const GROUP    = ','; // The digit group separator
Severity: Minor
Found in src/Locale/AbstractLocale.php - About 2 hrs to fix

    Method readPoFile has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function readPoFile($lines)
        {
            // Strip comments
            $lines = array_filter($lines, function ($line) {
                return strpos($line, '#') !== 0;
    Severity: Minor
    Found in src/Translation.php - About 2 hrs to fix

      Function httpAcceptDowngrade has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          private static function httpAcceptDowngrade($preferences)
          {
              foreach ($preferences as $code => $priority) {
                  // Three parts: "zh-hans-cn" => "zh-hans" and "zh"
                  if (preg_match('/^(([a-z]+)-[a-z]+)-[a-z]+$/', $code, $match) === 1) {
      Severity: Minor
      Found in src/Locale.php - About 1 hr 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 __construct has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function __construct($filename)
          {
              $this->translations = array();
      
              switch (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
      Severity: Minor
      Found in src/Translation.php - About 1 hr to fix

        Function __construct has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            public function __construct($filename)
            {
                $this->translations = array();
        
                switch (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
        Severity: Minor
        Found in src/Translation.php - About 1 hr 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 httpAcceptLanguage has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function httpAcceptLanguage(array $server, array $available, LocaleInterface $default)
            {
                if (!empty($server['HTTP_ACCEPT_LANGUAGE'])) {
                    $http_accept_language = strtolower(str_replace(' ', '', $server['HTTP_ACCEPT_LANGUAGE']));
                    preg_match_all('/([a-z][a-z0-9_-]+)(?:;q=([0-9.]+))?/', $http_accept_language, $match);
        Severity: Minor
        Found in src/Locale.php - About 1 hr to fix

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

              public static function httpAcceptLanguage(array $server, array $available, LocaleInterface $default)
              {
                  if (!empty($server['HTTP_ACCEPT_LANGUAGE'])) {
                      $http_accept_language = strtolower(str_replace(' ', '', $server['HTTP_ACCEPT_LANGUAGE']));
                      preg_match_all('/([a-z][a-z0-9_-]+)(?:;q=([0-9.]+))?/', $http_accept_language, $match);
          Severity: Minor
          Found in src/Locale.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

          Function plural has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function plural($number)
              {
                  $number = abs($number);
          
                  if ($number === 1) {
          Severity: Minor
          Found in src/PluralRule/PluralRule13.php - About 35 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

          Function number has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function number($number)
              {
                  if ($number < 0) {
                      $number   = -$number;
                      $negative = self::NEGATIVE;
          Severity: Minor
          Found in src/Locale/AbstractLocale.php - About 35 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

          Avoid too many return statements within this method.
          Open

                      return 4;
          Severity: Major
          Found in src/PluralRule/PluralRule12.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return 4;
            Severity: Major
            Found in src/PluralRule/PluralRule13.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $default;
              Severity: Major
              Found in src/Locale.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return 4;
                Severity: Major
                Found in src/PluralRule/PluralRule11.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return 5;
                  Severity: Major
                  Found in src/PluralRule/PluralRule12.php - About 30 mins to fix

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

                        public function code()
                        {
                            $code   = $this->language()->code() . '_' . $this->territory()->code();
                            $script = $this->script()->unicodeName();
                    
                    
                    Severity: Minor
                    Found in src/Locale/AbstractLocale.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

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

                        public function plural($number)
                        {
                            $number = abs($number);
                    
                            if ($number === 1 || $number === 11) {
                    Severity: Minor
                    Found in src/PluralRule/PluralRule4.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

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

                        public function plural($number)
                        {
                            $number = abs($number);
                    
                            if ($number === 1) {
                    Severity: Minor
                    Found in src/PluralRule/PluralRule11.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

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

                        public function plural($number)
                        {
                            $number = abs($number);
                    
                            if ($number === 0) {
                    Severity: Minor
                    Found in src/PluralRule/PluralRule12.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

                    Severity
                    Category
                    Status
                    Source
                    Language