Method applySystemUserSettings
has 145 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function applySystemUserSettings($detailed, $action)
{
$this->addLeftTable('gems__systemuser_setup', ['gsf_id_user' => 'gsus_id_user'], 'gsus');
$this->resetOrder();
File StaffModel.php
has 395 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* The staff model
*
Method applySettings
has 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function applySettings($detailed, $action)
{
$this->resetOrder();
$dbLookup = $this->util->getDbLookup();
Method _addLoginSettings
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _addLoginSettings($editing)
{
if ($this->currentUser->hasPrivilege('pr.staff.see.all') || (! $editing)) {
// Select organization
$options = $this->util->getDbLookup()->getOrganizations();
Function applySettings
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function applySettings($detailed, $action)
{
$this->resetOrder();
$dbLookup = $this->util->getDbLookup();
- 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 applyOwnAccountEdit
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function applyOwnAccountEdit()
{
$noscript = new \MUtil_Validate_NoScript();
$this->set('gsf_id_user', 'elementClass', 'None');
Function _addLoginSettings
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
protected function _addLoginSettings($editing)
{
if ($this->currentUser->hasPrivilege('pr.staff.see.all') || (! $editing)) {
// Select organization
$options = $this->util->getDbLookup()->getOrganizations();
- 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
Function save
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function save(array $newValues, array $filter = null, array $saveTables = null)
{
//First perform a save
$savedValues = parent::save($newValues, $filter, $saveTables);
- 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 applySettings() has 118 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function applySettings($detailed, $action)
{
$this->resetOrder();
$dbLookup = $this->util->getDbLookup();
- Exclude checks
The method applySystemUserSettings() has 168 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function applySystemUserSettings($detailed, $action)
{
$this->addLeftTable('gems__systemuser_setup', ['gsf_id_user' => 'gsus_id_user'], 'gsus');
$this->resetOrder();
- Exclude checks
The class Gems_Model_StaffModel has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13. Open
class Gems_Model_StaffModel extends \Gems_Model_JoinModel
{
/**
*
* @var \Gems_User_Organization
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Avoid unused parameters such as '$detailed'. Open
public function applySystemUserSettings($detailed, $action)
- 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
Avoid unused parameters such as '$name'. Open
public function __construct($name = 'staff')
- 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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (1 == count($defaultStaffDefinitions)) {
reset($defaultStaffDefinitions);
$this->set('gul_user_class',
'default', key($defaultStaffDefinitions),
'elementClass', 'Hidden',
- 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 144.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (1 == count($defaultStaffDefinitions)) {
reset($defaultStaffDefinitions);
$this->set('gul_user_class',
'default', key($defaultStaffDefinitions),
'elementClass', 'Hidden',
- 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 144.
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
Avoid excessively long variable names like $defaultStaffDefinitions. Keep variable name length under 20. Open
$defaultStaffDefinitions = $this->loader->getUserLoader()->getAvailableStaffDefinitions();
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $defaultStaffDefinitions. Keep variable name length under 20. Open
$defaultStaffDefinitions = $this->loader->getUserLoader()->getAvailableStaffDefinitions();
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $allowedRespondentGroups. Keep variable name length under 20. Open
$allowedRespondentGroups = $dbLookup->getAllowedRespondentGroups();
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $defaultStaffDefinition. Keep variable name length under 20. Open
protected $defaultStaffDefinition = \Gems_User_UserLoader::USER_STAFF;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}