Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$paramsToString = '?'.http_build_query($params);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$params['rand'] = uniqid('u_', true);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$params' which will lead to PHP notices. Open
$params['w'] = 64;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
The method getGroupsByUser uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$qb->andWhere('gu.relationType = :relationType')
->setParameter('relationType', $relationType)
;
}
- 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
The method searchGroupsByTags uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$qb->select('g.id, g.title, g.description, g.url, g.picture');
}
- 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 unused parameters such as '$withImage'. Open
public function getGroupsByUser(int $userId, int $relationType = 0, bool $withImage = false): array
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
The parameter $number_of_items is not named in camelCase. Open
public function searchGroupsByTags(string $tag, int $from = 0, int $number_of_items = 10, bool $getCount = false)
{
$qb = $this->createQueryBuilder('g');
if ($getCount) {
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Missing function doc comment Open
public function getUsersByGroup(int $groupID)
- Exclude checks
Missing function doc comment Open
public function isGroupModerator(int $groupId, int $userId): bool
- Exclude checks
Variable "number_of_items" is not in valid camel caps format Open
public function searchGroupsByTags(string $tag, int $from = 0, int $number_of_items = 10, bool $getCount = false)
- Exclude checks
Missing function doc comment Open
public function addUserToGroup(int $userId, int $groupId, int $relationType = Usergroup::GROUP_USER_PERMISSION_READER): void
- Exclude checks
Missing function doc comment Open
public function searchGroupsByTags(string $tag, int $from = 0, int $number_of_items = 10, bool $getCount = false)
- Exclude checks
Missing function doc comment Open
public function getNewestGroups(int $limit = 30, string $query = ''): array
- Exclude checks
Add a single space around assignment operators Open
declare(strict_types=1);
- Exclude checks
Missing function doc comment Open
public function isGroupMember(int $groupId, User $user): bool
- Exclude checks
Missing function doc comment Open
public function findGroupById($id)
- Exclude checks
Missing function doc comment Open
public function searchGroups(string $searchTerm): array
- Exclude checks
Missing function doc comment Open
public function removeUserFromGroup(int $userId, int $groupId, bool $checkLeaveRestriction = true): bool
- Exclude checks
Doc comment for parameter $relationType does not match actual variable name $userId Open
* @param int|array $relationType
- Exclude checks
Missing function doc comment Open
public function getPopularGroups(int $limit = 30): array
- Exclude checks
Missing function doc comment Open
public function getInvitedUsers(int $groupId): array
- Exclude checks
Missing function doc comment Open
public function updateUserRole($userId, $groupId, $relationType = Usergroup::GROUP_USER_PERMISSION_READER): void
- Exclude checks
Missing function doc comment Open
public function countMembers(int $usergroupId): int
- Exclude checks
Missing function doc comment Open
public function __construct(
- Exclude checks
Missing class doc comment Open
class UsergroupRepository extends ResourceRepository
- Exclude checks
Missing function doc comment Open
public function getUsergroupPicture($userGroupId): string
- Exclude checks
Missing function doc comment Open
public function getUserGroupRole(int $groupId, int $userId): ?int
- Exclude checks
Missing function doc comment Open
public function getInvitedUsersByGroup(int $groupID)
- Exclude checks
Variable "number_of_items" is not in valid camel caps format Open
->setMaxResults($number_of_items)
- Exclude checks
The 'getUseMultipleUrl()' method which returns a boolean should be named 'is...()' or 'has...()' Open
public function getUseMultipleUrl(): bool
{
// TODO: Implement the actual logic to determine if multi-URLs should be used.
// For now, returning false as a default value.
return false;
- Read upRead up
- Exclude checks
BooleanGetMethodName
Since: 0.2
Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.
Example
class Foo {
/**
* @return boolean
*/
public function getFoo() {} // bad
/**
* @return bool
*/
public function isFoo(); // ok
/**
* @return boolean
*/
public function getFoo($bar); // ok, unless checkParameterizedMethods=true
}
Source https://phpmd.org/rules/naming.html#booleangetmethodname
Line indented incorrectly; expected 4 spaces, found 8 Open
private readonly AccessUrlHelper $accessUrlHelper,
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
private readonly IllustrationRepository $illustrationRepository,
- Exclude checks
The variable $number_of_items is not named in camelCase. Open
public function searchGroupsByTags(string $tag, int $from = 0, int $number_of_items = 10, bool $getCount = false)
{
$qb = $this->createQueryBuilder('g');
if ($getCount) {
- Read upRead up
- 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();
}
}