Showing 113 of 113 total issues
File ExportImportService.php
has 353 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace EscolaLms\CoursesImportExport\Services;
use EscolaLms\Categories\Models\Category;
The class ExportImportService has an overall complexity of 67 which is very high. The configured complexity threshold is 50. Open
class ExportImportService implements ExportImportServiceContract
{
private CourseRepositoryContract $courseRepository;
private LessonRepositoryContract $lessonRepository;
private TopicRepositoryContract $topicRepository;
- Exclude checks
ExportImportService
has 22 functions (exceeds 20 allowed). Consider refactoring. Open
class ExportImportService implements ExportImportServiceContract
{
private CourseRepositoryContract $courseRepository;
private LessonRepositoryContract $lessonRepository;
private TopicRepositoryContract $topicRepository;
Avoid excessively long class names like EscolaLmsCoursesImportExportServiceProvider. Keep class name length under 40. Open
class EscolaLmsCoursesImportExportServiceProvider extends ServiceProvider
{
public $singletons = [
ExportImportServiceContract::class => ExportImportService::class,
CloneCourseServiceContract::class => CloneCourseService::class,
- Read upRead up
- Exclude checks
LongClassName
Since: 2.9
Detects when classes or interfaces are declared with excessively long names.
Example
class ATooLongClassNameThatHintsAtADesignProblem {
}
interface ATooLongInterfaceNameThatHintsAtADesignProblem {
}
Source https://phpmd.org/rules/naming.html#longclassname
Avoid excessively long variable names like $topicResourceRepository. Keep variable name length under 20. Open
TopicResourceRepositoryContract $topicResourceRepository,
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Function fixAssetPaths
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function fixAssetPaths(): array
{
$results = [];
$results = $results + $this->fixPath('image_path');
$results = $results + $this->fixPath('video_path');
- 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 createTopicFromImport
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function createTopicFromImport(array $topicData, string $dirFullPath, int $courseId): ?Model
{
if (!isset($topicData['topicable_type'])) {
return null;
}
The parameter $course_id is not named in camelCase. Open
public function clone(int $course_id, CloneCourseAPIRequest $request): JsonResponse
{
$this->cloneCourseService->clone($request->getCourse());
return $this->sendSuccess(__('Course cloning started. This may take a while.'));
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $course_id is not named in camelCase. Open
public function export(int $course_id, GetCourseExportAPIRequest $request): JsonResponse;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $course_id is not named in camelCase. Open
public function clone(int $course_id, CloneCourseAPIRequest $request): JsonResponse;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $course_id is not named in camelCase. Open
public function export(int $course_id, GetCourseExportAPIRequest $request): JsonResponse
{
$export = $this->exportImportService->export($course_id);
return $this->sendResponse($export, __('Export created'));
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Function createTopicFromImport
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function createTopicFromImport(array $topicData, string $dirFullPath, int $courseId): ?Model
{
if (!isset($topicData['topicable_type'])) {
return null;
}
- 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
The class ExportImportService has a coupling between objects value of 27. Consider to reduce the number of dependencies under 13. Open
class ExportImportService implements ExportImportServiceContract
{
private CourseRepositoryContract $courseRepository;
private LessonRepositoryContract $lessonRepository;
private TopicRepositoryContract $topicRepository;
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
CourseRepositoryContract $courseRepository,
LessonRepositoryContract $lessonRepository,
TopicRepositoryContract $topicRepository,
TopicResourceRepositoryContract $topicResourceRepository,
CategoriesRepositoryContract $categoriesRepository
Function createLessonFromImport
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function createLessonFromImport(array $lessonData, string $dirFullPath): Model
{
$lessonValidator = Validator::make($lessonData, Lesson::$rules);
/** @var Lesson $lesson */
$lesson = $this->lessonRepository->create($lessonValidator->validate());
- 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
Blank line found at end of control structure Open
- Exclude checks
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line Open
{
- Exclude checks
Function createCourseFromImport
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function createCourseFromImport(array $courseData, string $dirFullPath): Model
{
unset($courseData['author_id']);
$courseData = $this->addFilesToArrayBasedOnPath($courseData, $dirFullPath);
- 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 false;
The method export has a boolean flag argument $withUrl, which is a certain sign of a Single Responsibility Principle violation. Open
public function export($courseId, bool $withUrl = true): string;
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}