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.
- Create a ticketCreate a ticket
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()
{
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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()
{
- Create a ticketCreate a ticket
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');
- Create a ticketCreate a ticket
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';
- Create a ticketCreate a ticket
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';
- Create a ticketCreate a ticket
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;
- Create a ticketCreate a ticket
Missing class import via use statement (line '676', column '31'). Open
$resultItem = new ItemDao();
- Read upRead up
- Create a ticketCreate a ticket
- 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 'MidasLoader' in method 'testGetAllScores'. Open
$folderModel = MidasLoader::loadModel('Folder');
- Read upRead up
- Create a ticketCreate a ticket
- 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 'Zend_Registry' in method 'setUp'. Open
$configDatabase = Zend_Registry::get('configDatabase');
- Read upRead up
- Create a ticketCreate a ticket
- 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 'MidasLoader' in method '_loginUsingApiKey'. Open
$userApiModel = MidasLoader::loadModel('Userapi');
- Read upRead up
- Create a ticketCreate a ticket
- 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 'MidasLoader' in method '_loginUsingApiKeyAsAdmin'. Open
$userApiModel = MidasLoader::loadModel('Userapi');
- Read upRead up
- Create a ticketCreate a ticket
- 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 'MidasLoader' in method 'testGetAllScores'. Open
$itemModel = MidasLoader::loadModel('Item');
- Read upRead up
- Create a ticketCreate a ticket
- 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 'Zend_Registry' in method 'setUp'. Open
$db = Zend_Registry::get('dbAdapter');
- Read upRead up
- Create a ticketCreate a ticket
- 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 'MidasLoader' in method 'testGetAllScores'. Open
$dashboardModel = MidasLoader::loadModel('Dashboard', 'validation');
- Read upRead up
- Create a ticketCreate a ticket
- 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
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;
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
- Read upRead up
- Create a ticketCreate a ticket
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Validation_ApiComponentControllerTest extends ControllerTestCase
- Create a ticketCreate a ticket
- Exclude checks
The class Validation_ApiComponentControllerTest is not named in CamelCase. Open
class Validation_ApiComponentControllerTest extends ControllerTestCase
{
/** set up tests */
public function setUp()
{
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = Zend_Registry::get('dbAdapter');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Method name "_assertStatusFailed" should not be prefixed with an underscore to indicate visibility Open
private function _assertStatusFailed($resp)
- Create a ticketCreate a ticket
- Exclude checks
Method name "_callJsonApi" should not be prefixed with an underscore to indicate visibility Open
private function _callJsonApi($sessionUser = null)
- Create a ticketCreate a ticket
- Exclude checks
Method name "_loginUsingApiKey" should not be prefixed with an underscore to indicate visibility Open
private function _loginUsingApiKey()
- Create a ticketCreate a ticket
- Exclude checks
Method name "_loginUsingApiKeyAsAdmin" should not be prefixed with an underscore to indicate visibility Open
private function _loginUsingApiKeyAsAdmin()
- Create a ticketCreate a ticket
- Exclude checks
Method name "_assertStatusOk" should not be prefixed with an underscore to indicate visibility Open
private function _assertStatusOk($resp)
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
"SELECT setval('validation_dashboard_dashboard_id_seq', (SELECT MAX(dashboard_id) FROM validation_dashboard)+1);"
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 157 characters Open
"SELECT setval('validation_dashboard2folder_dashboard2folder_id_seq', (SELECT MAX(dashboard2folder_id) FROM validation_dashboard2folder)+1);"
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 182 characters Open
"SELECT setval('validation_dashboard2scalarresult_dashboard2scalarresult_id_seq', (SELECT MAX(dashboard2scalarresult_id) FROM validation_dashboard2scalarresult)+1);"
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
"SELECT setval('validation_scalarresult_scalarresult_id_seq', (SELECT MAX(scalarresult_id) FROM validation_scalarresult)+1);"
- Create a ticketCreate a ticket
- Exclude checks
Class name "Validation_ApiComponentControllerTest" is not in camel caps format Open
class Validation_ApiComponentControllerTest extends ControllerTestCase
- Create a ticketCreate a ticket
- Exclude checks
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');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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());
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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());
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}