Function getStructure
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function getStructure(): array
{
$structure = [];
$moduleName = $this->recordModel->getModuleName();
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- 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 getStructure
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getStructure(): array
{
$structure = [];
$moduleName = $this->recordModel->getModuleName();
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
The method getStructure() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function getStructure(): array
{
$structure = [];
$moduleName = $this->recordModel->getModuleName();
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- 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 22 to the 15 allowed. Open
public function getStructure(): array
- 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 '31', column '14'). Open
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 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
Avoid assigning values to variables in if clauses and the like (line '63', column '7'). Open
public function getStructure(): array
{
$structure = [];
$moduleName = $this->recordModel->getModuleName();
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- 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 '\App\Language' in method 'getStructure'. Open
$structure[$blockName][$field['var_value']] = \App\Language::translate($field['label'], $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 '\App\Language' in method 'getStructure'. Open
$structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $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 '\App\Language' in method 'getStructure'. Open
$blockName = \App\Language::translate($blockName, $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 '\App\Privilege' in method 'getStructure'. Open
if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {
- 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\Language' in method 'getStructure'. Open
$structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $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 assigning values to variables in if clauses and the like (line '70', column '10'). Open
public function getStructure(): array
{
$structure = [];
$moduleName = $this->recordModel->getModuleName();
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- 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 '\App\Record' in method 'getStructure'. Open
if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {
- 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 '\Vtiger_Record_Model' in method 'checkPermission'. Open
$this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
- 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\Mail' in method 'checkPermission'. Open
if (!$this->recordModel || !($this->recordModel->isEditable() && \App\Mail::checkInternalMailClient())) {
- 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 '67', column '20'). Open
public function getStructure(): array
{
$structure = [];
$moduleName = $this->recordModel->getModuleName();
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- 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 'App\TextParser' in method 'getStructure'. Open
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- 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\Record' in method 'getStructure'. Open
if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {
- 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\Record' in method 'getStructure'. Open
$name = trim(\App\Record::getLabel($crmId));
- 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
Class extends undeclared class \App\Controller\Modal
Open
class Calendar_SendInvitationModal_View extends \App\Controller\Modal
- Exclude checks
Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
Open
$viewer->assign('RECORD_ID', $this->recordModel->getId());
- Exclude checks
Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
Open
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- Exclude checks
Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
Open
$this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
- Exclude checks
Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
Open
if ($invites = $this->recordModel->getInvities()) {
- Exclude checks
Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
Open
$moduleName = $this->recordModel->getModuleName();
- Exclude checks
Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
Open
if (!$this->recordModel || !($this->recordModel->isEditable() && \App\Mail::checkInternalMailClient())) {
- Exclude checks
Call to undeclared method \Calendar_SendInvitationModal_View::getViewer
Open
$viewer = $this->getViewer($request);
- Exclude checks
Call to method getInstanceByModel
from undeclared class \App\TextParser
(Did you mean class \Tests\App\TextParser) Open
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Calendar_SendInvitationModal_View extends \App\Controller\Modal
- Exclude checks
The class Calendar_SendInvitationModal_View is not named in CamelCase. Open
class Calendar_SendInvitationModal_View extends \App\Controller\Modal
{
/** {@inheritdoc} */
protected $pageTitle = 'LBL_SEND_CALENDAR';
/** {@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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('FIELDS', $this->getStructure());
- 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
$structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $modalIcon = 'yfi-send-invitation';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($invites = $this->recordModel->getInvities()) {
- 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
$viewer->assign('RECORD_ID', $this->recordModel->getId());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fields as $field) {
- 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
$textParser = App\TextParser::getInstanceByModel($this->recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $successBtn = 'LBL_SEND';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = $this->recordModel->getModuleName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$blockName = \App\Language::translate($blockName, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->view('Modals/SendInvitationModal.tpl', $request->getModule());
- 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 (($email = $invite['email'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$emails[] = $name ? "{$name} <{$email}>" : $email;
- 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
protected $pageTitle = 'LBL_SEND_CALENDAR';
- 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
* Gets structure.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
$structure[$blockName][$field['var_value']] = \App\Language::translate($field['label'], $moduleName);
- 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
if (!$this->recordModel || !($this->recordModel->isEditable() && \App\Mail::checkInternalMailClient())) {
- 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
Line exceeds 120 characters; contains 160 characters Open
$structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $moduleName);
- 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
public function getStructure(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$name = trim($invite['name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function checkPermission(App\Request $request)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $structure;
- 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
/** {@inheritdoc} */
- 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 ($textParser->getRelatedVariable('email', true) as $modules) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$emails = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($modules as $blockName => $fields) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$name = trim(\App\Record::getLabel($crmId));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
$this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());
- 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
$viewer = $this->getViewer($request);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$viewer->assign('EMAIL_FIELD_OPTION', $this->getStructure());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$structure[$blockName][$field['var_value']] = \App\Language::translate($field['label'], $moduleName);
- Exclude checks
Line exceeds 120 characters; contains 176 characters Open
if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$structure = [];
- 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 ($invites as $invite) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($emails) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Calendar_SendInvitationModal_View" is not in camel caps format Open
class Calendar_SendInvitationModal_View extends \App\Controller\Modal
- Exclude checks