midasplatform/Midas

View on GitHub
core/tests/controllers/api/RestCallMethodsTestCase.php

Summary

Maintainability
F
1 wk
Test Coverage

Function exerciseInvalidCases has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    protected function exerciseInvalidCases($method, $validUser, $invalidUsers, $requiredParams)
    {
        // test all invalid users with valid params
        foreach ($invalidUsers as $invalidUser) {
            $this->resetAll();
Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 3 hrs to fix

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 class RestCallMethodsTestCase has an overall complexity of 51 which is very high. The configured complexity threshold is 50.
Open

class RestCallMethodsTestCase extends ControllerTestCase
{
    /** set up tests */
    public function setUp()
    {

File RestCallMethodsTestCase.php has 299 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*=========================================================================
 Midas Server
 Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
 All rights reserved.
Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 3 hrs to fix

Method exerciseInvalidCases has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function exerciseInvalidCases($method, $validUser, $invalidUsers, $requiredParams)
    {
        // test all invalid users with valid params
        foreach ($invalidUsers as $invalidUser) {
            $this->resetAll();
Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 2 hrs to fix

Function initializePrivacyStatus has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    protected function initializePrivacyStatus($testFolders, $testItems, $desiredPrivacyStatus)
    {
        /** @var GroupModel $groupModel */
        $groupModel = MidasLoader::loadModel('Group');
        $anonymousGroup = $groupModel->load(MIDAS_GROUP_ANONYMOUS_KEY);
Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 1 hr to fix

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 initializePrivacyStatus has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function initializePrivacyStatus($testFolders, $testItems, $desiredPrivacyStatus)
    {
        /** @var GroupModel $groupModel */
        $groupModel = MidasLoader::loadModel('Group');
        $anonymousGroup = $groupModel->load(MIDAS_GROUP_ANONYMOUS_KEY);
Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 1 hr to fix

Method assertPolicygroupExistence has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function assertPolicygroupExistence($testFolders, $testItems, $group, $policyCode)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 1 hr to fix

Method assertPolicyuserExistence has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function assertPolicyuserExistence($testFolders, $testItems, $user, $policyCode)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 1 hr to fix

Function assertPolicygroupExistence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    protected function assertPolicygroupExistence($testFolders, $testItems, $group, $policyCode)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 45 mins to fix

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 assertPolicyuserExistence has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    protected function assertPolicyuserExistence($testFolders, $testItems, $user, $policyCode)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 45 mins to fix

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 assertPolicygroupNonexistence has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function assertPolicygroupNonexistence($testFolders, $testItems, $group)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 25 mins to fix

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 assertPolicyuserNonexistence has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    protected function assertPolicyuserNonexistence($testFolders, $testItems, $user)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Minor
Found in core/tests/controllers/api/RestCallMethodsTestCase.php - About 25 mins to fix

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 exerciseInvalidCases() has an NPath complexity of 215. The configured NPath complexity threshold is 200.
Open

    protected function exerciseInvalidCases($method, $validUser, $invalidUsers, $requiredParams)
    {
        // test all invalid users with valid params
        foreach ($invalidUsers as $invalidUser) {
            $this->resetAll();

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 exerciseInvalidCases() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
Open

    protected function exerciseInvalidCases($method, $validUser, $invalidUsers, $requiredParams)
    {
        // test all invalid users with valid params
        foreach ($invalidUsers as $invalidUser) {
            $this->resetAll();

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

Missing class import via use statement (line '442', column '31').
Open

                    throw new Exception('left most param state is 3');

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 '415', column '31').
Open

                    throw new Exception('left most param state is invalid value: '.$state);

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 'MidasLoader' in method 'assertPrivacyStatus'.
Open

        $itempolicygroupModel = MidasLoader::loadModel('Itempolicygroup');

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 'MidasLoader' in method 'assertPolicygroupNonexistence'.
Open

        $folderModel = MidasLoader::loadModel('Folder');

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 'MidasLoader' in method 'assertPolicygroupNonexistence'.
Open

        $itemModel = MidasLoader::loadModel('Item');

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 'MidasLoader' in method 'assertPolicyuserExistence'.
Open

        $folderpolicyuserModel = MidasLoader::loadModel('Folderpolicyuser');

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 'MidasLoader' in method 'initializePrivacyStatus'.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 'MidasLoader' in method 'assertPolicygroupExistence'.
Open

        $itemModel = MidasLoader::loadModel('Item');

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 assertPolicyuserExistence uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $message = $item->getName().' does not have any policy for user '.$user->getUserId(
                    ).' policy '.$policyCode;
                $this->assertTrue(false, $message);
            }

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 'MidasLoader' in method 'assertPolicyuserNonexistence'.
Open

        $itempolicyuserModel = MidasLoader::loadModel('Itempolicyuser');

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 'MidasLoader' in method 'initializePrivacyStatus'.
Open

        $itempolicygroupModel = MidasLoader::loadModel('Itempolicygroup');

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 initializePrivacyStatus uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $policyDao = $folderpolicygroupModel->getPolicy($anonymousGroup, $folder);
                    $folderpolicygroupModel->delete($policyDao);
                }

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 'MidasLoader' in method 'assertPolicyuserExistence'.
Open

        $itempolicyuserModel = MidasLoader::loadModel('Itempolicyuser');

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 'MidasLoader' in method 'initializePrivacyStatus'.
Open

        $groupModel = MidasLoader::loadModel('Group');

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 assertPolicygroupExistence uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $message = $folder->getName().' does not have any policy for group '.$group->getGroupId(
                    ).' policy '.$policyCode;
                $this->assertTrue(false, $message);
            }

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 'MidasLoader' in method 'assertPolicyuserNonexistence'.
Open

        $folderpolicyuserModel = MidasLoader::loadModel('Folderpolicyuser');

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 'MidasLoader' in method 'assertPrivacyStatus'.
Open

        $folderModel = MidasLoader::loadModel('Folder');

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 'MidasLoader' in method 'assertPrivacyStatus'.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 'MidasLoader' in method 'assertPolicygroupExistence'.
Open

        $folderModel = MidasLoader::loadModel('Folder');

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 'MidasLoader' in method 'assertPolicygroupExistence'.
Open

        $itempolicygroupModel = MidasLoader::loadModel('Itempolicygroup');

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 assertPolicygroupExistence uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $message = $item->getName().' does not have any policy for group '.$group->getGroupId(
                    ).' policy '.$policyCode;
                $this->assertTrue(false, $message);
            }

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 'MidasLoader' in method 'assertPolicyuserExistence'.
Open

        $itemModel = MidasLoader::loadModel('Item');

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 exerciseInvalidCases uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    throw new Exception('left most param state is 3');
                }

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

The method assertPolicyuserExistence uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $message = $folder->getName().' does not have any policy for user '.$user->getUserId(
                    ).' policy '.$policyCode;
                $this->assertTrue(false, $message);
            }

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 'MidasLoader' in method 'assertPolicyuserNonexistence'.
Open

        $itemModel = MidasLoader::loadModel('Item');

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 'MidasLoader' in method 'assertPrivacyStatus'.
Open

        $itemModel = MidasLoader::loadModel('Item');

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 'MidasLoader' in method 'assertPolicygroupNonexistence'.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 'MidasLoader' in method 'assertPolicygroupNonexistence'.
Open

        $itempolicygroupModel = MidasLoader::loadModel('Itempolicygroup');

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 initializePrivacyStatus uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $policyDao = $itempolicygroupModel->getPolicy($anonymousGroup, $item);
                    $itempolicygroupModel->delete($policyDao);
                }

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 'MidasLoader' in method 'assertPolicygroupExistence'.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 'MidasLoader' in method '_loginAsUser'.
Open

        $userApiModel = MidasLoader::loadModel('Userapi');

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 'MidasLoader' in method 'assertPolicyuserExistence'.
Open

        $folderModel = MidasLoader::loadModel('Folder');

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 'MidasLoader' in method 'assertPolicyuserNonexistence'.
Open

        $folderModel = MidasLoader::loadModel('Folder');

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

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    protected function assertPolicyuserExistence($testFolders, $testItems, $user, $policyCode)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 3 other locations - About 1 day to fix
core/tests/controllers/api/RestCallMethodsTestCase.php on lines 201..240
modules/api/tests/controllers/CallMethodsTestCase.php on lines 194..233
modules/api/tests/controllers/CallMethodsTestCase.php on lines 274..312

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 364.

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

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    protected function assertPolicygroupExistence($testFolders, $testItems, $group, $policyCode)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 3 other locations - About 1 day to fix
core/tests/controllers/api/RestCallMethodsTestCase.php on lines 281..319
modules/api/tests/controllers/CallMethodsTestCase.php on lines 194..233
modules/api/tests/controllers/CallMethodsTestCase.php on lines 274..312

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 364.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        while (array_sum($requiredParamStates) < $allTwosSum) {
            $this->resetAll();
            $this->params['token'] = $this->_loginAsUser($validUser);
            $this->params['method'] = $method;
            $skipTestCase = false;
Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 1 other location - About 1 day to fix
modules/api/tests/controllers/CallMethodsTestCase.php on lines 387..439

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 355.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    protected function initializePrivacyStatus($testFolders, $testItems, $desiredPrivacyStatus)
    {
        /** @var GroupModel $groupModel */
        $groupModel = MidasLoader::loadModel('Group');
        $anonymousGroup = $groupModel->load(MIDAS_GROUP_ANONYMOUS_KEY);
Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 1 other location - About 1 day to fix
modules/api/tests/controllers/CallMethodsTestCase.php on lines 109..154

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 288.

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

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    protected function assertPolicygroupNonexistence($testFolders, $testItems, $group)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 3 other locations - About 7 hrs to fix
core/tests/controllers/api/RestCallMethodsTestCase.php on lines 325..354
modules/api/tests/controllers/CallMethodsTestCase.php on lines 239..268
modules/api/tests/controllers/CallMethodsTestCase.php on lines 318..347

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 244.

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

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    protected function assertPolicyuserNonexistence($testFolders, $testItems, $user)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 3 other locations - About 7 hrs to fix
core/tests/controllers/api/RestCallMethodsTestCase.php on lines 246..275
modules/api/tests/controllers/CallMethodsTestCase.php on lines 239..268
modules/api/tests/controllers/CallMethodsTestCase.php on lines 318..347

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 244.

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

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

    protected function assertPrivacyStatus($testFolders, $testItems, $expectedPrivacyStatus)
    {
        /** @var FolderModel $folderModel */
        $folderModel = MidasLoader::loadModel('Folder');

Severity: Major
Found in core/tests/controllers/api/RestCallMethodsTestCase.php and 1 other location - About 4 hrs to fix
modules/api/tests/controllers/CallMethodsTestCase.php on lines 159..188

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 172.

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

Further Reading

Avoid excessively long variable names like $folderpolicygroupModel. Keep variable name length under 20.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 $expectedPrivacyStatus. Keep variable name length under 20.
Open

    protected function assertPrivacyStatus($testFolders, $testItems, $expectedPrivacyStatus)

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 $folderpolicygroupModel. Keep variable name length under 20.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 $folderpolicygroupModel. Keep variable name length under 20.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 $folderpolicyuserModel. Keep variable name length under 20.
Open

        $folderpolicyuserModel = MidasLoader::loadModel('Folderpolicyuser');

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 $folderpolicygroupModel. Keep variable name length under 20.
Open

        $folderpolicygroupModel = MidasLoader::loadModel('Folderpolicygroup');

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 $folderpolicyuserModel. Keep variable name length under 20.
Open

        $folderpolicyuserModel = MidasLoader::loadModel('Folderpolicyuser');

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

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class RestCallMethodsTestCase extends ControllerTestCase

Method name "_callRestApi" should not be prefixed with an underscore to indicate visibility
Open

    protected function _callRestApi($method, $path, $sessionUser = null)

Method name "_assertStatusOk" should not be prefixed with an underscore to indicate visibility
Open

    protected function _assertStatusOk($resp)

Method name "_assertStatusFail" should not be prefixed with an underscore to indicate visibility
Open

    protected function _assertStatusFail($resp)

Method name "_loginAsNormalUser" should not be prefixed with an underscore to indicate visibility
Open

    protected function _loginAsNormalUser()

Method name "_loginAsUser" should not be prefixed with an underscore to indicate visibility
Open

    protected function _loginAsUser($userDao)

Method name "_loginAsAdministrator" should not be prefixed with an underscore to indicate visibility
Open

    protected function _loginAsAdministrator()

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ).' policy '.$policyCode;

The method _assertStatusOk is not named in camelCase.
Open

    protected function _assertStatusOk($resp)
    {
        $this->assertNotEquals($resp, false);
        $this->assertContains($resp['status'], array(200, 201));
        $this->assertTrue(isset($resp['body']->data));

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

The method _loginAsNormalUser is not named in camelCase.
Open

    protected function _loginAsNormalUser()
    {
        $usersFile = $this->loadData('User', 'default');
        $userDao = $this->User->load($usersFile[0]->getKey());

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

The method _loginAsUser is not named in camelCase.
Open

    protected function _loginAsUser($userDao)
    {
        /** @var UserapiModel $userApiModel */
        $userApiModel = MidasLoader::loadModel('Userapi');
        $userApiModel->createDefaultApiKey($userDao);

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

The method _loginAsAdministrator is not named in camelCase.
Open

    protected function _loginAsAdministrator()
    {
        $usersFile = $this->loadData('User', 'default');
        $userDao = $this->User->load($usersFile[2]->getKey());

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

The method _callRestApi is not named in camelCase.
Open

    protected function _callRestApi($method, $path, $sessionUser = null)
    {
        $this->request->setMethod($method);
        $this->dispatchUrl('/rest'.$path, $sessionUser, false, false);
        $responseStatus = $this->_response->getHttpResponseCode();

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

The method _assertStatusFail is not named in camelCase.
Open

    protected function _assertStatusFail($resp)
    {
        $this->assertNotEquals($resp, false);
        $this->assertContains($resp['status'], array(400, 401, 405));
    }

CamelCaseMethodName

Since: 0.2

It is considered best practice to use the camelCase notation to name methods.

Example

class ClassName {
    public function get_name() {
    }
}

Source

There are no issues that match your filters.

Category
Status