EscolaLMS/Webinar

View on GitHub
src/Services/WebinarService.php

Summary

Maintainability
C
7 hrs
Test Coverage

File WebinarService.php has 325 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EscolaLms\Webinar\Services;

use Carbon\Carbon;
Severity: Minor
Found in src/Services/WebinarService.php - About 3 hrs to fix

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

    class WebinarService implements WebinarServiceContract
    {
        private WebinarRepositoryContract $webinarRepositoryContract;
        private JitsiServiceContract $jitsiServiceContract;
        private YoutubeServiceContract $youtubeServiceContract;
    Severity: Minor
    Found in src/Services/WebinarService.php by phpmd

    WebinarService has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WebinarService implements WebinarServiceContract
    {
        private WebinarRepositoryContract $webinarRepositoryContract;
        private JitsiServiceContract $jitsiServiceContract;
        private YoutubeServiceContract $youtubeServiceContract;
    Severity: Minor
    Found in src/Services/WebinarService.php - About 2 hrs to fix

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

          public function generateJitsi(int $webinarId): array
          {
              /** @var Webinar|null $webinar */
              $webinar = $this->webinarRepositoryContract->find($webinarId);
              if (!$webinar || !$this->canGenerateJitsi($webinar)) {
      Severity: Minor
      Found in src/Services/WebinarService.php - About 1 hr to fix

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

        class WebinarService implements WebinarServiceContract
        {
            private WebinarRepositoryContract $webinarRepositoryContract;
            private JitsiServiceContract $jitsiServiceContract;
            private YoutubeServiceContract $youtubeServiceContract;
        Severity: Minor
        Found in src/Services/WebinarService.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 getWebinarsList has a boolean flag argument $onlyIncoming, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function getWebinarsList(array $search = [], bool $onlyActive = false, ?OrderDto $orderDto = null, bool $onlyIncoming = false): Builder
        Severity: Minor
        Found in src/Services/WebinarService.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

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

            public function getWebinarsList(array $search = [], bool $onlyActive = false, ?OrderDto $orderDto = null, bool $onlyIncoming = false): Builder
        Severity: Minor
        Found in src/Services/WebinarService.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

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

            public function extendResponse($webinarSimpleResource, $isApi = false)
        Severity: Minor
        Found in src/Services/WebinarService.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

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

                } else {
                    $now = now()->format('Y-m-d');
                    $search['active_to'] = isset($search['active_to']) ? Carbon::make($search['active_to'])->format('Y-m-d') : $now;
                    $search['active_from'] = isset($search['active_from']) ? Carbon::make($search['active_from']) : $now;
                }
        Severity: Minor
        Found in src/Services/WebinarService.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 'canGenerateJitsi'.
        Open

                $activeTo = $webinar->active_to ? Carbon::make($webinar->active_to) : null;
        Severity: Minor
        Found in src/Services/WebinarService.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) {
                    /** @var Webinar|null $webinar */
                    $webinar = $this->webinarRepositoryContract->find($id);
                    if (!$webinar) {
                        throw new NotFoundHttpException(__('Webinar not found'));
        Severity: Minor
        Found in src/Services/WebinarService.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 'getWebinarsListForCurrentUser'.
        Open

                    $search['active_from'] = isset($search['active_from']) ? Carbon::make($search['active_from']) : $now;
        Severity: Minor
        Found in src/Services/WebinarService.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\Webinar\Dto\FilterListDto' in method 'getWebinarsList'.
        Open

                $criteria = FilterListDto::prepareFilters($search);
        Severity: Minor
        Found in src/Services/WebinarService.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\Webinar\Dto\FilterListDto' in method 'reminderAboutWebinar'.
        Open

                    FilterListDto::prepareFilters($data)
        Severity: Minor
        Found in src/Services/WebinarService.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\Webinar\Dto\FilterListDto' in method 'getWebinarsListForCurrentUser'.
        Open

                $criteria = FilterListDto::prepareFilters($search);
        Severity: Minor
        Found in src/Services/WebinarService.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\Webinar\Http\Resources\WebinarSimpleResource' in method 'extendResponse'.
        Open

                WebinarSimpleResource::extend(function (WebinarSimpleResource $webinar) use ($isApi) {
                    $user = auth()->user();
                    $extendedArray = [];
                    if (($user && $this->isTrainer($user, $webinar->resource)) || !$isApi) {
                        $extendedArray = $webinar->resource->hasYT() ?
        Severity: Minor
        Found in src/Services/WebinarService.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\Webinar\Helpers\StrategyHelper' in method 'setRelations'.
        Open

                    StrategyHelper::useStrategyPattern(
                        $className,
                        'RelationsStrategy',
                        'setRelation',
                        $webinar,
        Severity: Minor
        Found in src/Services/WebinarService.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

                    $webinar->$key = FileHelper::getFilePath($file, ConstantEnum::DIRECTORY . "/{$webinar->getKey()}/images");
        Severity: Minor
        Found in src/Services/WebinarService.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 ($webinar, $webinarDto) {
                    $this->setFiles($webinar, $webinarDto->getFiles());
                    $webinar = $this->webinarRepositoryContract->updateModel($webinar, $webinarDto->toArray());
                    $this->setRelations($webinar, $webinarDto->getRelations());
                    if ($webinar->hasYT()) {
        Severity: Minor
        Found in src/Services/WebinarService.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 'getWebinarEndDate'.
        Open

                return $webinar->active_to ? Carbon::make($webinar->active_to) : null;
        Severity: Minor
        Found in src/Services/WebinarService.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($webinar->name),
        Severity: Minor
        Found in src/Services/WebinarService.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 ($webinarDto) {
                    /** @var Webinar $webinar */
                    $webinar = $this->webinarRepositoryContract->create($webinarDto->toArray());
                    $this->setRelations($webinar, $webinarDto->getRelations());
                    $this->setFiles($webinar, $webinarDto->getFiles());
        Severity: Minor
        Found in src/Services/WebinarService.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 parameters such as '$onlyIncoming'.
        Open

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

        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

        Avoid unused local variables such as '$now'.
        Open

                $now = now();
        Severity: Minor
        Found in src/Services/WebinarService.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

        Avoid unused local variables such as '$value'.
        Open

                foreach ($relations as $key => $value) {
        Severity: Minor
        Found in src/Services/WebinarService.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 'WebinarRepositoryContract' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
        Open

            private WebinarRepositoryContract $webinarRepositoryContract;
        Severity: Critical
        Found in src/Services/WebinarService.php by phan

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

                WebinarRepositoryContract $webinarRepositoryContract,
        Severity: Minor
        Found in src/Services/WebinarService.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 $youtubeServiceContract. Keep variable name length under 20.
        Open

                YoutubeServiceContract    $youtubeServiceContract
        Severity: Minor
        Found in src/Services/WebinarService.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 $webinarRepositoryContract. Keep variable name length under 20.
        Open

            private WebinarRepositoryContract $webinarRepositoryContract;
        Severity: Minor
        Found in src/Services/WebinarService.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 $youtubeServiceContract. Keep variable name length under 20.
        Open

            private YoutubeServiceContract $youtubeServiceContract;
        Severity: Minor
        Found in src/Services/WebinarService.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 $webinarSimpleResource. Keep variable name length under 20.
        Open

            public function extendResponse($webinarSimpleResource, $isApi = false)
        Severity: Minor
        Found in src/Services/WebinarService.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): Webinar
        Severity: Minor
        Found in src/Services/WebinarService.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, WebinarDto $webinarDto): Webinar
        Severity: Minor
        Found in src/Services/WebinarService.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/WebinarService.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

        The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
        Open

            {

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

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

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

                    'event_start_date_time' => $webinar->active_to ? Carbon::make($webinar->active_to)->format('Y-m-d H:i:s') : now()->format('Y-m-d H:i:s'),

        There are no issues that match your filters.

        Category
        Status