midasplatform/Midas

View on GitHub
modules/validation/tests/controllers/ApiComponentControllerTest.php

Summary

Maintainability
F
6 days
Test Coverage

File ApiComponentControllerTest.php has 578 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: Major
Found in modules/validation/tests/controllers/ApiComponentControllerTest.php - About 1 day to fix

The class Validation_ApiComponentControllerTest has 19 public methods. Consider refactoring Validation_ApiComponentControllerTest to keep number of public methods under 10.
Open

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

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Validation_ApiComponentControllerTest has 25 functions (exceeds 20 allowed). Consider refactoring.
Open

class Validation_ApiComponentControllerTest extends ControllerTestCase
{
    /** set up tests */
    public function setUp()
    {
Severity: Minor
Found in modules/validation/tests/controllers/ApiComponentControllerTest.php - About 2 hrs to fix

Method testGetAllScores has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function testGetAllScores()
    {
        // Acquire the dashboard from the database
        /** @var Validation_DashboardModel $dashboardModel */
        $dashboardModel = MidasLoader::loadModel('Dashboard', 'validation');
Severity: Major
Found in modules/validation/tests/controllers/ApiComponentControllerTest.php - About 2 hrs to fix

Method testGetScores has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function testGetScores()
    {
        // Add a result folder
        $this->params['token'] = $this->_loginUsingApiKey();
        $this->params['method'] = 'midas.validation.addresultfolder';
Severity: Minor
Found in modules/validation/tests/controllers/ApiComponentControllerTest.php - About 1 hr to fix

Method testGetSetScalarResult has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function testGetSetScalarResult()
    {
        // Add a result folder
        $this->params['token'] = $this->_loginUsingApiKey();
        $this->params['method'] = 'midas.validation.addresultfolder';
Severity: Minor
Found in modules/validation/tests/controllers/ApiComponentControllerTest.php - About 1 hr to fix

Method testGetResults has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function testGetResults()
    {
        $this->params['token'] = $this->_loginUsingApiKey();
        $this->params['method'] = 'midas.validation.addresultfolder';
        $this->params['dashboard_id'] = 1;
Severity: Minor
Found in modules/validation/tests/controllers/ApiComponentControllerTest.php - About 1 hr to fix

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

            $resultItem = new ItemDao();

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 'testGetAllScores'.
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 'Zend_Registry' in method 'setUp'.
Open

        $configDatabase = Zend_Registry::get('configDatabase');

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 '_loginUsingApiKey'.
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 '_loginUsingApiKeyAsAdmin'.
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 'testGetAllScores'.
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 'Zend_Registry' in method 'setUp'.
Open

        $db = Zend_Registry::get('dbAdapter');

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 'testGetAllScores'.
Open

        $dashboardModel = MidasLoader::loadModel('Dashboard', 'validation');

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 2 locations. Consider refactoring.
Open

    public function testSetFoldersWithInvalidFolders()
    {
        $this->params['token'] = $this->_loginUsingApiKeyAsAdmin();
        $this->params['method'] = 'midas.validation.settestingfolder';
        $this->params['dashboard_id'] = 1;
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 332..360

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

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 2 locations. Consider refactoring.
Open

    public function testSetFoldersAsNonAdmin()
    {
        $this->params['token'] = $this->_loginUsingApiKey();
        $this->params['method'] = 'midas.validation.settestingfolder';
        $this->params['dashboard_id'] = 1;
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 366..394

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

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 3 locations. Consider refactoring.
Open

    public function testSetTruthFolder()
    {
        $this->params['token'] = $this->_loginUsingApiKeyAsAdmin();
        $this->params['method'] = 'midas.validation.settruthfolder';
        $this->params['dashboard_id'] = 1;
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 234..253
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 256..275

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

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 3 locations. Consider refactoring.
Open

    public function testSetTrainingFolder()
    {
        $this->params['token'] = $this->_loginUsingApiKeyAsAdmin();
        $this->params['method'] = 'midas.validation.settrainingfolder';
        $this->params['dashboard_id'] = 1;
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 234..253
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 278..297

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

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 3 locations. Consider refactoring.
Open

    public function testSetTestingFolder()
    {
        $this->params['token'] = $this->_loginUsingApiKeyAsAdmin();
        $this->params['method'] = 'midas.validation.settestingfolder';
        $this->params['dashboard_id'] = 1;
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 256..275
modules/validation/tests/controllers/ApiComponentControllerTest.php on lines 278..297

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

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

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

class Validation_ApiComponentControllerTest extends ControllerTestCase

The class Validation_ApiComponentControllerTest is not named in CamelCase.
Open

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

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 $db. Configured minimum length is 3.
Open

        $db = Zend_Registry::get('dbAdapter');

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

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

    private function _assertStatusFailed($resp)

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

    private function _callJsonApi($sessionUser = null)

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

    private function _loginUsingApiKey()

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

    private function _loginUsingApiKeyAsAdmin()

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

    private function _assertStatusOk($resp)

Line exceeds 120 characters; contains 129 characters
Open

                "SELECT setval('validation_dashboard_dashboard_id_seq', (SELECT MAX(dashboard_id) FROM validation_dashboard)+1);"

Line exceeds 120 characters; contains 157 characters
Open

                "SELECT setval('validation_dashboard2folder_dashboard2folder_id_seq', (SELECT MAX(dashboard2folder_id) FROM validation_dashboard2folder)+1);"

Line exceeds 120 characters; contains 182 characters
Open

                "SELECT setval('validation_dashboard2scalarresult_dashboard2scalarresult_id_seq', (SELECT MAX(dashboard2scalarresult_id) FROM  validation_dashboard2scalarresult)+1);"

Line exceeds 120 characters; contains 141 characters
Open

                "SELECT setval('validation_scalarresult_scalarresult_id_seq', (SELECT MAX(scalarresult_id) FROM validation_scalarresult)+1);"

Class name "Validation_ApiComponentControllerTest" is not in camel caps format
Open

class Validation_ApiComponentControllerTest extends ControllerTestCase

The method _assertStatusOk is not named in camelCase.
Open

    private function _assertStatusOk($resp)
    {
        $this->assertNotEquals($resp, false);
        $this->assertEquals($resp->message, '');
        $this->assertEquals($resp->stat, 'ok');

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 _callJsonApi is not named in camelCase.
Open

    private function _callJsonApi($sessionUser = null)
    {
        $this->dispatchUrl($this->webroot.'api/json', $sessionUser);

        return json_decode($this->getBody());

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 _loginUsingApiKeyAsAdmin is not named in camelCase.
Open

    private function _loginUsingApiKeyAsAdmin()
    {
        $usersFile = $this->loadData('User', 'default');
        $userDao = $this->User->load($usersFile[0]->getKey());
        $userDao->setAdmin(1);

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 _assertStatusFailed is not named in camelCase.
Open

    private function _assertStatusFailed($resp)
    {
        $this->assertEquals($resp->stat, 'fail');
        $this->assertEquals($resp->code, -1);
    }

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 _loginUsingApiKey is not named in camelCase.
Open

    private function _loginUsingApiKey()
    {
        $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

There are no issues that match your filters.

Category
Status