Avoid using static access to class '\App\Version' in method 'testLibraryVersion'. Open
$appVersion = \App\Version::get($lib['name']);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Settings_ModuleManager_Library_Model' in method 'testLibraryVersion'. Open
$libs = \Settings_ModuleManager_Library_Model::getAll();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Settings_ModuleManager_Library_Model' in method 'testLibraryVersion'. Open
\Settings_ModuleManager_Library_Model::downloadAll();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "version.php" 3 times. Open
$this->assertFileExists($lib['dir'] . 'version.php', 'File does not exist: ' . $lib['dir'] . 'version.php');
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Call to undeclared method \Tests\Base\F_Library::assertTrue
Open
$this->assertTrue($appVersion == $libVersion, "Wrong library version: $name, library version: $libVersion, config version: $appVersion");
- Exclude checks
Call to undeclared method \Tests\Base\F_Library::assertFileExists
Open
$this->assertFileExists($lib['dir'] . 'version.php', 'File does not exist: ' . $lib['dir'] . 'version.php');
- Exclude checks
The class F_Library is not named in CamelCase. Open
class F_Library extends \Tests\Base
{
/**
* Testing library versions.
*/
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Spaces must be used to indent lines; tabs are not allowed Open
$libVersions = require $lib['dir'] . 'version.php';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$libs = \Settings_ModuleManager_Library_Model::getAll();
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
$this->assertTrue($appVersion == $libVersion, "Wrong library version: $name, library version: $libVersion, config version: $appVersion");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\Settings_ModuleManager_Library_Model::downloadAll();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Testing library versions.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function testLibraryVersion()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertTrue($appVersion == $libVersion, "Wrong library version: $name, library version: $libVersion, config version: $appVersion");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$appVersion = \App\Version::get($lib['name']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertFileExists($lib['dir'] . 'version.php', 'File does not exist: ' . $lib['dir'] . 'version.php');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($libs as $name => $lib) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$libVersion = $libVersions['version'];
- Exclude checks
Class name "F_Library" is not in camel caps format Open
class F_Library extends \Tests\Base
- Exclude checks