process accesses the super-global variable $_FILES. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Function process
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- 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 process
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
The method process() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
$qualifiedModule = $request->getModule(false);
$viewer = $this->getViewer($request);
- 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
Refactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed. Open
public function process(App\Request $request)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '59', column '16'). Open
throw new \App\Exceptions\Security('ERR_ILLEGAL_WATERMARK_IMAGE');
- 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 '21', column '15'). Open
throw new \App\Exceptions\Security('ERR_ILLEGAL_FILE');
- 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 using static access to class 'Settings_PDF_Record_Model' in method 'process'. Open
$pdfModel = Settings_PDF_Record_Model::getCleanInstance();
- 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
Avoid using static access to class '\App\Log' in method 'process'. Open
\App\Log::trace('Start ' . __METHOD__);
- 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
Avoid using static access to class 'Settings_PDF_Record_Model' in method 'process'. Open
Settings_PDF_Record_Model::save($pdfModel, 'import');
- 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
Avoid using static access to class '\App\Fields\File' in method 'process'. Open
$imageInstance = \App\Fields\File::loadFromInfo([
'content' => base64_decode($base64Image),
'path' => $imagePath,
'name' => 'watermark_image',
'validateAllCodeInjection' => true,
- 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
Avoid using static access to class 'Settings_PDF_Record_Model' in method 'process'. Open
Settings_PDF_Record_Model::save($pdfModel, 8);
- 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
Avoid using static access to class '\App\Fields\File' in method 'process'. Open
$fileInstance = \App\Fields\File::loadFromRequest($_FILES['imported_xml']);
- 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
Avoid using static access to class 'App\Purifier' in method 'process'. Open
$pdfModel->set($columnKey, App\Purifier::purifyHtml((string) $columnValue));
- 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
Avoid using static access to class '\App\Log' in method 'process'. Open
\App\Log::trace('End ' . __METHOD__);
- 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
Avoid using static access to class 'App\Purifier' in method 'process'. Open
$pdfModel->set($columnKey, App\Purifier::purify((string) $columnValue));
- 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 "watermark_image" 3 times. Open
case 'watermark_image':
- 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 trace
from undeclared class \App\Log
Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('UPLOAD', true);
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Start ' . __METHOD__);
- Exclude checks
Call to undeclared method \Vtiger_Viewer::assign
Open
$viewer->assign('RECORDID', $pdfModel->getId());
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_PDF_Import_View extends Settings_Vtiger_Index_View
- Exclude checks
The class Settings_PDF_Import_View is not named in CamelCase. Open
class Settings_PDF_Import_View extends Settings_Vtiger_Index_View
{
public function process(App\Request $request)
{
\App\Log::trace('Start ' . __METHOD__);
- 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
switch ($columnKey) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$imagePath = (string) $columnValue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Start ' . __METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$fileInstance->validate() || 'xml' !== $fileInstance->getExtension(true)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer = $this->getViewer($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\Security('ERR_ILLEGAL_FILE');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$imagePath = '';
- 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
public function process(App\Request $request)
- 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
$base64Image = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$base64Image = (string) $columnValue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qualifiedModule = $request->getModule(false);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Settings_PDF_Record_Model::save($pdfModel, 'import');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel = Settings_PDF_Record_Model::getCleanInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$xml = simplexml_load_file($fileInstance->getPath());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set($columnKey, App\Purifier::purifyHtml((string) $columnValue));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileInstance = \App\Fields\File::loadFromRequest($_FILES['imported_xml']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fieldsValue as $fieldValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'watermark_image':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set($columnKey, App\Purifier::purify((string) $columnValue));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'path' => $imagePath,
- 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
$viewer->assign('UPLOAD', true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'header_content':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$imageInstance = \App\Fields\File::loadFromInfo([
- 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
case 'body_content':
- 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
$targetDir = Settings_PDF_Module_Model::$uploadPath;
- 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
$pdfModel->set('watermark_image', $newFilePath);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('RECORDID', $pdfModel->getId());
- 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
$viewer->assign('QUALIFIED_MODULE', $qualifiedModule);
- 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
default:
- 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
case 'imageblob':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'content' => base64_decode($base64Image),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return array_merge($this->checkAndConvertCssStyles([
- 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
foreach ($fieldValue as $columnKey => $columnValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'name' => 'watermark_image',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\Security('ERR_ILLEGAL_WATERMARK_IMAGE');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$newFilePath = $targetDir . $pdfModel->getId() . '.' . $imageInstance->getExtension();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'modules.Settings.' . $request->getModule() . '.Edit',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($xml as $fieldsValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'footer_content':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($pdfModel->getId() && $imagePath && $base64Image) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Settings_PDF_Record_Model::save($pdfModel, 8);
- 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 ($request->has('upload') && $request->getBoolean('upload')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set($columnKey, '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'validateAllCodeInjection' => true,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('End ' . __METHOD__);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$imageInstance->validateAndSecure('image')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
file_put_contents($newFilePath, $imageInstance->getContents());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
]), parent::getHeaderCss($request));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getHeaderCss(App\Request $request)
- 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
$viewer->view('Import.tpl', $qualifiedModule);
- Exclude checks
Class name "Settings_PDF_Import_View" is not in camel caps format Open
class Settings_PDF_Import_View extends Settings_Vtiger_Index_View
- Exclude checks