Method find
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function find($request, $match)
{
// check for topic
if (isset($match['topicId'])) {
$topicId = $match['topicId'];
Function remove
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function remove($request, $match)
{
if (isset($match['courseId'])) {
$courseId = $match['courseId'];
} else {
- 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 update
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function update($request, $match, $p)
{
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['modelId']);
// check topic
if (isset($match['topicId'])) {
- 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 get
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function get($request, $match)
{
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['courseId']);
// check topic
if (isset($match['topicId'])) {
- 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
Missing class import via use statement (line '66', column '23'). Open
$course = new ELearn_Course();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '67', column '26'). Open
$paginator = new Pluf_Paginator($course);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '69', column '24'). Open
$sql = new Pluf_SQL('topic=%s', array(
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '48', column '20'). Open
return new Pluf_HTTP_Response_Json($course);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '119', column '20'). Open
return new Pluf_HTTP_Response_Json($courseCopy);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '114', column '27'). Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $courseId . ') does not exist in topic with id (' . $topicId . ')');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '94', column '20'). Open
return new Pluf_HTTP_Response_Json($paginator->render_object());
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '135', column '27'). Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '139', column '28'). Open
$plufService = new Pluf_Views();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '45', column '27'). Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '29', column '28'). Open
$plufService = new Pluf_Views();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method remove uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$courseId = $request->REQUEST['courseId'];
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method create uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$topicId = $request->REQUEST['topic'];
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Define a constant instead of duplicating this literal ") does not exist in topic with id (" 3 times. Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "title" 3 times. Open
'title',
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "topicId" 14 times. Open
if (isset($match['topicId'])) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "ELearn_Course" 4 times. Open
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['courseId']);
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "ELearn_Topic" 4 times. Open
Pluf_Shortcuts_GetObjectOr404('ELearn_Topic', $topicId);
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "Course with id (" 3 times. Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "topic" 8 times. Open
$request->REQUEST['topic'] = $topicId;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "courseId" 4 times. Open
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['courseId']);
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Call to method __construct
from undeclared class \Pluf_SQL
Open
$sql = new Pluf_SQL('topic=%s', array(
- Exclude checks
Call to method loadFunction
from undeclared class \Pluf
Open
Pluf::loadFunction('ELearn_Shortcuts_NormalizeItemPerPage');
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Views
Open
$plufService = new Pluf_Views();
- Exclude checks
Return type of find()
is undeclared type \Pluf_HTTP_Response_Json
Open
public static function find($request, $match)
- Exclude checks
Reference to instance property forced_where
from undeclared class \Pluf_Paginator
Open
$paginator->forced_where = $sql;
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['modelId']);
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $courseId);
- Exclude checks
Parameter $request
has undeclared type \Pluf_HTTP_Request
Open
public static function create($request, $match, $p)
- Exclude checks
Reference to instance property REQUEST
from undeclared class \Pluf_HTTP_Request
Open
$request->REQUEST['topic'] = $topicId;
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
Pluf_Shortcuts_GetObjectOr404('ELearn_Topic', $topicId);
- Exclude checks
Call to method __construct
from undeclared class \Pluf_HTTP_Response_Json
Open
return new Pluf_HTTP_Response_Json($course);
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Exception_DoesNotExist
Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $courseId . ') does not exist in topic with id (' . $topicId . ')');
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Views
Open
$plufService = new Pluf_Views();
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$topic = Pluf_Shortcuts_GetObjectOr404('ELearn_Topic', $topicId);
- Exclude checks
Call to method setFromRequest
from undeclared class \Pluf_Paginator
Open
$paginator->setFromRequest($request);
- Exclude checks
Call to method render_object
from undeclared class \Pluf_Paginator
Open
return new Pluf_HTTP_Response_Json($paginator->render_object());
- Exclude checks
Call to method updateObject
from undeclared class \Pluf_Views
Open
return $plufService->updateObject($request, $match, $p);
- Exclude checks
Return type of create()
is undeclared type \Pluf_HTTP_Response
Open
public static function create($request, $match, $p)
- Exclude checks
Reference to instance property list_filters
from undeclared class \Pluf_Paginator
Open
$paginator->list_filters = array(
- Exclude checks
Call to method createObject
from undeclared class \Pluf_Views
Open
return $plufService->createObject($request, $match, $p);
- Exclude checks
Call to method __construct
from undeclared class \Pluf_HTTP_Response_Json
Open
return new Pluf_HTTP_Response_Json($paginator->render_object());
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$courseCopy = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $courseId);
- Exclude checks
Call to method loadFunction
from undeclared class \Pluf
Open
Pluf::loadFunction('Pluf_Shortcuts_GetObjectOr404');
- Exclude checks
Call to method configure
from undeclared class \Pluf_Paginator
Open
$paginator->configure(array(), $search_fields, $sort_fields);
- Exclude checks
Reference to instance property REQUEST
from undeclared class \Pluf_HTTP_Request
Open
$topicId = $request->REQUEST['topic'];
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Exception_DoesNotExist
Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Exclude checks
Call to method __construct
from undeclared class \Pluf_HTTP_Response_Json
Open
return new Pluf_HTTP_Response_Json($courseCopy);
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['courseId']);
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Paginator
Open
$paginator = new Pluf_Paginator($course);
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$topic = Pluf_Shortcuts_GetObjectOr404('ELearn_Topic', $topicId);
- Exclude checks
Call to method __construct
from undeclared class \Pluf_Exception_DoesNotExist
Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Exclude checks
Parameter $request
has undeclared type \Pluf_HTTP_Request
Open
public static function find($request, $match)
- Exclude checks
Reference to instance property REQUEST
from undeclared class \Pluf_HTTP_Request
Open
$topicId = $request->REQUEST['topicId'];
- Exclude checks
Call to undeclared function \Pluf_Shortcuts_GetObjectOr404()
Open
$topic = Pluf_Shortcuts_GetObjectOr404('ELearn_Topic', $topicId);
- Exclude checks
Reference to instance property REQUEST
from undeclared class \Pluf_HTTP_Request
Open
} elseif (isset($request->REQUEST['topicId'])) {
- Exclude checks
Reference to instance property items_per_page
from undeclared class \Pluf_Paginator
Open
$paginator->items_per_page = ELearn_Shortcuts_NormalizeItemPerPage($request);
- Exclude checks
Similar blocks of code found in 3 locations. Consider refactoring. Open
public static function remove($request, $match)
{
if (isset($match['courseId'])) {
$courseId = $match['courseId'];
} else {
- 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 214.
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 static function update($request, $match, $p)
{
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['modelId']);
// check topic
if (isset($match['topicId'])) {
- 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 194.
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 static function get($request, $match)
{
$course = Pluf_Shortcuts_GetObjectOr404('ELearn_Course', $match['courseId']);
// check topic
if (isset($match['topicId'])) {
- 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 161.
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
public static function create($request, $match, $p)
{
// check topic
if (isset($match['topicId'])) {
$topicId = $match['topicId'];
- 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 106.
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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class ELearn_Views_Course
- Exclude checks
Avoid variables with short names like $p. Configured minimum length is 3. Open
public static function update($request, $match, $p)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $p. Configured minimum length is 3. Open
public static function create($request, $match, $p)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 5 and the first side effect is on line 2. Open
<?php
- Exclude checks
The class ELearn_Views_Course is not named in CamelCase. Open
class ELearn_Views_Course
{
// *******************************************************************
// Course of Topic
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Line exceeds 120 characters; contains 147 characters Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $courseId . ') does not exist in topic with id (' . $topicId . ')');
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
throw new Pluf_Exception_DoesNotExist('Course with id (' . $course->id . ') does not exist in topic with id (' . $topic->id . ')');
- Exclude checks
Whitespace found at end of line Open
* @param array $match
- Exclude checks
Whitespace found at end of line Open
* @param Pluf_HTTP_Request $request
- Exclude checks
Usage of ELSE IF is discouraged; use ELSEIF instead Open
} else if (isset($request->REQUEST['topicId'])) {
- Exclude checks
Usage of ELSE IF is discouraged; use ELSEIF instead Open
} else if (isset($request->REQUEST['topic'])) {
- Exclude checks
Usage of ELSE IF is discouraged; use ELSEIF instead Open
} else if (isset($request->REQUEST['topic'])) {
- Exclude checks
Class name "ELearn_Views_Course" is not in camel caps format Open
class ELearn_Views_Course
- Exclude checks
Whitespace found at end of line Open
* @param Pluf_HTTP_Request $request
- Exclude checks
Whitespace found at end of line Open
* @param array $match
- Exclude checks
Whitespace found at end of line Open
* @param array $p
- Exclude checks
Expected 1 newline at end of file; 0 found Open
}
- Exclude checks
The variable $sort_fields is not named in camelCase. Open
public static function find($request, $match)
{
// check for topic
if (isset($match['topicId'])) {
$topicId = $match['topicId'];
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $sort_fields is not named in camelCase. Open
public static function find($request, $match)
{
// check for topic
if (isset($match['topicId'])) {
$topicId = $match['topicId'];
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $search_fields is not named in camelCase. Open
public static function find($request, $match)
{
// check for topic
if (isset($match['topicId'])) {
$topicId = $match['topicId'];
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $search_fields is not named in camelCase. Open
public static function find($request, $match)
{
// check for topic
if (isset($match['topicId'])) {
$topicId = $match['topicId'];
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}