Function formatToDisplay
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function formatToDisplay(?string $value): string
{
if (empty($value)) {
return '0';
}
- 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
Avoid using static access to class '\App\User' in method 'formatToDisplay'. Open
$userModel = \App\User::getCurrentUserModel();
- 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 assigning values to variables in if clauses and the like (line '34', column '8'). Open
public static function formatToDisplay(?string $value): string
{
if (empty($value)) {
return '0';
}
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\User' in method 'formatToDb'. Open
$userModel = \App\User::getCurrentUserModel();
- 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\TextUtils' in method 'formatToDisplay'. Open
if (($length = \App\TextUtils::getTextLength($value)) > 3) {
- 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
Call to method getCurrentUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userModel = \App\User::getCurrentUserModel();
- Exclude checks
Call to method getCurrentUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
$userModel = \App\User::getCurrentUserModel();
- Exclude checks
The DEFAULT body must start on the line following the statement Open
default:
- Exclude checks
Line exceeds 120 characters; contains 172 characters Open
$value = preg_replace('/(\d)(?=(\d\d)+(?!\d))/', "$1{$groupSeperator}", substr($value, 0, $length - 3)) . $groupSeperator . substr($value, $length - 3);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Convert number to format for database.
- 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 formatToDisplay(?string $value): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case '123,456,789':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = preg_replace('/(\d)(?=(\d\d)+(?!\d))/', "$1{$groupSeperator}", substr($value, 0, $length - 3)) . $groupSeperator . substr($value, $length - 3);
- 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
$userModel = \App\User::getCurrentUserModel();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case '123456,789':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = substr($value, 0, $length - 3) . $groupSeperator . substr($value, $length - 3);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case '12,34,56,789':
- 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
public static function formatToDb(?string $value): int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = str_replace($groupSeperator, '', $value);
- 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 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$groupSeperator = $userModel->getDetail('currency_grouping_separator');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to display number in user format.
- 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 (empty($value)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = preg_replace('/(\d)(?=(\d\d\d)+(?!\d))/', "$1{$groupSeperator}", $value);
- 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 string|null $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$groupPatern = $userModel->getDetail('currency_grouping_pattern');
- 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|null $value
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($value)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return (int) preg_replace('/[^0-9\.-]/', '', $value);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return '0';
- 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
}
- 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
return $value;
- 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 (($length = \App\TextUtils::getTextLength($value)) > 3) {
- 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
*/
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$groupSeperator = $userModel->getDetail('currency_grouping_separator');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($groupPatern) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userModel = \App\User::getCurrentUserModel();
- 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
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks