EscolaLMS/Cart

View on GitHub

Showing 46 of 46 total issues

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 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
          {
              $user = $request ? $request->user() : Auth::user();
              $data = [
                  'id' => $this->getProduct()->getKey(),
      Severity: Minor
      Found in src/Http/Resources/BaseProductResource.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
            {
                $product = Product::find($this->productUser->product_id);
                $user = User::find($this->productUser->user_id);
        
        
        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 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 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 __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

                        Function saveProductProductables has a Cognitive Complexity of 10 (exceeds 5 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

                        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 attachProductableToUser has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

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

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

                              public function __construct(?string $name = null, ?string $type = null, ?bool $free = null, ?string $productable_type  = null, ?int $productable_id = null, ?bool $purchasable = true, ?int $per_page = null, ?array $tags)
                          Severity: Major
                          Found in src/Dtos/ProductsSearchDto.php - About 1 hr to fix

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

                                    ?Carbon $date_from = null,
                                    ?Carbon $date_to = null,
                                    ?int $user_id = null,
                                    ?int $product_id = null,
                                    ?int $productable_id = null,
                            Severity: Major
                            Found in src/Dtos/OrdersSearchDto.php - About 1 hr to fix

                              Function detachProductFromUser has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function detachProductFromUser(Product $product, User $user, int $quantity = 1): void
                                  {
                                      $productUserPivot = ProductUser::where(['user_id' => $user->getKey(), 'product_id' => $product->getKey()])->first();
                              
                                      if (!$productUserPivot) {
                              Severity: Minor
                              Found in src/Services/ProductService.php - About 45 mins 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

                              Function passes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  public function passes($attribute, $value): bool
                                  {
                                      if (!is_array($value)) {
                                          $this->message = __(':field must be an array.');
                                          return false;
                              Severity: Minor
                              Found in src/Rules/ProductProductablesRule.php - About 45 mins 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

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

                                      if (!is_null($searchDto->getProductableType())) {
                                          $class = $searchDto->getProductableType();
                                          /** @var Model $model */
                                          $model = new $class();
                                          if (!is_null($searchDto->getProductableId())) {
                              Severity: Minor
                              Found in src/Services/ProductService.php and 1 other location - About 45 mins to fix
                              src/Services/OrderService.php on lines 230..239

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

                              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

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

                                      if (!is_null($searchDto->getProductableType())) {
                                          $class = $searchDto->getProductableType();
                                          /** @var Model $model */
                                          $model = new $class();
                                          if (!is_null($searchDto->getProductableId())) {
                              Severity: Minor
                              Found in src/Services/OrderService.php and 1 other location - About 45 mins to fix
                              src/Services/ProductService.php on lines 172..181

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

                              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

                              Severity
                              Category
                              Status
                              Source
                              Language