EscolaLMS/Consultations

View on GitHub
src/Services/ConsultationService.php

Summary

Maintainability
D
2 days
Test Coverage
B
85%

File ConsultationService.php has 436 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EscolaLms\Consultations\Services;

use Auth;
Severity: Minor
Found in src/Services/ConsultationService.php - About 6 hrs to fix

    ConsultationService has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ConsultationService implements ConsultationServiceContract
    {
        private ConsultationRepositoryContract $consultationRepositoryContract;
        private ConsultationUserRepositoryContract $consultationUserRepositoryContract;
        private JitsiServiceContract $jitsiServiceContract;
    Severity: Minor
    Found in src/Services/ConsultationService.php - About 4 hrs to fix

      The class ConsultationService has an overall complexity of 62 which is very high. The configured complexity threshold is 50.
      Open

      class ConsultationService implements ConsultationServiceContract
      {
          private ConsultationRepositoryContract $consultationRepositoryContract;
          private ConsultationUserRepositoryContract $consultationUserRepositoryContract;
          private JitsiServiceContract $jitsiServiceContract;
      Severity: Minor
      Found in src/Services/ConsultationService.php by phpmd

      The class ConsultationService has 22 public methods. Consider refactoring ConsultationService to keep number of public methods under 10.
      Open

      class ConsultationService implements ConsultationServiceContract
      {
          private ConsultationRepositoryContract $consultationRepositoryContract;
          private ConsultationUserRepositoryContract $consultationUserRepositoryContract;
          private JitsiServiceContract $jitsiServiceContract;
      Severity: Minor
      Found in src/Services/ConsultationService.php by phpmd

      TooManyPublicMethods

      Since: 0.1

      A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

      By default it ignores methods starting with 'get' or 'set'.

      Example

      Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

      Method generateJitsi has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function generateJitsi(int $consultationTermId): array
          {
              /** @var ConsultationUserPivot $consultationTerm */
              $consultationTerm = $this->consultationUserRepositoryContract->find($consultationTermId);
              if (!$this->canGenerateJitsi(
      Severity: Minor
      Found in src/Services/ConsultationService.php - About 1 hr to fix

        Method forCurrentUserResponse has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function forCurrentUserResponse(
                ListConsultationsRequest $listConsultationsRequest
            ): AnonymousResourceCollection {
                $search = $listConsultationsRequest->except(['limit', 'skip', 'order', 'order_by', 'paginate']);
                $consultations = $this->getConsultationsListForCurrentUser($search);
        Severity: Minor
        Found in src/Services/ConsultationService.php - About 1 hr to fix

          Method generateJitsiUrlForEmail has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function generateJitsiUrlForEmail(int $consultationTermId, int $userId): ?string
              {
                  /** @var ConsultationUserPivot $consultationTerm */
                  $consultationTerm = $this->consultationUserRepositoryContract->find($consultationTermId);
                  $isModerator = false;
          Severity: Minor
          Found in src/Services/ConsultationService.php - About 1 hr to fix

            The class ConsultationService has a coupling between objects value of 39. Consider to reduce the number of dependencies under 13.
            Open

            class ConsultationService implements ConsultationServiceContract
            {
                private ConsultationRepositoryContract $consultationRepositoryContract;
                private ConsultationUserRepositoryContract $consultationUserRepositoryContract;
                private JitsiServiceContract $jitsiServiceContract;
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            CouplingBetweenObjects

            Since: 1.1.0

            A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

            Example

            class Foo {
                /**
                 * @var \foo\bar\X
                 */
                private $x = null;
            
                /**
                 * @var \foo\bar\Y
                 */
                private $y = null;
            
                /**
                 * @var \foo\bar\Z
                 */
                private $z = null;
            
                public function setFoo(\Foo $foo) {}
                public function setBar(\Bar $bar) {}
                public function setBaz(\Baz $baz) {}
            
                /**
                 * @return \SplObjectStorage
                 * @throws \OutOfRangeException
                 * @throws \InvalidArgumentException
                 * @throws \ErrorException
                 */
                public function process(\Iterator $it) {}
            
                // ...
            }

            Source https://phpmd.org/rules/design.html#couplingbetweenobjects

            The method getConsultationsList has a boolean flag argument $onlyActive, which is a certain sign of a Single Responsibility Principle violation.
            Open

                public function getConsultationsList(array $search = [], bool $onlyActive = false, OrderDto $orderDto = null): Builder
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            BooleanArgumentFlag

            Since: 1.4.0

            A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

            Example

            class Foo {
                public function bar($flag = true) {
                }
            }

            Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

            Avoid using static access to class '\EscolaLms\Consultations\Helpers\StrategyHelper' in method 'setRelations'.
            Open

                        StrategyHelper::useStrategyPattern(
                            $className,
                            'RelationsStrategy',
                            'setRelation',
                            $consultation,
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'getConsultationsListForCurrentUser'.
            Open

                    $search['active_to'] = isset($search['active_to']) ? Carbon::make($search['active_to']) : $now;
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Illuminate\Support\Facades\DB' in method 'store'.
            Open

                    return DB::transaction(function () use($consultationDto) {
                        /** @var Consultation $consultation */
                        $consultation = $this->consultationRepositoryContract->create($consultationDto->toArray());
                        $this->setRelations($consultation, $consultationDto->getRelations());
                        $this->setFiles($consultation, $consultationDto->getFiles());
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Illuminate\Support\Facades\DB' in method 'setStatus'.
            Open

                    return DB::transaction(function () use ($status, $consultationTerm) {
                        return $this->consultationUserRepositoryContract->updateModel($consultationTerm, ['executed_status' => $status]);
                    });
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'forCurrentUserResponse'.
            Open

                            'executed_at' => Carbon::make($consultation->resource->executed_at),
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'getConsultationsListForCurrentUser'.
            Open

                    $search['active_from'] = isset($search['active_from']) ? Carbon::make($search['active_from']) : $now;
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'reportTerm'.
            Open

                            'executed_at' => Carbon::make($executedAt)
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Jitsi\Helpers\StringHelper' in method 'generateJitsi'.
            Open

                        StringHelper::convertToJitsiSlug($consultationTerm->consultation->name),
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Illuminate\Support\Facades\DB' in method 'update'.
            Open

                    return DB::transaction(function () use($consultation, $consultationDto) {
                        $this->setFiles($consultation, $consultationDto->getFiles());
                        $consultation = $this->consultationRepositoryContract->updateModel($consultation, $consultationDto->toArray());
                        $this->setRelations($consultation, $consultationDto->getRelations());
                        return $consultation;
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Dto\FilterConsultationTermsListDto' in method 'getConsultationTermsByConsultationId'.
            Open

                    $filterConsultationTermsDto = FilterConsultationTermsListDto::prepareFilters(
                        array_merge($search, ['consultation_id' => $consultationId])
                    );
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'changeTerm'.
            Open

                                'executed_at' => Carbon::make($executedAt),
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Dto\FilterListDto' in method 'getConsultationsList'.
            Open

                    $criteria = FilterListDto::prepareFilters($search);
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Illuminate\Support\Facades\DB' in method 'delete'.
            Open

                    return DB::transaction(function () use($id) {
                        return $this->consultationRepositoryContract->delete($id);
                    });
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'getBusyTermsFormatDate'.
            Open

                        fn ($term) => Carbon::make($term->executed_at)
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Models\User' in method 'generateJitsiUrlForEmail'.
            Open

                    $user = User::find($userId);
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Http\Resources\ConsultationSimpleResource' in method 'forCurrentUserResponse'.
            Open

                    ConsultationSimpleResource::extend(function (ConsultationSimpleResource $consultation) {
                        return [
                            'consultation_term_id' => $consultation->resource->consultation_user_id,
                            'name' => $consultation->resource->name,
                            'image_path' => $consultation->resource->image_path,
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Illuminate\Support\Facades\DB' in method 'changeTerm'.
            Open

                    DB::transaction(function () use ($consultationTermId, $executedAt) {
                        try {
                            /** @var ConsultationUserPivot $consultationUser */
                            $consultationUser = $this->consultationUserRepositoryContract->update([
                                'executed_at' => Carbon::make($executedAt),
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Dto\FilterListDto' in method 'getConsultationsListForCurrentUser'.
            Open

                    $criteria = FilterListDto::prepareFilters($search);
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Jitsi\Helpers\StringHelper' in method 'generateJitsiUrlForEmail'.
            Open

                        StringHelper::convertToJitsiSlug($consultationTerm->consultation->name),
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Http\Resources\ConsultationSimpleResource' in method 'forCurrentUserResponse'.
            Open

                        $consultationsCollection = ConsultationSimpleResource::collection($consultations->paginate(
                            $listConsultationsRequest->get('per_page') ??
                            config('escolalms_consultations.perPage', ConstantEnum::PER_PAGE)
                        ));
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'canGenerateJitsi'.
            Open

                        $dateTo = Carbon::make($executedAt);
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Files\Helpers\FileHelper' in method 'setFiles'.
            Open

                        $consultation->$key = FileHelper::getFilePath($file, ConstantEnum::DIRECTORY . "/{$consultation->getKey()}/images");
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\EscolaLms\Consultations\Http\Resources\ConsultationSimpleResource' in method 'forCurrentUserResponse'.
            Open

                        $consultationsCollection = ConsultationSimpleResource::collection($consultations->get());
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Illuminate\Support\Facades\DB' in method 'reportTerm'.
            Open

                    return DB::transaction(function () use ($consultationTermId, $executedAt) {
                        /** @var ConsultationUserPivot $consultationTerm */
                        $consultationTerm = $this->consultationUserRepositoryContract->find($consultationTermId);
                        if ($this->termIsBusy($consultationTerm->consultation_id, $executedAt)) {
                            abort(400, __('Term is busy, change your term.'));
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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

            The method forCurrentUserResponse uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    } else {
                        $consultationsCollection = ConsultationSimpleResource::collection($consultations->get());
                    }
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 '\Carbon\Carbon' in method 'filterProposedTerms'.
            Open

                    return $proposedTerms->map(fn(ConsultationProposedTerm $proposedTerm) => Carbon::make($proposedTerm->proposed_at))->filter(fn (Carbon $proposedTerm) => !in_array($proposedTerm, $busyTerms))->toArray();
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 unused local variables such as '$value'.
            Open

                    foreach ($relations as $key => $value) {
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

            syntax error, unexpected 'ConsultationRepositoryContract' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
            Open

                private ConsultationRepositoryContract $consultationRepositoryContract;
            Severity: Critical
            Found in src/Services/ConsultationService.php by phan

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public function rejectTerm(int $consultationTermId): bool
                {
                    /** @var ConsultationUserPivot $consultationTerm */
                    $consultationTerm = $this->consultationUserRepositoryContract->find($consultationTermId);
                    $this->setStatus($consultationTerm, ConsultationTermStatusEnum::REJECT);
            Severity: Minor
            Found in src/Services/ConsultationService.php and 1 other location - About 1 hr to fix
            src/Services/ConsultationService.php on lines 148..158

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 100.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                public function approveTerm(int $consultationTermId): bool
                {
                    /** @var ConsultationUserPivot $consultationTerm */
                    $consultationTerm = $this->consultationUserRepositoryContract->find($consultationTermId);
                    $this->setStatus($consultationTerm, ConsultationTermStatusEnum::APPROVED);
            Severity: Minor
            Found in src/Services/ConsultationService.php and 1 other location - About 1 hr to fix
            src/Services/ConsultationService.php on lines 160..170

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 100.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Avoid excessively long variable names like $consultationUserRepositoryContract. Keep variable name length under 20.
            Open

                private ConsultationUserRepositoryContract $consultationUserRepositoryContract;
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 $consultationRepositoryContract. Keep variable name length under 20.
            Open

                private ConsultationRepositoryContract $consultationRepositoryContract;
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 $consultationRepositoryContract. Keep variable name length under 20.
            Open

                    ConsultationRepositoryContract $consultationRepositoryContract,
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 $listConsultationsRequest. Keep variable name length under 20.
            Open

                    ListConsultationsRequest $listConsultationsRequest
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 $filterConsultationTermsDto. Keep variable name length under 20.
            Open

                    $filterConsultationTermsDto = FilterConsultationTermsListDto::prepareFilters(
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 $consultationsCollection. Keep variable name length under 20.
            Open

                        $consultationsCollection = ConsultationSimpleResource::collection($consultations->paginate(
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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

                    $consultationUserPivot = $this->consultationUserRepositoryContract->find($consultationTermId);
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 $consultationUserRepositoryContract. Keep variable name length under 20.
            Open

                    ConsultationUserRepositoryContract $consultationUserRepositoryContract,
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            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 variables with short names like $id. Configured minimum length is 3.
            Open

                public function show(int $id): Consultation
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            Avoid variables with short names like $id. Configured minimum length is 3.
            Open

                public function update(int $id, ConsultationDto $consultationDto): Consultation
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            Avoid variables with short names like $id. Configured minimum length is 3.
            Open

                public function delete(int $id): ?bool
            Severity: Minor
            Found in src/Services/ConsultationService.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            Expected 1 space after USE keyword; found 0
            Open

                    return DB::transaction(function () use($consultationDto) {

            Expected 1 space after USE keyword; found 0
            Open

                    return DB::transaction(function () use($id) {

            Expected 1 space after USE keyword; found 0
            Open

                    return DB::transaction(function () use($consultation, $consultationDto) {

            Line exceeds 120 characters; contains 128 characters
            Open

                        $consultation->$key = FileHelper::getFilePath($file, ConstantEnum::DIRECTORY . "/{$consultation->getKey()}/images");

            Line exceeds 120 characters; contains 124 characters
            Open

                        $search['active_to'] = isset($search['active_to']) ? Carbon::make($search['active_to'])->format('Y-m-d') : $now;

            Line exceeds 120 characters; contains 123 characters
            Open

                        $consultation = $this->consultationRepositoryContract->updateModel($consultation, $consultationDto->toArray());

            Line exceeds 120 characters; contains 130 characters
            Open

                                throw new ChangeTermException(__('Term is changed but not executed event because user or term is no exists'));

            Line exceeds 120 characters; contains 122 characters
            Open

                public function getConsultationsList(array $search = [], bool $onlyActive = false, OrderDto $orderDto = null): Builder

            Line exceeds 120 characters; contains 130 characters
            Open

                        $search['active_from'] = isset($search['active_from']) ? Carbon::make($search['active_from'])->format('Y-m-d') : $now;

            Line exceeds 120 characters; contains 136 characters
            Open

                    return $this->filterProposedTerms($consultationUserPivot->consultation_id, $consultationUserPivot->consultation->proposedTerms);

            Line exceeds 120 characters; contains 209 characters
            Open

                    return $proposedTerms->map(fn(ConsultationProposedTerm $proposedTerm) => Carbon::make($proposedTerm->proposed_at))->filter(fn (Carbon $proposedTerm) => !in_array($proposedTerm, $busyTerms))->toArray();

            Line exceeds 120 characters; contains 125 characters
            Open

                        return $this->consultationUserRepositoryContract->updateModel($consultationTerm, ['executed_status' => $status]);

            Line exceeds 120 characters; contains 123 characters
            Open

                            'is_ended' => $this->isEnded($consultation->resource->executed_at, $consultation->resource->getDuration()),

            Space before opening parenthesis of function call prohibited
            Open

                    if ($terms->first(fn (ConsultationUserPivot $userPivot) => $userPivot->user_id === $userId) !== null) {

            Space before opening parenthesis of function call prohibited
            Open

                    if ($terms->first(fn (ConsultationUserPivot $userPivot) => $userPivot->user_id === $userId) !== null) {

            Space before opening parenthesis of function call prohibited
            Open

                        fn ($term) => Carbon::make($term->executed_at)

            Space before opening parenthesis of function call prohibited
            Open

                    return $proposedTerms->map(fn(ConsultationProposedTerm $proposedTerm) => Carbon::make($proposedTerm->proposed_at))->filter(fn (Carbon $proposedTerm) => !in_array($proposedTerm, $busyTerms))->toArray();

            There are no issues that match your filters.

            Category
            Status