Method find
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function find($request, $match)
{
if (isset($match['secureId'])) {
$order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
} else {
Missing class import via use statement (line '79', column '23'). Open
throw new Pluf_HTTP_Error404('Order with id ' . $order->id . ' has no history with id ' . $orderHistory->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 '25', column '34'). Open
$pag->forced_where = new Pluf_SQL('`order_id`=' . $order->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 '24', column '39'). Open
$pag = new Pluf_Paginator(new Shop_OrderHistory());
- 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 '24', column '20'). Open
$pag = new Pluf_Paginator(new Shop_OrderHistory());
- 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 get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['orderId']);
Shop_Views_Order::checkAccess($request, $order);
}
- 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
Avoid using static access to class 'Shop_Views_Order' in method 'find'. Open
Shop_Views_Order::checkAccess($request, $order);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method find uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$order = Pluf_Shortcuts_GetObjectOr404('Shop_Order', $match['orderId']);
Shop_Views_Order::checkAccess($request, $order);
}
- 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
Avoid using static access to class 'Shop_Views_Order' in method 'get'. Open
Shop_Views_Order::checkAccess($request, $order);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "action" 3 times. Open
'action',
- 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 "state" 3 times. Open
'state',
- 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 "Shop_Order" 4 times. Open
$order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
- 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 "secureId" 4 times. Open
if (isset($match['secureId'])) {
- 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.
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Shop_Views_OrderHistory
- Exclude checks
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 6 and the first side effect is on line 2. Open
<?php
- Exclude checks
The class Shop_Views_OrderHistory is not named in CamelCase. Open
class Shop_Views_OrderHistory
{
/**
* Returns history of order
- 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
Expected 1 blank line at end of file; 2 found Open
}
- Exclude checks
The closing brace for the class must go on the next line after the body Open
}
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
throw new Pluf_HTTP_Error404('Order with id ' . $order->id . ' has no history with id ' . $orderHistory->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
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
Class name "Shop_Views_OrderHistory" is not in camel caps format Open
class Shop_Views_OrderHistory
- Exclude checks
The variable $sort_fields is not named in camelCase. Open
public static function find($request, $match)
{
if (isset($match['secureId'])) {
$order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
} else {
- 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)
{
if (isset($match['secureId'])) {
$order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
} else {
- 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)
{
if (isset($match['secureId'])) {
$order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
} else {
- 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)
{
if (isset($match['secureId'])) {
$order = Shop_Shortcuts_GetObjectBySecureIdOr404('Shop_Order', $match['secureId']);
} else {
- 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();
}
}