post accesses the super-global variable $_FILES. Open
public function post(App\Request $request)
{
$moduleName = $request->getModule(false);
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
$fieldModel = $moduleModel->getFieldInstanceByName('image');
- 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 post
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function post(App\Request $request)
{
$moduleName = $request->getModule(false);
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
$fieldModel = $moduleModel->getFieldInstanceByName('image');
- 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 post
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function post(App\Request $request)
{
$moduleName = $request->getModule(false);
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
$fieldModel = $moduleModel->getFieldInstanceByName('image');
Missing class import via use statement (line '67', column '20'). 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 '32', column '13'). Open
throw new \App\Exceptions\NoPermitted('Not Acceptable', 406);
- 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 post uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Settings_Vtiger_Tracker_Model::addBasic('save');
$attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, 0);
$result = [
'field' => $fieldModel->getName(),
- 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 assigning values to variables in if clauses and the like (line '62', column '20'). Open
public function post(App\Request $request)
{
$moduleName = $request->getModule(false);
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
$fieldModel = $moduleModel->getFieldInstanceByName('image');
- 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
Avoid using static access to class 'Settings_Vtiger_Tracker_Model' in method 'post'. Open
Settings_Vtiger_Tracker_Model::addBasic('delete');
- 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_Vtiger_Module_Model' in method 'post'. Open
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
- 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_Vtiger_Tracker_Model' in method 'post'. Open
Settings_Vtiger_Tracker_Model::addDetail(['key' => $key], ['key' => '']);
- 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_Vtiger_Tracker_Model' in method 'post'. Open
Settings_Vtiger_Tracker_Model::addBasic('save');
- 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 assigning values to variables in if clauses and the like (line '51', column '9'). Open
public function post(App\Request $request)
{
$moduleName = $request->getModule(false);
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
$fieldModel = $moduleModel->getFieldInstanceByName('image');
- 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
Avoid using static access to class 'Settings_Vtiger_Tracker_Model' in method 'post'. Open
Settings_Vtiger_Tracker_Model::addDetail(['key' => ''], ['key' => implode(',', $keys)]);
- 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 unused parameters such as '$request'. Open
public function get(App\Request $request)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Call to undeclared method \Settings_Vtiger_Module_Model::getFieldInstanceByName
Open
$fieldModel = $moduleModel->getFieldInstanceByName('image');
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Settings_Media_Images_File extends Vtiger_Basic_File
- Exclude checks
The class Settings_Media_Images_File is not named in CamelCase. Open
class Settings_Media_Images_File extends Vtiger_Basic_File
{
use \App\Controller\Traits\SettingsPermission;
/** {@inheritdoc} */
- 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
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
use \App\Controller\Traits\SettingsPermission;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Settings_Vtiger_Tracker_Model::addBasic('delete');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $fileType = 'image';
- 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 postCheckPermission(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
}
- 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
'module' => $fieldModel->getModuleName(),
- 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\NoPermitted('Not Acceptable', 406);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->isAjax()) {
- 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
$attach = $fieldModel->getUITypeModel()->uploadTempFile($_FILES, 0);
- 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
if ($result = $fieldModel->getUITypeModel()->removeImage($key)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Settings_Vtiger_Tracker_Model::addDetail(['key' => $key], ['key' => '']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function get(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->checkPermission($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleModel = Settings_Vtiger_Module_Model::getInstance($moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$result = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->getBoolean('remove')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($attach && $keys = array_column($attach, 'key')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$response->setResult($result);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get attachment.
- 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
$moduleName = $request->getModule(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
public function post(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
$key = $request->getByType('key', \App\Purifier::ALNUM);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $storageName = 'public_html/Media/Images';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Settings_Vtiger_Tracker_Model::addBasic('save');
- 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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel = $moduleModel->getFieldInstanceByName('image');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'field' => $fieldModel->getName(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'attach' => $attach,
- 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
Settings_Vtiger_Tracker_Model::addDetail(['key' => ''], ['key' => implode(',', $keys)]);
- 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
$response = new Vtiger_Response();
- Exclude checks
Class name "Settings_Media_Images_File" is not in camel caps format Open
class Settings_Media_Images_File extends Vtiger_Basic_File
- Exclude checks