EscolaLMS/Cart

View on GitHub

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

    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

      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

        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

            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

            Method run has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function run()
                {
                    $student = User::role(UserRole::STUDENT)->first();
                    if (!$student) {
                        // This will only be called if Users were not seeded before CartSeeder was Called
            Severity: Minor
            Found in database/seeders/OrdersSeeder.php - About 1 hr to fix

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

                  public function toArray($request): array
                  {
                      /** @var User|null $user */
                      // @phpstan-ignore-next-line
                      $user = $request ? $request->user() : Auth::user();
              Severity: Minor
              Found in src/Http/Resources/BaseProductResource.php - About 1 hr to fix

                Method listAllProductables has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function listAllProductables(): Collection
                    {
                        $collection = Collection::empty();
                        foreach ($this->listRegisteredProductableClasses() as $productableClass) {
                            /** @var Model&Productable $model */
                Severity: Minor
                Found in src/Services/ProductService.php - About 1 hr to fix

                  Method handle has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function handle(OrderServiceContract $orderService): void
                      {
                          /** @var Product $product */
                          $product = Product::find($this->productUser->product_id);
                          /** @var User $user */
                  Severity: Minor
                  Found in src/Jobs/RenewRecursiveProductUser.php - About 1 hr to fix

                    Method searchAndPaginateProducts has 33 lines of code (exceeds 25 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

                      Function searchOrders has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function searchOrders(OrdersSearchDto $searchDto, ?OrderDto $sortDto): Builder
                          {
                              /** @var OrderModelQueryBuilder $query */
                              $query = Order::query();
                      
                      
                      Severity: Minor
                      Found in src/Services/OrderService.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

                      Method createOrderFromProduct has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function createOrderFromProduct(Product $product, int $userId, ?ClientDetailsDto $clientDetailsDto = null): Order
                          {
                              $optionalClientDetailsDto = optional($clientDetailsDto);
                      
                              /** @var User $user */
                      Severity: Minor
                      Found in src/Services/OrderService.php - About 1 hr to fix

                        Method saveProductProductables has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            private function saveProductProductables(Product $product, array $productables)
                            {
                                if ($product->type === ProductType::SINGLE && count($productables) > 1) {
                                    throw new Exception(__('Product with type SINGLE can contain only one single Productable'));
                                }
                        Severity: Minor
                        Found in src/Services/ProductService.php - About 1 hr to fix

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

                              public function searchOrders(OrdersSearchDto $searchDto, ?OrderDto $sortDto): Builder
                              {
                                  /** @var OrderModelQueryBuilder $query */
                                  $query = Order::query();
                          
                          
                          Severity: Minor
                          Found in src/Services/OrderService.php - About 1 hr to fix

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

                                public function rules(): array
                                {
                                    return [
                                        'name' => ['sometimes', 'string'],
                                        'type' => ['sometimes', Rule::in(ProductType::getValues())],
                            Severity: Minor
                            Found in src/Http/Requests/Admin/ProductUpdateRequest.php - About 1 hr to fix

                              Method __construct has 9 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                      ?string $name = null,
                                      ?string $email = null,
                                      ?string $street = null,
                                      ?string $street_number = null,
                                      ?string $city = null,
                              Severity: Major
                              Found in src/Dtos/ClientDetailsDto.php - About 1 hr to fix

                                Method rules has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public function rules(): array
                                    {
                                        return [
                                            'name' => ['required', 'string'],
                                            'type' => ['required', Rule::in(ProductType::getValues())],
                                Severity: Minor
                                Found in src/Http/Requests/Admin/ProductCreateRequest.php - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language