EscolaLMS/Consultations

View on GitHub
src/Http/Resources/ConsultationTermsResource.php

Summary

Maintainability
A
1 hr
Test Coverage
A
100%

Method toArray has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function toArray($request)
    {
        $consultationServiceContract = app(ConsultationServiceContract::class);
        $fields = [
            'consultation_term_id' => $this->resource->getKey(),
Severity: Minor
Found in src/Http/Resources/ConsultationTermsResource.php - About 1 hr to fix

    Avoid using static access to class 'EscolaLms\Consultations\Http\Resources\ConsultationTermResource' in method 'toArray'.
    Open

                'busy_terms' => ConsultationTermResource::collection($consultationServiceContract->getBusyTermsFormatDate($this->resource->consultation->getKey())),

    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\ConsultationAuthorResource' in method 'toArray'.
    Open

                'author' =>  $this->resource->consultation->author ? ConsultationAuthorResource::make($this->resource->consultation->author) : null,

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

                'date' => Carbon::make($this->resource->executed_at) ?? '',

    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\ConsultationAuthorResource' in method 'toArray'.
    Open

                    ConsultationAuthorResource::make($this->resource->user) :

    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 parameters such as '$request'.
    Open

        public function toArray($request)

    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

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'date' => Carbon::make($this->resource->executed_at) ?? '',

    Call to undeclared function \app()
    Open

            $consultationServiceContract = app(ConsultationServiceContract::class);

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->executed_at,

    Static call to undeclared method \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource::apply
    Open

            return self::apply($fields, $this);

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->consultation->getDuration()

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'user' => isset($this->resource->user) ?

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->executed_at,

    Static call to undeclared method \EscolaLms\Consultations\Http\Resources\ConsultationAuthorResource::make
    Open

                'author' =>  $this->resource->consultation->author ? ConsultationAuthorResource::make($this->resource->consultation->author) : null,

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'duration' => $this->resource->consultation->getDuration(),

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->executed_status,

    Static call to undeclared method \EscolaLms\Consultations\Http\Resources\ConsultationTermResource::collection
    Open

                'busy_terms' => ConsultationTermResource::collection($consultationServiceContract->getBusyTermsFormatDate($this->resource->consultation->getKey())),

    Class uses undeclared trait \EscolaLms\Auth\Traits\ResourceExtandable
    Open

    class ConsultationTermsResource extends JsonResource

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'status' => $this->resource->executed_status ?? '',

    Static call to undeclared method \EscolaLms\Consultations\Http\Resources\ConsultationAuthorResource::make
    Open

                    ConsultationAuthorResource::make($this->resource->user) :

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->consultation->getDuration()

    Class extends undeclared class \Illuminate\Http\Resources\Json\JsonResource
    Open

    class ConsultationTermsResource extends JsonResource

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->consultation->getDuration()

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->executed_status,

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'consultation_term_id' => $this->resource->getKey(),

    Call to method make from undeclared class \Illuminate\Support\Carbon
    Open

                'date' => Carbon::make($this->resource->executed_at) ?? '',

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    ConsultationAuthorResource::make($this->resource->user) :

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'author' =>  $this->resource->consultation->author ? ConsultationAuthorResource::make($this->resource->consultation->author) : null,

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                    $this->resource->executed_at,

    Reference to undeclared property \EscolaLms\Consultations\Http\Resources\ConsultationTermsResource->resource
    Open

                'busy_terms' => ConsultationTermResource::collection($consultationServiceContract->getBusyTermsFormatDate($this->resource->consultation->getKey())),

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

            $consultationServiceContract = app(ConsultationServiceContract::class);

    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 144 characters
    Open

                'author' =>  $this->resource->consultation->author ? ConsultationAuthorResource::make($this->resource->consultation->author) : null,

    Line exceeds 120 characters; contains 160 characters
    Open

                'busy_terms' => ConsultationTermResource::collection($consultationServiceContract->getBusyTermsFormatDate($this->resource->consultation->getKey())),

    There are no issues that match your filters.

    Category
    Status