Method process
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
try {
$orderId = $message = '';
$responseType = 'success';
Function process
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
try {
$orderId = $message = '';
$responseType = 'success';
- 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 method process() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function process(App\Request $request)
{
try {
$orderId = $message = '';
$responseType = 'success';
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Missing class import via use statement (line '63', column '19'). Open
$response = new Vtiger_Response();
- 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 '43', column '16'). Open
throw new \App\Exceptions\AppException('LBL_NOT_FILLED_MANDATORY_FIELDS');
- 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 '37', column '17'). Open
throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');
- 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 '30', column '17'). Open
$order = new \App\YetiForce\Order();
- 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 '15'). Open
throw new \App\Exceptions\AppException($error);
- 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
Avoid assigning values to variables in if clauses and the like (line '47', column '8'). Open
public function process(App\Request $request)
{
try {
$orderId = $message = '';
$responseType = 'success';
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
throw new \App\Exceptions\AppException('LBL_NOT_FILLED_MANDATORY_FIELDS');
}
- 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 unused local variables such as '$mas'. Open
if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Call to method send
from undeclared class \App\YetiForce\Order
Open
$result = $order->send();
- Exclude checks
Call to method getId
from undeclared class \App\YetiForce\Order
Open
$orderId = $order->getId();
- Exclude checks
Call to method getError
from undeclared class \App\YetiForce\Order
Open
if ($error = $order->getError()) {
- Exclude checks
Call to method set
from undeclared class \App\YetiForce\Order
Open
$order->set($fieldName, $field->getDBValue($value));
- Exclude checks
Call to method setPackageId
from undeclared class \App\YetiForce\Order
Open
$order->setPackageId($request->getByType('packageId', \App\Purifier::ALNUM2));
- Exclude checks
Call to method getFieldInstances
from undeclared class \App\YetiForce\Order
Open
foreach ($order->getFieldInstances() as $field) {
- Exclude checks
Call to method __construct
from undeclared class \App\YetiForce\Order
Open
$order = new \App\YetiForce\Order();
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
if ($request->has($fieldName) && !$request->isEmpty($fieldName)) {
$value = $request->getRaw($fieldName);
if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {
throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');
}
- 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 Settings_YetiForce_Buy_Action extends Settings_Vtiger_Save_Action
- Exclude checks
The class Settings_YetiForce_Buy_Action is not named in CamelCase. Open
class Settings_YetiForce_Buy_Action extends Settings_Vtiger_Save_Action
{
/**
* Process user request.
*
- 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
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $request->getRaw($fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$order->set($fieldName, $field->getDBValue($value));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$responseType = 'error';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->has($fieldName) && !$request->isEmpty($fieldName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = $order->send();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$order->setPackageId($request->getByType('packageId', \App\Purifier::ALNUM2));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process user request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$order = new \App\YetiForce\Order();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($order->getFieldInstances() as $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$field->getUITypeModel()->validate($value, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param \App\Request $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldName = $field->getName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$responseType = 'error';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $request->getByType($fieldName, $field->get('purifyType'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($value && preg_match('/[^A-Za-zÀ-ž\W\d\s]+/u', (string) $value, $mas)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('LBL_NOT_FILLED_MANDATORY_FIELDS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($error = $order->getError()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $e->getDisplayMessage();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$message = $e->getMessage();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response = new Vtiger_Response();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$responseType = 'success';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException($error);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'message' => $message ?? '',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($result) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$orderId = $order->getId();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'orderId' => $orderId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->emit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws \App\Exceptions\NoPermitted
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Throwable $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('ERR_PLEASE_USE_LATIN_CHARACTERS');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\App\Exceptions\AppException $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$orderId = $message = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => $responseType,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'success' => $result ?? false,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Settings_YetiForce_Buy_Action" is not in camel caps format Open
class Settings_YetiForce_Buy_Action extends Settings_Vtiger_Save_Action
- Exclude checks