Showing 46 of 46 total issues
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 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 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 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 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 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 __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())],
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'));
}
- 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 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(),
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 = null)
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,
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) {
- 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
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;
- 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
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())) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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())) {
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76