Function Set
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function Set($aLocale)
{
if (in_array($aLocale, array_keys($this->iDayAbb), true)) {
$this->iLocale = $aLocale;
- 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 Set
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function Set($aLocale)
{
if (in_array($aLocale, array_keys($this->iDayAbb), true)) {
$this->iLocale = $aLocale;
Remove error control operator '@' on line 50. Open
public function Set($aLocale)
{
if (in_array($aLocale, array_keys($this->iDayAbb), true)) {
$this->iLocale = $aLocale;
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
Remove error control operator '@' on line 42. Open
public function Set($aLocale)
{
if (in_array($aLocale, array_keys($this->iDayAbb), true)) {
$this->iLocale = $aLocale;
- Read upRead up
- Exclude checks
ErrorControlOperator
Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.
Example
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
Source http://phpmd.org/rules/cleancode.html#errorcontroloperator
The method Set uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$res = @setlocale(LC_TIME, $aLocale);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Amenadiel\JpGraph\Util\JpGraphError' in method 'Set'. Open
JpGraphError::RaiseL(25007, $aLocale);
- 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
Method name "DateLocale::GetShortDay" is not in camel caps format Open
public function GetShortDay()
- Exclude checks
Method name "DateLocale::Set" is not in camel caps format Open
public function Set($aLocale)
- Exclude checks
Method name "DateLocale::GetDayAbb" is not in camel caps format Open
public function GetDayAbb()
- Exclude checks
Method name "DateLocale::GetMonth" is not in camel caps format Open
public function GetMonth()
- Exclude checks
Method name "DateLocale::GetShortMonth" is not in camel caps format Open
public function GetShortMonth()
- Exclude checks
Method name "DateLocale::GetShortMonthName" is not in camel caps format Open
public function GetShortMonthName($aNbr)
- Exclude checks
Method name "DateLocale::GetLongMonthName" is not in camel caps format Open
public function GetLongMonthName($aNbr)
- Exclude checks
Line exceeds 120 characters; contains 180 characters Open
//("You are trying to use the locale ($aLocale) which your PHP installation does not support. Hint: Use '' to indicate the default locale for this geographic region.");
- Exclude checks