EscolaLMS/Cart

View on GitHub

Showing 46 of 46 total issues

File ProductService.php has 534 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace EscolaLms\Cart\Services;

use EscolaLms\Cart\Contracts\Productable;
Severity: Major
Found in src/Services/ProductService.php - About 1 day to fix

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

    <?php
    
    namespace EscolaLms\Cart\Http\Requests\Admin;
    
    use EscolaLms\Cart\Models\Product;
    Severity: Major
    Found in src/Http/Requests/Admin/ProductAttachRequest.php and 1 other location - About 4 hrs to fix
    src/Http/Requests/Admin/ProductDetachRequest.php on lines 1..48

    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 182.

    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

    <?php
    
    namespace EscolaLms\Cart\Http\Requests\Admin;
    
    use EscolaLms\Cart\Models\Product;
    Severity: Major
    Found in src/Http/Requests/Admin/ProductDetachRequest.php and 1 other location - About 4 hrs to fix
    src/Http/Requests/Admin/ProductAttachRequest.php on lines 1..48

    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 182.

    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

    <?php
    
    namespace EscolaLms\Cart\Http\Requests\Admin;
    
    use EscolaLms\Cart\Enums\CartPermissionsEnum;
    Severity: Major
    Found in src/Http/Requests/Admin/ProductableDetachRequest.php and 1 other location - About 3 hrs to fix
    src/Http/Requests/Admin/ProductableAttachRequest.php on lines 1..42

    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 154.

    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

    <?php
    
    namespace EscolaLms\Cart\Http\Requests\Admin;
    
    use EscolaLms\Cart\Enums\CartPermissionsEnum;
    Severity: Major
    Found in src/Http/Requests/Admin/ProductableAttachRequest.php and 1 other location - About 3 hrs to fix
    src/Http/Requests/Admin/ProductableDetachRequest.php on lines 1..42

    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 154.

    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

    ProductService has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ProductService implements ProductServiceContract
    {
        protected array $productables = [];
        protected array $productablesMorphs = [];
    
    
    Severity: Minor
    Found in src/Services/ProductService.php - About 3 hrs to fix

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

          public function attachToUser(User $user, int $quantity = 1, ?Product $product = null): void
          {
              if (ModelHelper::hasRelation($this, 'users') && $this->users() instanceof BelongsToMany) {
                  $this->users()->syncWithoutDetaching($user->getKey());
              } elseif (ModelHelper::hasRelation($user, $this->getTable()) && $user->{$this->getTable()}() instanceof BelongsToMany) {
      Severity: Major
      Found in src/Contracts/ProductableTrait.php and 1 other location - About 3 hrs to fix
      src/Contracts/ProductableTrait.php on lines 100..109

      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 147.

      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 detachFromUser(User $user, int $quantity = 1, ?Product $product = null): void
          {
              if (ModelHelper::hasRelation($this, 'users') && $this->users() instanceof BelongsToMany) {
                  $this->users()->detach($user->getKey());
              } elseif (ModelHelper::hasRelation($user, $this->getTable()) && $user->{$this->getTable()}() instanceof BelongsToMany) {
      Severity: Major
      Found in src/Contracts/ProductableTrait.php and 1 other location - About 3 hrs to fix
      src/Contracts/ProductableTrait.php on lines 89..98

      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 147.

      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

      Method update has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function update(Product $product, array $data): Product
          {
              if (ProductType::isSubscriptionType($product->type) && !ProductType::isSubscriptionType($data['type'])) {
                  throw new Exception(__('Product with subscription type cannot have type changed'));
              }
      Severity: Major
      Found in src/Services/ProductService.php - About 3 hrs to fix

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

            public function scopeOwnedByUser(Builder $query, User $user): Builder
            {
                if (ModelHelper::hasRelation($this, 'users')) {
                    return $query->whereHas('users', fn (Builder $query) => $query->where('users.id', $user->getKey()));
                }
        Severity: Major
        Found in src/Contracts/ProductableTrait.php and 1 other location - About 2 hrs to fix
        src/Contracts/ProductableTrait.php on lines 60..69

        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 141.

        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 scopeNotOwnedByUser(Builder $query, User $user): Builder
            {
                if (ModelHelper::hasRelation($this, 'users')) {
                    return $query->whereDoesntHave('users', fn (Builder $query) => $query->where('users.id', $user->getKey()));
                }
        Severity: Major
        Found in src/Contracts/ProductableTrait.php and 1 other location - About 2 hrs to fix
        src/Contracts/ProductableTrait.php on lines 49..58

        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 141.

        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

        Function attachProductToUser has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            public function attachProductToUser(Product $product, User $user, int $quantity = 1): void
            {
                Log::debug(__('Attaching product to user'), [
                    'product' => [
                        'id' => $product->getKey(),
        Severity: Minor
        Found in src/Services/ProductService.php - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method attachProductToUser has 69 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function attachProductToUser(Product $product, User $user, int $quantity = 1): void
            {
                Log::debug(__('Attaching product to user'), [
                    'product' => [
                        'id' => $product->getKey(),
        Severity: Major
        Found in src/Services/ProductService.php - About 2 hrs to fix

          Function update has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
          Open

              public function update(Product $product, array $data): Product
              {
                  if (ProductType::isSubscriptionType($product->type) && !ProductType::isSubscriptionType($data['type'])) {
                      throw new Exception(__('Product with subscription type cannot have type changed'));
                  }
          Severity: Minor
          Found in src/Services/ProductService.php - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Product has 24 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class Product extends Model implements ProductInterface
          {
              use ProductTrait;
              use HasFactory;
          
          
          Severity: Minor
          Found in src/Models/Product.php - About 2 hrs to fix

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

                public function whereDoesntHaveProductablesNotOwnedByUser(?User $user = null): Builder
                {
                    $user = $user ?? Auth::user();
                    return $this->whereDoesntHave('productables', fn (Builder $query) => $query->whereHas('productable', function (Builder $subquery) use ($user) {
                        // We need to change queried model to the one that implements Productable class and has NotOwnedByUser scope method
            Severity: Major
            Found in src/QueryBuilders/ProductModelQueryBuilder.php and 1 other location - About 2 hrs to fix
            src/QueryBuilders/ProductModelQueryBuilder.php on lines 55..63

            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 124.

            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 whereDoesntHaveProductablesNotBuyableByUser(?User $user = null): Builder
                {
                    $user = $user ?? Auth::user();
                    return $this->whereDoesntHave('productables', fn (Builder $query) => $query->whereHas('productable', function (Builder $subquery) use ($user) {
                        // We need to change queried model to the one that implements Productable class and has NotBuyableByUser scope method
            Severity: Major
            Found in src/QueryBuilders/ProductModelQueryBuilder.php and 1 other location - About 2 hrs to fix
            src/QueryBuilders/ProductModelQueryBuilder.php on lines 45..53

            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 124.

            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

            <?php
            
            namespace EscolaLms\Cart\Events;
            
            use EscolaLms\Cart\Models\Product;
            Severity: Major
            Found in src/Events/AbstractProductEvent.php and 1 other location - About 1 hr to fix
            src/Events/AbstractProductableEvent.php on lines 1..39

            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 119.

            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

            <?php
            
            namespace EscolaLms\Cart\Events;
            
            use EscolaLms\Core\Models\User;
            Severity: Major
            Found in src/Events/AbstractProductableEvent.php and 1 other location - About 1 hr to fix
            src/Events/AbstractProductEvent.php on lines 1..39

            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 119.

            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

            Function searchAndPaginateProducts has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                public function searchAndPaginateProducts(ProductsSearchDto $searchDto, ?OrderDto $orderDto = null): LengthAwarePaginator
                {
                    $query = Product::query();
            
                    if (!is_null($searchDto->getName())) {
            Severity: Minor
            Found in src/Services/ProductService.php - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Severity
            Category
            Status
            Source
            Language