src/Repositories/ConsultationUserTermRepository.php
Method getByCurrentUserTutor
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function getByCurrentUserTutor(): Collection
{
$result = collect();
$terms = $this->model->newQuery()
->whereHas('consultationUser', fn (Builder $query) => $query
The method getByCurrentUserTutor uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
} else {
$result->push(new ConsultationUserTermResourceDto(
$term->consultation_user_id,
$term->consultationUser->consultation_id,
$term->executed_at,
- 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
syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')'
Open
Open
$query->whereHas('consultationUser', fn($query) => $query->where('consultation_id', '=', $consultationId));
- Exclude checks
Avoid excessively long variable names like $filterConsultationTermsListDto. Keep variable name length under 20. Open
Open
public function allQueryBuilder(?FilterConsultationTermsListDto $filterConsultationTermsListDto = null): Collection
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $consultationUserPivot. Keep variable name length under 20. Open
Open
public function createUserTerm(ConsultationUserPivot $consultationUserPivot, array $data): ConsultationUserTerm
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $consultationUserPivot. Keep variable name length under 20. Open
Open
public function updateUserTermByExecutedAt(ConsultationUserPivot $consultationUserPivot, string $executedAt, array $data): ConsultationUserTerm
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Line exceeds 120 characters; contains 125 characters Open
Open
->orWhereHas('teachers', fn (Builder $query) => $query->where('users.id', '=', auth()->user()->getKey()))
- Exclude checks
Line exceeds 120 characters; contains 196 characters Open
Open
$userTerm = $result->first(fn (ConsultationUserTermResourceDto $dto) => $dto->consultation_id === $term->consultationUser->consultation_id && $term->executed_at === $dto->executed_at);
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
Open
public function updateByConsultationUserIdAndExecutedAt(int $consultationUserId, string $executedAt, array $data): ConsultationUserTerm
- Exclude checks
Line exceeds 120 characters; contains 163 characters Open
Open
$userTerm->executed_status = $term->executed_status === ConsultationTermStatusEnum::APPROVED ? $term->executed_status : $userTerm->executed_status;
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
Open
$query->whereIn('executed_status', [ConsultationTermStatusEnum::APPROVED, ConsultationTermStatusEnum::REPORTED]);
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
Open
public function updateUserTermByExecutedAt(ConsultationUserPivot $consultationUserPivot, string $executedAt, array $data): ConsultationUserTerm
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
->whereHas('consultation', fn (Builder $query) => $query
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
$userTerm = $result->first(fn (ConsultationUserTermResourceDto $dto) => $dto->consultation_id === $term->consultationUser->consultation_id && $term->executed_at === $dto->executed_at);
- Exclude checks
Expected 0 spaces before closing bracket; newline found Open
Open
->whereHas('consultationUser', fn (Builder $query) => $query
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
->orWhereHas('teachers', fn (Builder $query) => $query->where('users.id', '=', auth()->user()->getKey()))
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
->whereHas('consultationUser', fn (Builder $query) => $query->where('user_id', '=', $userId))
- Exclude checks
Expected 0 spaces before closing bracket; newline found Open
Open
->whereHas('consultation', fn (Builder $query) => $query
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
->whereHas('consultationUser', fn (Builder $query) => $query
- Exclude checks