File UserOrganizationTrait.php
has 270 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* _ __ __ _____ _____ ___ ____ _____
* | | / // // ___//_ _// || __||_ _|
Method revokeOrganization
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function revokeOrganization($organization, $revokeIfHasChildren = true)
{
if (!($organization instanceof $this->organizationClass))
{
$class = $this->organizationClass;
Method createBaseOrganization
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
protected function createBaseOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '', $type = Organization::TYPE_ORGANIZATION)
Method createOrganization
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
Method createDepartment
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function createDepartment($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
Method setUpDepartment
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function setUpDepartment($name, $parent, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
Function revokeOrganization
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function revokeOrganization($organization, $revokeIfHasChildren = true)
{
if (!($organization instanceof $this->organizationClass))
{
$class = $this->organizationClass;
- 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 setUpOrganization
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function setUpOrganization($name, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
Function setUpBaseOrganization
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function setUpBaseOrganization($models)
{
$model = null;
$associatedModels = [];
if (is_array($models)) {
- 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 revokeOrganization() has an NPath complexity of 272. The configured NPath complexity threshold is 200. Open
public function revokeOrganization($organization, $revokeIfHasChildren = true)
{
if (!($organization instanceof $this->organizationClass))
{
$class = $this->organizationClass;
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method revokeOrganization() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function revokeOrganization($organization, $revokeIfHasChildren = true)
{
if (!($organization instanceof $this->organizationClass))
{
$class = $this->organizationClass;
- 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
The method revokeOrganization has a boolean flag argument $revokeIfHasChildren, which is a certain sign of a Single Responsibility Principle violation. Open
public function revokeOrganization($organization, $revokeIfHasChildren = 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 '292', column '23'). Open
throw new \Exception('Failed to set up.');
- 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 '\Yii' in method 'setUpOrganization'. Open
Yii::error($ex->getMessage(), __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 '\Yii' in method 'revokeOrganization'. Open
Yii::error($ex->getMessage(), __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 '\Yii' in method 'setUpDepartment'. Open
Yii::error($ex->getMessage(), __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
The parameter $gravatar_type is not named in camelCase. Open
public function createOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
return $this->createBaseOrganization($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description);
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $gravatar_type is not named in camelCase. Open
public function setUpOrganization($name, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
$accessChecker = Yii::$app->authManager;
if (!$accessChecker->checkAccess($this, (new SetUpOrganization)->name)) {
throw new InvalidParamException("You do not have permission to set up organization.");
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $gravatar_type is not named in camelCase. Open
public function setUpDepartment($name, $parent, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
if (!($parent instanceof $this->organizationClass)) {
throw new InvalidParamException('Invalid Parent Parameter.');
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $gravatar_type is not named in camelCase. Open
protected function createBaseOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '', $type = Organization::TYPE_ORGANIZATION)
{
$class = $this->organizationClass;
$profileConfig = [
'name' => $name,
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $gravatar_type is not named in camelCase. Open
public function createDepartment($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
return $this->createBaseOrganization($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description, Organization::TYPE_DEPARTMENT);
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Line exceeds 120 characters; contains 155 characters Open
return $this->createBaseOrganization($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description, Organization::TYPE_DEPARTMENT);
- Exclude checks
Line exceeds 120 characters; contains 161 characters Open
return $this->hasMany(get_class($this->getNoInitMember()), [$this->getNoInitMember()->memberAttribute => $this->guidAttribute])->inverseOf('memberUser');
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
$organization->type == Organization::TYPE_ORGANIZATION ? (new RevokeOrganization)->name : (new RevokeDepartment)->name,
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$models = $this->createOrganization($name, null, $nickname, $gravatar_type, $gravatar, $timezone, $description);
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
return $this->createBaseOrganization($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description);
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
return $this->getOfMembers()->andWhere(['role' => [(new DepartmentAdmin)->name, (new OrganizationAdmin)->name]]);
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
return $this->hasOne($this->organizationLimitClass, [$this->getNoInitOrganizationLimit()->createdByAttribute => $this->guidAttribute]);
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
$models = $this->createDepartment($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description);
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
return $this->hasMany($this->organizationClass, [$this->guidAttribute => $this->getNoInitMember()->createdByAttribute])->via('ofCreators');
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
public function createDepartment($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
- Exclude checks
Line exceeds 120 characters; contains 199 characters Open
protected function createBaseOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '', $type = Organization::TYPE_ORGANIZATION)
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
public function setUpOrganization($name, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
- Exclude checks
Line exceeds 120 characters; contains 151 characters Open
public function createOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
public function setUpDepartment($name, $parent, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
return $this->hasMany($this->organizationClass, [$this->guidAttribute => $this->getNoInitMember()->createdByAttribute])->via('ofAdministrators');
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
return $this->getOfMembers()->andWhere(['role' => [(new DepartmentCreator)->name, (new OrganizationCreator)->name]]);
- Exclude checks
Line exceeds 120 characters; contains 146 characters Open
return $this->hasMany($this->organizationClass, [$this->guidAttribute => $this->getNoInitMember()->createdByAttribute])->via('ofMembers');
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
$this,
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
foreach ($organizations as $org)
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if ($result instanceof \Exception){
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 16 Open
['organization' => $organization])) {
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Whitespace found at end of line Open
*
- Exclude checks
Expected 1 space after closing parenthesis; found 9 Open
if (!($organization instanceof $this->organizationClass))
- Exclude checks
Multi-line function call not indented correctly; expected 12 spaces but found 16 Open
$organization->type == Organization::TYPE_ORGANIZATION ? (new RevokeOrganization)->name : (new RevokeDepartment)->name,
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
['organization' => $organization])) {
- Exclude checks
The variable $gravatar_type is not named in camelCase. Open
public function setUpOrganization($name, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
$accessChecker = Yii::$app->authManager;
if (!$accessChecker->checkAccess($this, (new SetUpOrganization)->name)) {
throw new InvalidParamException("You do not have permission to set up organization.");
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $gravatar_type is not named in camelCase. Open
public function createOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
return $this->createBaseOrganization($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $gravatar_type is not named in camelCase. Open
public function createDepartment($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
return $this->createBaseOrganization($name, $parent, $nickname, $gravatar_type, $gravatar, $timezone, $description, Organization::TYPE_DEPARTMENT);
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $gravatar_type is not named in camelCase. Open
public function setUpDepartment($name, $parent, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '')
{
if (!($parent instanceof $this->organizationClass)) {
throw new InvalidParamException('Invalid Parent Parameter.');
}
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $gravatar_type is not named in camelCase. Open
protected function createBaseOrganization($name, $parent = null, $nickname = '', $gravatar_type = 0, $gravatar = '', $timezone = 'UTC', $description = '', $type = Organization::TYPE_ORGANIZATION)
{
$class = $this->organizationClass;
$profileConfig = [
'name' => $name,
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}