The method hasTrait uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$hasTrait = false;
foreach (class_uses($class) as $useName) {
if ($useName === $traitName || self::hasTrait($useName, $traitName)) {
$hasTrait = true;
- Read upRead up
- Create a ticketCreate a ticket
- 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
The property $_hasTraitCache is not named in camelCase. Open
final class TraitUtil
{
/** @var array<class-string, array<string, bool>> */
private static $_hasTraitCache = [];
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Property name "$_hasTraitCache" should not be prefixed with an underscore to indicate visibility Open
private static $_hasTraitCache = [];
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
throw new Exception(self::class . '::hasTrait() method is not intended for use with other than Atk4\Core\* traits');
- Create a ticketCreate a ticket
- Exclude checks
The variable $_hasTraitCache is not named in camelCase. Open
public static function hasTrait($class, string $traitName): bool
{
if (is_object($class)) {
$class = get_class($class);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_hasTraitCache is not named in camelCase. Open
public static function hasTrait($class, string $traitName): bool
{
if (is_object($class)) {
$class = get_class($class);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_hasTraitCache is not named in camelCase. Open
public static function hasTrait($class, string $traitName): bool
{
if (is_object($class)) {
$class = get_class($class);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $_hasTraitCache is not named in camelCase. Open
public static function hasTrait($class, string $traitName): bool
{
if (is_object($class)) {
$class = get_class($class);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}