Showing 67 of 67 total issues
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function getImageUrlAttribute(): ?string
{
if ($this->attributes['image_path'] ?? null) {
$path = trim(trim($this->attributes['image_path'], '/'));
if ($path) {
- 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 108.
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
Similar blocks of code found in 3 locations. Consider refactoring. Open
public function getVideoUrlAttribute(): ?string
{
if ($this->attributes['video_path'] ?? null) {
$path = trim(trim($this->attributes['video_path'], '/'));
if ($path) {
- 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 108.
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
Method toArray
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toArray($request)
{
$this->withoutWrapping();
if ($this->resource instanceof Course) {
Method toArray
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toArray($request): array
{
$this->withoutWrapping();
$course = $this->getResource();
Method run
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function run()
{
if (Course::count() === 0) {
$this->call(CoursesSeeder::class);
}
Method toArray
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toArray($request): array
{
$this->withoutWrapping();
$course = $this->getResource();
Function update
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function update(array $input, int $id): Model
{
$query = $this->model->newQuery();
/** @var Course $model */
- 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 allQueryBuilder
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function allQueryBuilder(array $search = [], array $criteria = []): Builder
{
/** search main category and all subcategories */
if (isset($search['category_id'])) {
$collection = Category::where('id', $search['category_id'])->with('children')->get();
- 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 31 lines of code (exceeds 25 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)) {
Method run
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function run()
{
// create permissions
$admin = Role::findOrCreate(UserRole::ADMIN, 'api');
$tutor = Role::findOrCreate(UserRole::TUTOR, 'api');
Similar blocks of code found in 2 locations. Consider refactoring. Open
<?php
namespace EscolaLms\Courses\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
- 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 103.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
<?php
namespace EscolaLms\Courses\Http\Requests;
use EscolaLms\Courses\Models\Lesson;
- 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 103.
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
Function cloneTopic
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function cloneTopic(Topic $topic): Model
{
$clonedTopicArray = $topic->replicate()->toArray();
unset($clonedTopicArray['order']);
/** @var Topic $clonedTopic */
- 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 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',