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;
ProductService
has 29 functions (exceeds 20 allowed). Consider refactoring. Open
class ProductService implements ProductServiceContract
{
protected array $productables = [];
protected array $productablesMorphs = [];
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'));
}
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(),
- Read upRead up
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(),
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'));
}
- Read upRead up
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;
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())) {
- Read upRead up
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
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();
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 */
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 */
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())) {
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();
- Read upRead up
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 */
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'));
}
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();
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())],
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,
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())],