Showing 48 of 67 total issues
Function getByUser
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getByUser(User $user): Collection
{
$progresses = new Collection();
if (!$user instanceof CoursesUser) {
/** @var CoursesUser $user */
- 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 rules
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function rules(): array
{
return [
'title' => 'string|max:255',
'summary' => 'nullable|string',
Method buildProgress
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function buildProgress(): EloquentCollection
{
$topicWithProgressId = CourseProgress::where('user_id', $this->user->getKey())->whereIn('topic_id', $this->topics->toArray())->pluck('topic_id')->toArray();
$topicsWithoutProgress = $this->course
->topics()
Method toArray
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toArray($request)
{
$topicable = $this->resource->topicable;
if ($this->resource->lesson && !$this->resource->lesson->isActive()) {
Method createTopicContentModelFromRequest
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function createTopicContentModelFromRequest(FormRequest $request, Topic $topic): Model
{
$class = $request->input('topicable_type');
if (!in_array($class, $this->contentClasses)) {
Function updateInTopic
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void
{
$update = ['status' => $status];
if (!is_null($seconds)) {
- 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 allMain
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
array $search = [],
?int $skip = null,
?int $limit = null,
array $columns = ['*'],
string $orderDirection = 'asc',
Method allMain
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
array $search = [],
?int $skip = null,
?int $limit = null,
array $columns = ['*'],
string $orderDirection = 'asc',
Function updateFromRequest
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function updateFromRequest(UpdateTopicAPIRequest $request): Topic
{
$topic = $request->getTopic()->loadMissing('topicable');
if ($request->has('topicable_type')) {
- 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 getCoursesListWithOrdering
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function getCoursesListWithOrdering(OrderDto $orderDto, array $search = []): Builder
{
$criteria = $this->prepareCriteria($orderDto);
if (isset($search['title'])) {
- 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 authorize
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function authorize(): bool
{
$user = auth()->user();
$course = Course::find($this->input('course_id'));
if (isset($user) && $user->can('update', $course)) {
- 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 updateInTopic
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void
Method updateInTopic
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function updateInTopic(Topic $topic, Authenticatable $user, int $status, ?int $seconds = null, ?bool $newAttempt = false): void;
Function buildProgress
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function buildProgress(): EloquentCollection
{
$topicWithProgressId = CourseProgress::where('user_id', $this->user->getKey())->whereIn('topic_id', $this->topics->toArray())->pluck('topic_id')->toArray();
$topicsWithoutProgress = $this->course
->topics()
- 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 getRulesForTopicContentUpdate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function getRulesForTopicContentUpdate(FormRequest $request, TopicContentContract $topicContent)
{
// we want to do partial update, so we add 'sometimes' to all rules
$partialRules = array_map(fn ($field_rules) => is_array($field_rules) ? array_merge(['sometimes'], $field_rules) : 'sometimes' . $field_rules, $topicContent::rules());
- 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
Avoid too many return
statements within this method. Open
return $this->sendResponseForResource(TopicAdminResource::make($topic), __('Topic updated successfully'));
Avoid too many return
statements within this method. Open
return $course->is_published && $course->hasUser($user);
Avoid too many return
statements within this method. Open
return $this->sendSuccess(__('Topic deleted successfully'));
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $course->hasAuthor($user);