Method formatToRangeText
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
{
$full = $short = [];
$hours = (int) $value;
if ('y' === $unit) {
Function getIntervalPart
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function getIntervalPart(\DateInterval $dateInterval, string $formatOut = 'ahis')
{
$value = 0;
$parts = str_split($formatOut, 1);
foreach (['a', 'h', 'i', 's'] as $part) {
- Read upRead up
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 displayElapseTime
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
{
$dateFormat = [];
$multiplier = 1;
switch ($formatIn) {
- Read upRead up
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 formatToRangeText
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
{
$full = $short = [];
$hours = (int) $value;
if ('y' === $unit) {
- Read upRead up
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 displayElapseTime
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
{
$dateFormat = [];
$multiplier = 1;
switch ($formatIn) {
The method formatToRangeText() has an NPath complexity of 1080. The configured NPath complexity threshold is 200. Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
{
$full = $short = [];
$hours = (int) $value;
if ('y' === $unit) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 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 https://phpmd.org/rules/codesize.html#npathcomplexity
The method displayElapseTime() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
{
$dateFormat = [];
$multiplier = 1;
switch ($formatIn) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 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 https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method formatToRangeText() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
{
$full = $short = [];
$hours = (int) $value;
if ('y' === $unit) {
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 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 https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Refactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed. Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The method displayElapseTime has a boolean flag argument $short, which is a certain sign of a Single Responsibility Principle violation. Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '60', column '15'). Open
$dtF = new \DateTime('@0');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '61', column '15'). Open
$dtT = new \DateTime("@{$seconds}");
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method formatToRangeText has a boolean flag argument $showEmptyValue, which is a certain sign of a Single Responsibility Principle violation. Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $years ? $years . ' ' . \App\Language::translate('LBL_YEAR') : $years . ' ' . \App\Language::translate('LBL_YEARS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $days ? $days . ' ' . \App\Language::translate('LBL_DAY') : $days . ' ' . \App\Language::translate('LBL_DAYS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $hours ? $hours . ' ' . \App\Language::translate('LBL_HOUR') : $hours . ' ' . \App\Language::translate('LBL_HOURS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'displayElapseTime'. Open
$dateFormat[] = $short ? $seconds . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$seconds} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['plural']);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $years ? $years . ' ' . \App\Language::translate('LBL_YEAR') : $years . ' ' . \App\Language::translate('LBL_YEARS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$short[] = 1 === $years ? $years . \App\Language::translate('LBL_Y') : $years . \App\Language::translate('LBL_YRS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$short[] = 1 === $years ? $years . \App\Language::translate('LBL_Y') : $years . \App\Language::translate('LBL_YRS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$short[] = $minutes . \App\Language::translate('LBL_M');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $days ? $days . ' ' . \App\Language::translate('LBL_DAY') : $days . ' ' . \App\Language::translate('LBL_DAYS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $minutes ? $minutes . ' ' . \App\Language::translate('LBL_MINUTE') : $minutes . ' ' . \App\Language::translate('LBL_MINUTES');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $hours ? $hours . ' ' . \App\Language::translate('LBL_HOUR') : $hours . ' ' . \App\Language::translate('LBL_HOURS');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$short[] = $days . \App\Language::translate('LBL_D');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'displayElapseTime'. Open
$dateFormat[] = $short ? $val . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$val} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part][(1 === $val ? 'singular' : 'plural')]);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'displayElapseTime'. Open
$dateFormat[] = $short ? $val . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$val} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part][(1 === $val ? 'singular' : 'plural')]);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$short[] = $hours . \App\Language::translate('LBL_H');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'displayElapseTime'. Open
$dateFormat[] = $short ? $seconds . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$seconds} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['plural']);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Language' in method 'formatToRangeText'. Open
$full[] = 1 === $minutes ? $minutes . ' ' . \App\Language::translate('LBL_MINUTE') : $minutes . ' ' . \App\Language::translate('LBL_MINUTES');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "short" 9 times. Open
'y' => ['short' => 'LBL_Y', 'plural' => 'LBL_YEARS', 'singular' => 'LBL_YEAR'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "plural" 7 times. Open
'y' => ['short' => 'LBL_Y', 'plural' => 'LBL_YEARS', 'singular' => 'LBL_YEAR'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "singular" 6 times. Open
'y' => ['short' => 'LBL_Y', 'plural' => 'LBL_YEARS', 'singular' => 'LBL_YEAR'],
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Expected @param annotation for interval
to be before the @param annotation for formatIn
Open
* @param string $formatIn y,h,m,s
- Exclude checks
Saw an @param annotation for timePeriod,
but it was not found in the param list of function displayElapseTime(mixed $interval, string $formatIn = 'i', string $formatOut = 'ahi', bool|true $short = null) : string
Open
* @param int|float $timePeriod Elapse time
- Exclude checks
Return type of getIntervalPart()
is undeclared type \App\Fields\Generator
(Did you mean class \Generator) Open
public static function getIntervalPart(\DateInterval $dateInterval, string $formatOut = 'ahis')
- Exclude checks
Returning type \Generator
but getIntervalPart()
is declared to return \App\Fields\Generator
Open
public static function getIntervalPart(\DateInterval $dateInterval, string $formatOut = 'ahis')
- Exclude checks
Returning type array{short:string,full:string}
but formatToRangeText()
is declared to return string
Open
'short' => implode(' ', $short),
- Exclude checks
Avoid variables with short names like $y. Configured minimum length is 3. Open
private static function myBcmod($x, $y)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $x. Configured minimum length is 3. Open
private static function myBcmod($x, $y)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $a. Configured minimum length is 3. Open
$a = (int) $mod . substr($x, 0, $take);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateInterval = $dtF->diff($dtT);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return Generator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$years = (int) floor($val / 365);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($mode && isset(${$mode})) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (['a', 'h', 'i', 's'] as $part) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$val = (int) $dateInterval->format("%{$part}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $mode
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$full = $short = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$days = static::myBcmod(($value), (60 * 24 * 365));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($days)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$full[] = 1 === $days ? $days . ' ' . \App\Language::translate('LBL_DAY') : $days . ' ' . \App\Language::translate('LBL_DAYS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'i':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
yield [$val, $part];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $unit
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$short[] = $hours . \App\Language::translate('LBL_H');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int|float $timePeriod Elapse time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $formatIn y,h,m,s
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getIntervalPart(\DateInterval $dateInterval, string $formatOut = 'ahis')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parts = str_split($formatOut, 1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$days = ($days) / (24 * 60);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$short[] = $minutes . \App\Language::translate('LBL_M');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'a' => ['short' => 'LBL_D', 'plural' => 'LBL_DAYS', 'singular' => 'LBL_DAY'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $formatOut ahis - a:days(year), h:hours, i:minutes, s:seconds
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $short
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$seconds = (int) ((float) $interval * $multiplier);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('a' === $part && $val > 365 && \in_array($part, $parts)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $value Date time
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$short[] = 1 === $years ? $years . \App\Language::translate('LBL_Y') : $years . \App\Language::translate('LBL_YRS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$short[] = $days . \App\Language::translate('LBL_D');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
's' => ['short' => 'LBL_S', 'plural' => 'LBL_SECONDS', 'singular' => 'LBL_SECOND'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($val) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$part = substr($formatOut, -1) ?: 'i';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('y' === $unit || 'd' === $unit) {
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
$full[] = 1 === $days ? $days . ' ' . \App\Language::translate('LBL_DAY') : $days . ' ' . \App\Language::translate('LBL_DAYS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = ($hours) / (60);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$minutes = static::myBcmod(($value), (60));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$multiplier = 60 * 24 * 365;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dtT = new \DateTime("@{$seconds}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateFormat[] = $short ? $seconds . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$seconds} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['plural']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function returns the date in user specified format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = (int) $value;
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
$full[] = 1 === $hours ? $hours . ' ' . \App\Language::translate('LBL_HOUR') : $hours . ' ' . \App\Language::translate('LBL_HOURS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return implode(' ', ${$mode});
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (self::getIntervalPart($dateInterval, $formatOut) as [$val, $part]) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('h' === $part || 'i' === $part) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$full[] = 1 === $hours ? $hours . ' ' . \App\Language::translate('LBL_HOUR') : $hours . ' ' . \App\Language::translate('LBL_HOURS');
- Exclude checks
Line exceeds 120 characters; contains 154 characters Open
$full[] = 1 === $minutes ? $minutes . ' ' . \App\Language::translate('LBL_MINUTE') : $minutes . ' ' . \App\Language::translate('LBL_MINUTES');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'h':
- Exclude checks
Line exceeds 120 characters; contains 233 characters Open
$dateFormat[] = $short ? $val . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$val} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part][(1 === $val ? 'singular' : 'plural')]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = ($val + $value) * 60;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$days = floor($days);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$minutes = floor($minutes);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var array Interval labels
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$full[] = 1 === $years ? $years . ' ' . \App\Language::translate('LBL_YEAR') : $years . ' ' . \App\Language::translate('LBL_YEARS');
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
$full[] = 1 === $years ? $years . ' ' . \App\Language::translate('LBL_YEAR') : $years . ' ' . \App\Language::translate('LBL_YEARS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = static::myBcmod(($value), (24 * 60));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($minutes) || $showEmptyValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get the current interval in a human readable format.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $interval
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($formatIn) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($seconds) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
yield [$years, 'y'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\in_array($part, $parts)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
$short[] = 1 === $years ? $years . \App\Language::translate('LBL_Y') : $years . \App\Language::translate('LBL_YRS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'h' => ['short' => 'LBL_H', 'plural' => 'LBL_HOURS', 'singular' => 'LBL_HOUR'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'i' => ['short' => 'LBL_M', 'plural' => 'LBL_MINUTES', 'singular' => 'LBL_MINUTE'],
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
public static function displayElapseTime($interval, string $formatIn = 'i', string $formatOut = 'ahi', bool $short = true): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'y':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get data interval part.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('a' === $part) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$years = floor($years);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $formatOut
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $val * 24;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('y' === $unit) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const DIFF_INTERVAL_LABELS = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'y' => ['short' => 'LBL_Y', 'plural' => 'LBL_YEARS', 'singular' => 'LBL_YEAR'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateFormat = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$multiplier = 1;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$multiplier = 60;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ($formatOut) {
- Exclude checks
Line exceeds 120 characters; contains 205 characters Open
$dateFormat[] = $short ? $seconds . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$seconds} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['plural']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return implode(' ', $dateFormat);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$val = (int) static::myBcmod(($val), 365);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$val += $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $showEmptyValue
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$years = ((int) $value) / (60 * 24 * 365);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($hours)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dtF = new \DateTime('@0');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \DateInterval $dateInterval
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$hours = floor($hours);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$full[] = 1 === $minutes ? $minutes . ' ' . \App\Language::translate('LBL_MINUTE') : $minutes . ' ' . \App\Language::translate('LBL_MINUTES');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$multiplier = 60 * 60;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dateFormat[] = $short ? $val . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part]['short']) : "{$val} " . \App\Language::translate(self::DIFF_INTERVAL_LABELS[$part][(1 === $val ? 'singular' : 'plural')]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function formatToRangeText($value, $mode = 'short', $showEmptyValue = true, $unit = 'h')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($years)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (int) $mod;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mod = $a % $y;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} while (\strlen($x));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $x
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'full' => implode(' ', $full),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
do {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* myBcmod - get modulus (substitute for bcmod)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* by Andrius Baranauskas and Laurynas Butkus :) Vilnius, Lithuania.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* string my_bcmod ( string left_operand, int modulus )
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $y
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
// how many numbers to take at once? carefull not to exceed (int)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$mod = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$take = 5;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$a = (int) $mod . substr($x, 0, $take);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$x = substr($x, $take);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'short' => implode(' ', $short),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* left_operand can be really big, but be carefull with modulus :(
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static function myBcmod($x, $y)
- Exclude checks