# yiisoft/yii2

framework/i18n/Formatter.php

### Summary

F
1 wk

#### 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;
}
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"

#### 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;
}
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"

return $this->nullDisplay; } 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;
}
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"

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

class Formatter extends Component
{
/**
* @since 2.0.13
*/
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 ...] } #### The class Formatter has 49 public methods and attributes. Consider reducing the number of public items to less than 45. Open class Formatter extends Component { /** * @since 2.0.13 */ 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 ...]
}

#### 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); 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 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]; } 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) Found in framework/i18n/Formatter.php - About 1 hr to fix #### Function init has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open  public function init() { if ($this->timeZone === null) {
$this->timeZone = Yii::$app->timeZone;
}
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"

#### 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 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 ($carry === 0) {
break;
}
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 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 #### Avoid deeply nested control flow statements. Open  if ($oneUp === 10) {
$oneUp = 0;$carry = 1;
}
Found in framework/i18n/Formatter.php - About 45 mins to fix

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

    private function formatNumber($value,$decimals, $maxPosition,$formatBase, $options,$textOptions)
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 [
$value = 0; } 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', 'in {delta, plural, =1{a day} other{# days}}', ['delta' =>$interval->d], $this->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale);
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->locale);
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->locale);
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));
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->locale);
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->locale);
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->locale);
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->locale);
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->locale);
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{kilobyte} other{kilobytes}}', $params,$this->locale);
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'])),
];
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->locale);
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->locale);
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->locale);
Found in framework/i18n/Formatter.php - About 30 mins to fix

            return Yii::t('yii', 'just now', [], $this->locale); 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->locale); 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->locale); 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->locale); 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->locale); 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->locale); Found in framework/i18n/Formatter.php - About 30 mins to fix #### 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)) {
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"

#### 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;
}
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"

#### 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;
}
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"

    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') { 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 } } #### 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;
}
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
}
}

#### 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 = [])
{
$value = 0; } 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 } } #### 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
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
}
}

#### 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;
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
}
}

#### 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') { 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;
}
}
}
}

#### 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; } 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;
}
}
}
}

#### 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;
}
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; } } } } #### 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; 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;
}
}
}
}

#### 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;
}
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; } } } } #### 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; } 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;
}
}
}
}

#### 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;
}
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; } } } } #### 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; } 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;
}
}
}
}

#### 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 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;
}
}
}
}

#### 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
*/
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) {} // ... } #### 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)
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 {
return $this->nullDisplay; } Found in framework/i18n/Formatter.php and 1 other location - About 2 days to fix framework/i18n/Formatter.php on lines 1424..1463 ## 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;
}
Found in framework/i18n/Formatter.php and 1 other location - About 2 hrs to fix
framework/i18n/Formatter.php on lines 1303..1319

## 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

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

    public function asSpellout($value) { if ($value === null) {
return $this->nullDisplay; } Found in framework/i18n/Formatter.php and 1 other location - About 2 hrs to fix framework/i18n/Formatter.php on lines 1333..1349 ## 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());
}
Found in framework/i18n/Formatter.php and 2 other locations - About 1 hr to fix
framework/i18n/Formatter.php on lines 1174..1181
framework/i18n/Formatter.php on lines 1214..1221

## 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

#### 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()); } Found in framework/i18n/Formatter.php and 2 other locations - About 1 hr to fix framework/i18n/Formatter.php on lines 1126..1133 framework/i18n/Formatter.php on lines 1214..1221 ## 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());
}
Found in framework/i18n/Formatter.php and 2 other locations - About 1 hr to fix
framework/i18n/Formatter.php on lines 1126..1133
framework/i18n/Formatter.php on lines 1174..1181

## 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

#### Avoid excessively long variable names like $numberFormatterTextOptions. Keep variable name length under 25. Open  public$numberFormatterTextOptions = [];
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++ ) {
}
}
}