yiisoft/yii2

View on GitHub
framework/i18n/Formatter.php

Summary

Maintainability
F
1 wk
Test Coverage

Function asDecimalStringFallback has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

    protected function asDecimalStringFallback($value, $decimals = 2)
    {
        if (empty($value)) {
            $value = 0;
        }
Severity: Minor
Found in framework/i18n/Formatter.php - About 7 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 asRelativeTime has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    public function asRelativeTime($value, $referenceTime = null)
    {
        if ($value === null) {
            return $this->nullDisplay;
        }
Severity: Minor
Found in framework/i18n/Formatter.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

Function formatDateTimeValue has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

    private function formatDateTimeValue($value, $format, $type)
    {
        $timeZone = $this->timeZone;
        // avoid time zone conversion for date-only and time-only values
        if ($type === 'date' || $type === 'time') {
Severity: Minor
Found in framework/i18n/Formatter.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

The class Formatter has 30 public methods. Consider refactoring Formatter to keep number of public methods under 10.
Open

class Formatter extends Component
{
    /**
     * @since 2.0.13
     */
Severity: Minor
Found in framework/i18n/Formatter.php by phpmd

Since: PHPMD 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'.

Source: http://phpmd.org/rules/codesize.txt

The class Formatter has 42 non-getter- and setter-methods. Consider refactoring Formatter to keep number of methods under 25.
Open

class Formatter extends Component
{
    /**
     * @since 2.0.13
     */
Severity: Minor
Found in framework/i18n/Formatter.php by phpmd

Since: PHPMD 0.1

A class with too many 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'. The default was changed from 10 to 25 in PHPMD 2.3.

Source: http://phpmd.org/rules/codesize.txt

The class Formatter has an overall complexity of 273 which is very high. The configured complexity threshold is 50.
Open

class Formatter extends Component
{
    /**
     * @since 2.0.13
     */
Severity: Minor
Found in framework/i18n/Formatter.php by phpmd

Since: PHPMD 0.2.5

The Weighted Method Count (WMC) of a class is a good indicator of how much time and effort is required to modify and maintain this class. The WMC metric is defined as the sum of complexities of all methods declared in a class. A large number of methods also means that this class has a greater potential impact on derived classes.

Example:

class Foo {
      public function bar() {
          if ($a == $b)  {
              if ($a1 == $b1) {
                  fiddle();
              } elseif ($a2 == $b2) {
                  fiddle();
              } else {
              }
          }
      }
      public function baz() {
          if ($a == $b) {
              if ($a1 == $b1) {
                  fiddle();
              } elseif ($a2 == $b2) {
                  fiddle();
              } else {
              }
          }
      }
      // Several other complex methods
  }

Source: http://phpmd.org/rules/codesize.txt

Function formatNumber has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    private function formatNumber($value, $decimals, $maxPosition, $formatBase, $options, $textOptions)
    {
        $value = $this->normalizeNumericValue($value);

        $position = 0;
Severity: Minor
Found in framework/i18n/Formatter.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

Function asCurrency has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function asCurrency($value, $currency = null, $options = [], $textOptions = [])
    {
        if ($value === null) {
            return $this->nullDisplay;
        }
Severity: Minor
Found in framework/i18n/Formatter.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

Function asDuration has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function asDuration($value, $implodeString = ', ', $negativeSign = '-')
    {
        if ($value === null) {
            return $this->nullDisplay;
        }
Severity: Minor
Found in framework/i18n/Formatter.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

The class Formatter has 24 fields. Consider redesigning Formatter to keep the number of fields under 15.
Open

class Formatter extends Component
{
    /**
     * @since 2.0.13
     */
Severity: Minor
Found in framework/i18n/Formatter.php by phpmd

Since: PHPMD 0.1

Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

Example:

class Person {
     protected $one;
     private $two;
     private $three;
     [... many more fields ...]
  }

Source: http://phpmd.org/rules/codesize.txt

The class Formatter has 50 public methods and attributes. Consider reducing the number of public items to less than 45.
Open

class Formatter extends Component
{
    /**
     * @since 2.0.13
     */
Severity: Minor
Found in framework/i18n/Formatter.php by phpmd

Since: PHPMD 0.1

A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.

Example:

public class Foo {
      public $value;
      public $something;
      public $var;
      // [... more more public attributes ...]

      public function doWork() {}
      public function doMoreWork() {}
      public function doWorkAgain() {}
      // [... more more public methods ...]
  }

Source: http://phpmd.org/rules/codesize.txt

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

    private function getUnitMessage($unitType, $unitFormat, $system, $position)
    {
        if (isset($this->_unitMessages[$unitType][$system][$position])) {
            return $this->_unitMessages[$unitType][$system][$position];
        }
Severity: Minor
Found in framework/i18n/Formatter.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

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

    public function init()
    {
        if ($this->timeZone === null) {
            $this->timeZone = Yii::$app->timeZone;
        }
Severity: Minor
Found in framework/i18n/Formatter.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

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

    protected function normalizeNumericStringValue($value)
    {
        $powerPosition = strrpos($value, 'E');
        if ($powerPosition !== false) {
            $valuePart = substr($value, 0, $powerPosition);
Severity: Minor
Found in framework/i18n/Formatter.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 formatUnit has 8 arguments (exceeds 4 allowed). Consider refactoring.
Open

    private function formatUnit($unitType, $unitFormat, $value, $baseUnit, $unitSystem, $decimals, $options, $textOptions)
Severity: Major
Found in framework/i18n/Formatter.php - About 1 hr to fix

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

        protected function normalizeDatetimeValue($value, $checkDateTimeInfo = false)
        {
            // checking for DateTime and DateTimeInterface is not redundant, DateTimeInterface is only in PHP>5.5
            if ($value === null || $value instanceof DateTime || $value instanceof DateTimeInterface) {
                // skip any processing
    Severity: Minor
    Found in framework/i18n/Formatter.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

    Avoid deeply nested control flow statements.
    Open

                            if ($oneUp === 10) {
                                $oneUp = 0;
                                $carry = 1;
                            }
    Severity: Major
    Found in framework/i18n/Formatter.php - About 45 mins to fix

      Function createNumberFormatter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
          {
              $formatter = new NumberFormatter($this->locale, $style);
      
              // set text attributes
      Severity: Minor
      Found in framework/i18n/Formatter.php - About 45 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

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

          private function formatNumber($value, $decimals, $maxPosition, $formatBase, $options, $textOptions)
      Severity: Minor
      Found in framework/i18n/Formatter.php - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if ($carry === 0) {
                                    break;
                                }
        Severity: Major
        Found in framework/i18n/Formatter.php - About 45 mins to fix

          Consider simplifying this complex logical expression.
          Open

                      if ($checkDateTimeInfo) {
                          $timestamp = new DateTime($value, new DateTimeZone($this->defaultTimeZone));
                          $info = date_parse($value);
                          return [
                              $timestamp,
          Severity: Major
          Found in framework/i18n/Formatter.php - About 40 mins to fix

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

                protected function asPercentStringFallback($value, $decimals = null)
                {
                    if (empty($value)) {
                        $value = 0;
                    }
            Severity: Minor
            Found in framework/i18n/Formatter.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 Yii::t('yii', '{nFormatted} {n, plural, =1{kilobyte} other{kilobytes}}', $params, $this->language);
            Severity: Major
            Found in framework/i18n/Formatter.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return Yii::t('yii', '{delta, plural, =1{a month} other{# months}} ago', ['delta' => $interval->m], $this->language);
              Severity: Major
              Found in framework/i18n/Formatter.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                    return Yii::t('yii', '{nFormatted} PiB', $params, $this->language);
                Severity: Major
                Found in framework/i18n/Formatter.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                      return Yii::t('yii', '{nFormatted} kB', $params, $this->language);
                  Severity: Major
                  Found in framework/i18n/Formatter.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return Yii::t('yii', 'just now', [], $this->language);
                    Severity: Major
                    Found in framework/i18n/Formatter.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return Yii::t('yii', 'just now', [], $this->language);
                      Severity: Major
                      Found in framework/i18n/Formatter.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return Yii::t('yii', 'in {delta, plural, =1{a minute} other{# minutes}}', ['delta' => $interval->i], $this->language);
                        Severity: Major
                        Found in framework/i18n/Formatter.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return Yii::t('yii', '{delta, plural, =1{a second} other{# seconds}} ago', ['delta' => $interval->s], $this->language);
                          Severity: Major
                          Found in framework/i18n/Formatter.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return Yii::t('yii', '{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}', $params, $this->language);
                            Severity: Major
                            Found in framework/i18n/Formatter.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                  return Yii::t('yii', '{nFormatted} {n, plural, =1{terabyte} other{terabytes}}', $params, $this->language);
                              Severity: Major
                              Found in framework/i18n/Formatter.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return Yii::t('yii', '{delta, plural, =1{a year} other{# years}} ago', ['delta' => $interval->y], $this->language);
                                Severity: Major
                                Found in framework/i18n/Formatter.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return Yii::t('yii', '{delta, plural, =1{an hour} other{# hours}} ago', ['delta' => $interval->h], $this->language);
                                  Severity: Major
                                  Found in framework/i18n/Formatter.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                        return Yii::t('yii', '{nFormatted} GiB', $params, $this->language);
                                    Severity: Major
                                    Found in framework/i18n/Formatter.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return Yii::t('yii', '{nFormatted} {n, plural, =1{megabyte} other{megabytes}}', $params, $this->language);
                                      Severity: Major
                                      Found in framework/i18n/Formatter.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return Yii::t('yii', '{delta, plural, =1{a day} other{# days}} ago', ['delta' => $interval->d], $this->language);
                                        Severity: Major
                                        Found in framework/i18n/Formatter.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                              return Yii::t('yii', '{nFormatted} B', $params, $this->language);
                                          Severity: Major
                                          Found in framework/i18n/Formatter.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                                return Yii::t('yii', '{nFormatted} {n, plural, =1{petabyte} other{petabytes}}', $params, $this->language);
                                            Severity: Major
                                            Found in framework/i18n/Formatter.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                                  return Yii::t('yii', '{nFormatted} TB', $params, $this->language);
                                              Severity: Major
                                              Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                    return Yii::t('yii', '{nFormatted} {n, plural, =1{tebibyte} other{tebibytes}}', $params, $this->language);
                                                Severity: Major
                                                Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                                  return [
                                                                      $timestamp,
                                                                      !($info['hour'] === false && $info['minute'] === false && $info['second'] === false),
                                                                      !($info['year'] === false && $info['month'] === false && $info['day'] === false && empty($info['zone'])),
                                                                  ];
                                                  Severity: Major
                                                  Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                return new DateTime($value, new DateTimeZone($this->defaultTimeZone));
                                                    Severity: Major
                                                    Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                          return Yii::t('yii', '{nFormatted} GB', $params, $this->language);
                                                      Severity: Major
                                                      Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                            return Yii::t('yii', '{nFormatted} {n, plural, =1{pebibyte} other{pebibytes}}', $params, $this->language);
                                                        Severity: Major
                                                        Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                          return Yii::t('yii', 'in {delta, plural, =1{a day} other{# days}}', ['delta' => $interval->d], $this->language);
                                                          Severity: Major
                                                          Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                                return Yii::t('yii', '{nFormatted} MB', $params, $this->language);
                                                            Severity: Major
                                                            Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                          return Yii::t('yii', 'in {delta, plural, =1{a second} other{# seconds}}', ['delta' => $interval->s], $this->language);
                                                              Severity: Major
                                                              Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                            return Yii::t('yii', '{delta, plural, =1{a minute} other{# minutes}} ago', ['delta' => $interval->i], $this->language);
                                                                Severity: Major
                                                                Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                                      return Yii::t('yii', '{nFormatted} PB', $params, $this->language);
                                                                  Severity: Major
                                                                  Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                                        return Yii::t('yii', '{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}', $params, $this->language);
                                                                    Severity: Major
                                                                    Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                                      return Yii::t('yii', 'in {delta, plural, =1{an hour} other{# hours}}', ['delta' => $interval->h], $this->language);
                                                                      Severity: Major
                                                                      Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                                            return Yii::t('yii', '{nFormatted} TiB', $params, $this->language);
                                                                        Severity: Major
                                                                        Found in framework/i18n/Formatter.php - About 30 mins to fix

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                              return Yii::t('yii', '{nFormatted} {n, plural, =1{byte} other{bytes}}', $params, $this->language);
                                                                          Severity: Major
                                                                          Found in framework/i18n/Formatter.php - About 30 mins to fix

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

                                                                                public function asPercent($value, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.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 format has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                            Open

                                                                                public function format($value, $format)
                                                                                {
                                                                                    if ($format instanceof Closure) {
                                                                                        return call_user_func($format, $value, $this);
                                                                                    } elseif (is_array($format)) {
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.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 asDecimal has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                            Open

                                                                                public function asDecimal($value, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.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 asDecimalStringFallback() has 103 lines of code. Current threshold is set to 100. Avoid really long methods.
                                                                            Open

                                                                                protected function asDecimalStringFallback($value, $decimals = 2)
                                                                                {
                                                                                    if (empty($value)) {
                                                                                        $value = 0;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            The method normalizeDatetimeValue() has an NPath complexity of 430. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                protected function normalizeDatetimeValue($value, $checkDateTimeInfo = false)
                                                                                {
                                                                                    // checking for DateTime and DateTimeInterface is not redundant, DateTimeInterface is only in PHP>5.5
                                                                                    if ($value === null || $value instanceof DateTime || $value instanceof DateTimeInterface) {
                                                                                        // skip any processing
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The class Formatter has 2021 lines of code. Current threshold is 1000. Avoid really long classes.
                                                                            Open

                                                                            class Formatter extends Component
                                                                            {
                                                                                /**
                                                                                 * @since 2.0.13
                                                                                 */
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            The method asRelativeTime() has an NPath complexity of 41600. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                public function asRelativeTime($value, $referenceTime = null)
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The method asDecimalStringFallback() has an NPath complexity of 10640. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                protected function asDecimalStringFallback($value, $decimals = 2)
                                                                                {
                                                                                    if (empty($value)) {
                                                                                        $value = 0;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The method asDuration() has an NPath complexity of 6144. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                public function asDuration($value, $implodeString = ', ', $negativeSign = '-')
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The method formatDateTimeValue() has an NPath complexity of 3024. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                private function formatDateTimeValue($value, $format, $type)
                                                                                {
                                                                                    $timeZone = $this->timeZone;
                                                                                    // avoid time zone conversion for date-only and time-only values
                                                                                    if ($type === 'date' || $type === 'time') {
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The method formatNumber() has an NPath complexity of 378. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                private function formatNumber($value, $decimals, $maxPosition, $formatBase, $options, $textOptions)
                                                                                {
                                                                                    $value = $this->normalizeNumericValue($value);
                                                                            
                                                                                    $position = 0;
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The method createNumberFormatter() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                protected function createNumberFormatter($style, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    $formatter = new NumberFormatter($this->locale, $style);
                                                                            
                                                                                    // set text attributes
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The method asCurrency() has an NPath complexity of 300. The configured NPath complexity threshold is 200.
                                                                            Open

                                                                                public function asCurrency($value, $currency = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                            Example:

                                                                            class Foo {
                                                                                  function bar() {
                                                                                      // lots of complicated code
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                private function formatNumber($value, $decimals, $maxPosition, $formatBase, $options, $textOptions)
                                                                                {
                                                                                    $value = $this->normalizeNumericValue($value);
                                                                            
                                                                                    $position = 0;
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                public function asSize($value, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                public function asShortSize($value, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                public function asDuration($value, $implodeString = ', ', $negativeSign = '-')
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                public function asCurrency($value, $currency = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                private function formatDateTimeValue($value, $format, $type)
                                                                                {
                                                                                    $timeZone = $this->timeZone;
                                                                                    // avoid time zone conversion for date-only and time-only values
                                                                                    if ($type === 'date' || $type === 'time') {
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                public function asRelativeTime($value, $referenceTime = null)
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                protected function normalizeDatetimeValue($value, $checkDateTimeInfo = false)
                                                                                {
                                                                                    // checking for DateTime and DateTimeInterface is not redundant, DateTimeInterface is only in PHP>5.5
                                                                                    if ($value === null || $value instanceof DateTime || $value instanceof DateTimeInterface) {
                                                                                        // skip any processing
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

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

                                                                                protected function asDecimalStringFallback($value, $decimals = 2)
                                                                                {
                                                                                    if (empty($value)) {
                                                                                        $value = 0;
                                                                                    }
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.1

                                                                            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                            Example:

                                                                            // Cyclomatic Complexity = 11
                                                                              class Foo {
                                                                              1   public function example() {
                                                                              2       if ($a == $b) {
                                                                              3           if ($a1 == $b1) {
                                                                                              fiddle();
                                                                              4           } elseif ($a2 == $b2) {
                                                                                              fiddle();
                                                                                          } else {
                                                                                              fiddle();
                                                                                          }
                                                                              5       } elseif ($c == $d) {
                                                                              6           while ($c == $d) {
                                                                                              fiddle();
                                                                                          }
                                                                              7        } elseif ($e == $f) {
                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                              fiddle();
                                                                                          }
                                                                                      } else {
                                                                                          switch ($z) {
                                                                              9               case 1:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              10              case 2:
                                                                                                  fiddle();
                                                                                                  break;
                                                                              11              case 3:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                              default:
                                                                                                  fiddle();
                                                                                                  break;
                                                                                          }
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/codesize.txt

                                                                            The class Formatter has a coupling between objects value of 19. Consider to reduce the number of dependencies under 13.
                                                                            Open

                                                                            class Formatter extends Component
                                                                            {
                                                                                /**
                                                                                 * @since 2.0.13
                                                                                 */
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 1.1.0

                                                                            A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                                                                            Example:

                                                                            class Foo {
                                                                                  /**
                                                                                   * @var \foo\bar\X
                                                                                   */
                                                                                  private $x = null;
                                                                            
                                                                                  /**
                                                                                   * @var \foo\bar\Y
                                                                                   */
                                                                                  private $y = null;
                                                                            
                                                                                  /**
                                                                                   * @var \foo\bar\Z
                                                                                   */
                                                                                  private $z = null;
                                                                            
                                                                                  public function setFoo(\Foo $foo) {}
                                                                                  public function setBar(\Bar $bar) {}
                                                                                  public function setBaz(\Baz $baz) {}
                                                                            
                                                                                  /**
                                                                                   * @return \SplObjectStorage
                                                                                   * @throws \OutOfRangeException
                                                                                   * @throws \InvalidArgumentException
                                                                                   * @throws \ErrorException
                                                                                   */
                                                                                  public function process(\Iterator $it) {}
                                                                            
                                                                                  // ...
                                                                              }

                                                                            Source: http://phpmd.org/rules/design.txt

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

                                                                                protected function normalizeDatetimeValue($value, $checkDateTimeInfo = false)
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 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: http://phpmd.org/rules/cleancode.txt

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

                                                                                public function asSize($value, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 1 other location - About 2 days to fix
                                                                            framework/i18n/Formatter.php on lines 1378..1417

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 388.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

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

                                                                                public function asShortSize($value, $decimals = null, $options = [], $textOptions = [])
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 1 other location - About 2 days to fix
                                                                            framework/i18n/Formatter.php on lines 1434..1473

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 388.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

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

                                                                                public function asOrdinal($value)
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 1 other location - About 2 hrs to fix
                                                                            framework/i18n/Formatter.php on lines 1313..1329

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 116.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

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

                                                                                public function asSpellout($value)
                                                                                {
                                                                                    if ($value === null) {
                                                                                        return $this->nullDisplay;
                                                                                    }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 1 other location - About 2 hrs to fix
                                                                            framework/i18n/Formatter.php on lines 1343..1359

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 116.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

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

                                                                                    if ($this->_intlLoaded) {
                                                                                        $f = $this->createNumberFormatter(NumberFormatter::DECIMAL, $decimals, $options, $textOptions);
                                                                                        if (($result = $f->format($normalizedValue)) === false) {
                                                                                            throw new InvalidArgumentException('Formatting decimal value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
                                                                                        }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 2 other locations - About 1 hr to fix
                                                                            framework/i18n/Formatter.php on lines 1184..1191
                                                                            framework/i18n/Formatter.php on lines 1224..1231

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 83.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

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

                                                                                    if ($this->_intlLoaded) {
                                                                                        $f = $this->createNumberFormatter(NumberFormatter::SCIENTIFIC, $decimals, $options, $textOptions);
                                                                                        if (($result = $f->format($value)) === false) {
                                                                                            throw new InvalidArgumentException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
                                                                                        }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 2 other locations - About 1 hr to fix
                                                                            framework/i18n/Formatter.php on lines 1136..1143
                                                                            framework/i18n/Formatter.php on lines 1184..1191

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 83.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

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

                                                                                    if ($this->_intlLoaded) {
                                                                                        $f = $this->createNumberFormatter(NumberFormatter::PERCENT, $decimals, $options, $textOptions);
                                                                                        if (($result = $f->format($normalizedValue)) === false) {
                                                                                            throw new InvalidArgumentException('Formatting percent value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
                                                                                        }
                                                                            Severity: Major
                                                                            Found in framework/i18n/Formatter.php and 2 other locations - About 1 hr to fix
                                                                            framework/i18n/Formatter.php on lines 1136..1143
                                                                            framework/i18n/Formatter.php on lines 1224..1231

                                                                            Duplicated Code

                                                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                                            Tuning

                                                                            This issue has a mass of 83.

                                                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                            Refactorings

                                                                            Further Reading

                                                                            Avoid excessively long variable names like $numberFormatterTextOptions. Keep variable name length under 25.
                                                                            Open

                                                                                public $numberFormatterTextOptions = [];
                                                                            Severity: Minor
                                                                            Found in framework/i18n/Formatter.php by phpmd

                                                                            Since: PHPMD 0.2

                                                                            Detects when a field, formal or local variable is declared with a long name.

                                                                            Example:

                                                                            class Something {
                                                                                  protected $reallyLongIntName = -3; // VIOLATION - Field
                                                                                  public static function main( array $argumentsList[] ) { // VIOLATION - Formal
                                                                                      $otherReallyLongName = -5; // VIOLATION - Local
                                                                                      for ($interestingIntIndex = 0; // VIOLATION - For
                                                                                           $interestingIntIndex < 10;
                                                                                           $interestingIntIndex++ ) {
                                                                                      }
                                                                                  }
                                                                              }

                                                                            Source: http://phpmd.org/rules/naming.txt

                                                                            There are no issues that match your filters.

                                                                            Category
                                                                            Status