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 5 hrs to fix
    src/Http/Requests/Admin/ProductDetachRequest.php on lines 1..52

    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 5 hrs to fix
    src/Http/Requests/Admin/ProductAttachRequest.php on lines 1..52

    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

    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

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

      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

      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

        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

        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

        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

          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 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 46..55

            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 57..66

            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

            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

            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
            Severity
            Category
            Status
            Source
            Language