Showing 114 of 187 total issues
Avoid using static access to class '\SilverStripe\Core\ClassInfo' in method 'findOrigin'. Open
$dataclasses = array_diff($dataclasses, array_values(ClassInfo::subclassesFor($dataclass)));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method resolveField uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$value = $this->component->getValue();
}
- Read upRead up
- Exclude checks
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 unused private fields such as '$table_name'. Open
private static $table_name = 'Solr_SearchSynonym';
- Read upRead up
- Exclude checks
UnusedPrivateField
Since: 0.2
Detects when a private field is declared and/or assigned a value, but not used.
Example
class Something
{
private static $FOO = 2; // Unused
private $i = 5; // Unused
private $j = 6;
public function addOne()
{
return $this->j++;
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield
Avoid unused private fields such as '$table_name'. Open
private static $table_name = 'Solr_SolrLog';
- Read upRead up
- Exclude checks
UnusedPrivateField
Since: 0.2
Detects when a private field is declared and/or assigned a value, but not used.
Example
class Something
{
private static $FOO = 2; // Unused
private $i = 5; // Unused
private $j = 6;
public function addOne()
{
return $this->j++;
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedprivatefield
The method doReindex() contains an exit expression. Open
exit(0);
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
getSuggestion accesses the super-global variable $_SERVER. Open
function getSuggestion()
{
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php')) {
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
getSuggestion accesses the super-global variable $_SERVER. Open
function getSuggestion()
{
if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php')) {
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
The variable $IDs is not named in camelCase. Open
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName(['Class', 'IDs']);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $IDs is not named in camelCase. Open
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName(['Class', 'IDs']);
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
XXX found Open
such as /select?qt=XXX
- Exclude checks
XXX found Open
such as /select?qt=XXX
- Exclude checks
TODO found Open
<item>TODO</item>
- Exclude checks
XXX found Open
such as /select?qt=XXX
- Exclude checks
XXX found Open
such as /select?qt=XXX
- Exclude checks