Showing 31 of 31 total issues
File Searchify.php
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
class Searchify extends Object
{
The class Searchify has an overall complexity of 58 which is very high. The configured complexity threshold is 50. Open
class Searchify extends Object
{
/**
* @var Indextank_Api
- Exclude checks
Method addPage
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addPage($record)
{
if (!$this->index instanceof \Indextank_Index) {
user_error(
_t(
Method index
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function index(SS_HTTPRequest $r)
{
$results = Searchify::inst()->search($r->requestVar('q'));
$resultStack = array();
Method addPages
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function addPages($records)
{
if (!$records->count()) {
return false;
}
Method discover
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function discover($record)
{
$config = \Config::inst()->get($record->ClassName, 'db');
$content = array(
Method removePage
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function removePage($record)
{
if (!$this->index instanceof \Indextank_Index) {
user_error(
_t(
Method setIndex
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setIndex($key)
{
$indexes = $this->getIndexList();
if (!isset($indexes[$key])) {
if (!$this->config()->make_index) {
Function discover
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function discover($record)
{
$config = \Config::inst()->get($record->ClassName, 'db');
$content = array(
- Read upRead up
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 addPages
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function addPages($records)
{
if (!$records->count()) {
return false;
}
- Read upRead up
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 property $allowed_actions is not named in camelCase. Open
class SearchifyPage_ControllerExtension extends Extension
{
private static $allowed_actions = array(
'SearchForm',
);
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
The class SearchifyPage_Controller is not named in CamelCase. Open
class SearchifyPage_Controller extends Page_Controller
{
private static $allowed_actions = array(
'index'
);
- 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
The class SearchifyPage_ControllerExtension is not named in CamelCase. Open
class SearchifyPage_ControllerExtension extends Extension
{
private static $allowed_actions = array(
'SearchForm',
);
- 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
The property $allowed_actions is not named in camelCase. Open
class SearchifyPage_Controller extends Page_Controller
{
private static $allowed_actions = array(
'index'
);
- Read upRead up
- Exclude checks
CamelCasePropertyName
Since: 0.2
It is considered best practice to use the camelCase notation to name attributes.
Example
class ClassName {
protected $property_name;
}
Source
Function indexAll
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function indexAll()
{
$pages = SiteTree::get();
if (!$pages) {
- Read upRead up
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
Missing class import via use statement (line '32', column '29'). Open
$this->client = new Indextank_Api($apiUrl);
- Read upRead up
- 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
Function index
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function index(SS_HTTPRequest $r)
{
$results = Searchify::inst()->search($r->requestVar('q'));
$resultStack = array();
- Read upRead up
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 onAfterPublish uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Searchify::inst()->removePage($record);
}
- 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 '$allowed_actions'. Open
private static $allowed_actions = array(
'index'
);
- 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 '$allowed_actions'. Open
private static $allowed_actions = array(
'SearchForm',
);
- 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++;
}
}