Model
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class Model implements \JsonSerializable
{
// Flags
const COUNT_ONLY = 1;
Function factoryObjectCache
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
{
$schema = $schema ?: Schema::get(static::getNamespace());
list(,$table) = $schema->guessContext($classOrTable ?: get_called_class());
$namespace = $schema->namespace;
- 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
File Model.php
has 263 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Automatorm\Orm;
use Automatorm\Exception;
Method factoryObjectCache
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
{
$schema = $schema ?: Schema::get(static::getNamespace());
list(,$table) = $schema->guessContext($classOrTable ?: get_called_class());
$namespace = $schema->namespace;
Function dataClearCache
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
final public function dataClearCache()
{
$modelschema = $this->_data->getModel();
// Clean out cached column data
- 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
Method factory
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
Function factory
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
{
// Figure out the base class and table we need based on current context
$schema = $schema ?: Schema::get(static::getNamespace());
list($class, $table) = $schema->guessContext($classOrTablename ?: get_called_class());
- 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 factoryObjectCache() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
{
$schema = $schema ?: Schema::get(static::getNamespace());
list(,$table) = $schema->guessContext($classOrTable ?: get_called_class());
$namespace = $schema->namespace;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
Model::$instance[$namespace][$table][$row['id']] = $obj;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
$collection[] = Model::$instance[$namespace][$table][$id];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
if (isset(Model::$instance[$namespace][$table][$id])) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
if (!$obj = isset(Model::$instance[$namespace][$table][$row['id']]) ? Model::$instance[$namespace][$table][$row['id']] : false) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
if (isset(Model::$instance[$namespace][$table][$ids])) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
Model::$instance[$this->namespace][$this->table][strtolower(get_called_class())][$this->id] = $this;
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
if (!$obj = isset(Model::$instance[$namespace][$table][$row['id']]) ? Model::$instance[$namespace][$table][$row['id']] : false) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$instance' which will lead to PHP notices. Open
return Model::$instance[$namespace][$table][$ids];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Missing class import via use statement (line '314', column '23'). Open
throw new \BadMethodCallException("Method does not exist ({$var})", 0, $e);
- 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
Avoid assigning values to variables in if clauses and the like (line '123', column '18'). Open
final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
{
// Figure out the base class and table we need based on current context
$schema = $schema ?: Schema::get(static::getNamespace());
list($class, $table) = $schema->guessContext($classOrTablename ?: get_called_class());
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid unused local variables such as '$class'. Open
list($class, $table) = $schema->guessContext($classOrTablename ?: get_called_class());
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Saw an @param annotation for options,
but it was not found in the param list of function countAll(array|mixed[] $where = null) : \Automatorm\Orm\Collection|int
Open
* @param mixed[] $options Options to pass: limit => int, offeset => int, sort => "column direction"
- Exclude checks
Doc-block of $ids
in getAll
is phpdoc param type int[]
which is not a permitted replacement of the nullable param type ?array
declared in the signature ('?T' should be documented as 'T|null' or '?T') Open
* @param int[] $ids Ids of rows
- Exclude checks
Found a return statement with a value in the implementation of the magic method \Automatorm\Orm\Model::__wakeup,
expected void return type Open
public function __wakeup()
- Exclude checks
Doc-block of countAll
contains declared return type \Automatorm\Orm\Collection
which is incompatible with the return type int
declared in the signature Open
* @return \Automatorm\Orm\Collection
- Exclude checks
Assigning array[][][]
to property but \Automatorm\Orm\Model::$instance
is object[][][]
Open
static::$instance[$namespace][$table][$id] = [];
- Exclude checks
The property $_data is not named in camelCase. Open
class Model implements \JsonSerializable
{
// Flags
const COUNT_ONLY = 1;
- 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
Property name "$_data" should not be prefixed with an underscore to indicate visibility Open
protected $_data; // Container for the Model_Data object for this row. Used for both internal and external __get access.
- Exclude checks
Method name "_init" should not be prefixed with an underscore to indicate visibility Open
protected function _init()
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
// Call Model objects _init() function - this is to avoid recursion issues with object's natural constructor and the cache above
- Exclude checks
Line exceeds 120 characters; contains 134 characters Open
final public static function factory($where, $classOrTablename = null, $schema = null, array $options = [], $singleResult = false)
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
protected static $instance; // An internal store of created objects so that objects for each row only get created once
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
if (!$obj = isset(Model::$instance[$namespace][$table][$row['id']]) ? Model::$instance[$namespace][$table][$row['id']] : false) {
- Exclude checks
Line exceeds 120 characters; contains 173 characters Open
$foreignkeys = (array) $modelschema['one-to-one'] + (array) $modelschema['one-to-many'] + (array) $modelschema['many-to-many'] + (array) $modelschema['many-to-one'];
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
// If a special property method exists, then in effect the property exists, even if it hasn't been materialised yet.
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
// Return an empty Model_Data object for this class/table so that a new object can be constructed (and a new row entered in the table).
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
protected $_data; // Container for the Model_Data object for this row. Used for both internal and external __get access.
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
// Dynamic object properties - Prefer properties set on the model object over column data from the db (Model_Data object)
- Exclude checks
Line exceeds 120 characters; contains 121 characters Open
// We have a data object, call replacement constructor after storing in the cache list (to prevent recursion)
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
final public static function factoryObjectCache($ids, $classOrTable = null, Schema $schema = null, $forceRefresh = false)
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
// The real constructor is marked final as the normal constructor can cause infinite loops when combined with Class::get();
- Exclude checks
The method _init is not named in camelCase. Open
protected function _init()
{
}
- Read upRead up
- 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() {
}
}