The method getAll has a boolean flag argument $onlyActive, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getAll($onlyActive = true)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '74', column '18'). Open
$query = (new App\Db\Query())
- 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 '75', column '31'). Open
->select(['member' => new \yii\db\Expression("CONCAT('{$type}',':',{$tableName}.{$index})")])
- 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 '103', column '24'). Open
$recordModel = new Settings_Roles_Record_Model();
- 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 '108', column '24'). Open
$recordModel = new Settings_Groups_Record_Model();
- 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 'Users_Record_Model' in method 'getDetailViewUrl'. Open
$recordModel = Users_Record_Model::getCleanInstance($type);
- 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_Roles_Record_Model' in method 'getAll'. Open
$allRoles = Settings_Roles_Record_Model::getAll();
- 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 getAllByTypeForGroup uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$queryAll = $query;
}
- 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 'Users_Record_Model' in method 'getAll'. Open
$allUsers = Users_Record_Model::getAll($onlyActive);
- 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_Groups_Record_Model' in method 'getAll'. Open
$allGroups = Settings_Groups_Record_Model::getAll();
- 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
Saw unextractable annotation for comment '* @return <number> Id'</number>
Open
* @return <Number> Id
- Exclude checks
Argument 1 (value)
is string
but \Users_Record_Model::setId()
takes int
defined at /code/modules/Vtiger/models/Record.php:67
Open
$recordModel->setId($recordId);
- Exclude checks
Argument 1 (id)
is string
but \Settings_Groups_Record_Model::setId()
takes int
defined at /code/modules/Settings/Groups/models/Record.php:37
Open
$recordModel->setId($recordId);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$query = (new App\Db\Query())
- Exclude checks
Call to method __construct
from undeclared class \yii\db\Expression
Open
->select(['member' => new \yii\db\Expression("CONCAT('{$type}',':',{$tableName}.{$index})")])
- Exclude checks
Saw unextractable annotation for comment '* @return <array> - Array of Settings_Groups_Record_Model instances'</array>
Open
* @return <Array> - Array of Settings_Groups_Record_Model instances
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
foreach ($allRoles as $roleId => $roleModel) {
$qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_ROLES, $roleId);
$member = new self();
$members[self::MEMBER_TYPE_ROLES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());
- 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 148.
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_Groups_Member_Model extends \App\Base
- Exclude checks
The class Settings_Groups_Member_Model is not named in CamelCase. Open
class Settings_Groups_Member_Model extends \App\Base
{
const MEMBER_TYPE_USERS = 'Users';
const MEMBER_TYPE_GROUPS = 'Groups';
const MEMBER_TYPE_ROLES = 'Roles';
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function getQualifiedId($type, $id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function getIdComponentsFromQualifiedId($id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
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
[$tableName, $index] = $indexes;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* return string url.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set('roleid', $recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return explode(':', $id);
- 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
self::MEMBER_TYPE_ROLES => ['vtiger_group2role', 'roleid'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryAll = $query;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return <Array> - Array of Settings_Groups_Record_Model instances
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const MEMBER_TYPE_GROUPS = 'Groups';
- 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 int $groupId
- 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
[$type, $recordId] = self::getIdComponentsFromQualifiedId($this->getId());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = new Settings_Roles_Record_Model();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $recordModel->getEditViewUrl();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const MEMBER_TYPE_ROLE_AND_SUBORDINATES = 'RoleAndSubordinates';
- 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
foreach ($tables as $type => $indexes) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryAll->union($query, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $queryAll ? $queryAll->column() : [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getDetailViewUrl()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'Groups':
- 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
{
- 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
self::MEMBER_TYPE_USERS => ['vtiger_users2group', 'userid'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::MEMBER_TYPE_GROUPS => ['vtiger_group2grouprel', 'containsgroupid'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(["{$tableName}.groupid" => $groupId]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($queryAll) {
- 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 static function getIdComponentsFromQualifiedId($id)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null !== $type) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryAll = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get the Group Name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $type . ':' . $id;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->select(['member' => new \yii\db\Expression("CONCAT('{$type}',':',{$tableName}.{$index})")])
- 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
$recordModel->setId($recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'Roles':
- 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
$tables = isset($tables[$type]) ? [$type => $tables[$type]] : [];
- 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 'Users':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($allRoles as $roleId => $roleModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$members[self::MEMBER_TYPE_ROLE_AND_SUBORDINATES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getQualifiedId($type, $id)
- 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
Line exceeds 120 characters; contains 131 characters Open
$members[self::MEMBER_TYPE_USERS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $userModel->getName());
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
$members[self::MEMBER_TYPE_GROUPS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $groupModel->getName());
- Exclude checks
Line exceeds 120 characters; contains 131 characters Open
$members[self::MEMBER_TYPE_ROLES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
$members[self::MEMBER_TYPE_ROLE_AND_SUBORDINATES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->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
return $this->get('id');
- 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
return $recordModel->getDetailViewUrl();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'RoleAndSubordinates':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->setId($recordId);
- 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
const MEMBER_TYPE_ROLES = 'Roles';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return <Number> Id
- 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
* Gets members by type.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getAllByTypeForGroup(int $groupId, ?string $type = null): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get Detail View Url of this member
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Users_Record_Model::getCleanInstance($type);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $recordModel->getDetailViewUrl();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$members[self::MEMBER_TYPE_USERS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $userModel->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
$tables = [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from($tableName)
- 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
switch ($type) {
- 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
$qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_GROUPS, $groupId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$member = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get the Qualified Id of the Group Member.
- 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 getId()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $this->get('name');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $onlyActive
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getAll($onlyActive = true)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allUsers = Users_Record_Model::getAll($onlyActive);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const MEMBER_TYPE_USERS = 'Users';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function 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
self::MEMBER_TYPE_ROLE_AND_SUBORDINATES => ['vtiger_group2rs', 'roleandsubid']
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query = (new App\Db\Query())
- 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
$recordModel = new Settings_Groups_Record_Model();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get all the groups.
- 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
$allRoles = Settings_Roles_Record_Model::getAll();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$members = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_ROLE_AND_SUBORDINATES, $roleId);
- 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
foreach ($allUsers as $userId => $userModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$members[self::MEMBER_TYPE_ROLES][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $roleModel->getName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $members;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $type
- 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
}
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_ROLES, $roleId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$qualifiedId = self::getQualifiedId(self::MEMBER_TYPE_USERS, $userId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$member = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$member = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$allGroups = Settings_Groups_Record_Model::getAll();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($allGroups as $groupId => $groupModel) {
- 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
$member = new self();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$members[self::MEMBER_TYPE_GROUPS][$qualifiedId] = $member->set('id', $qualifiedId)->set('name', $groupModel->getName());
- Exclude checks
Class name "Settings_Groups_Member_Model" is not in camel caps format Open
class Settings_Groups_Member_Model extends \App\Base
- Exclude checks