File Data.php
has 576 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace Automatorm\Orm;
use Automatorm\Exception;
use Automatorm\Database\SqlString;
Data
has 39 functions (exceeds 20 allowed). Consider refactoring. Open
class Data
{
protected $data = []; // Data from columns on this table
protected $external = []; // Links to foreign key objects
Method groupJoinM2M
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function groupJoinM2M(Collection $collection, $var, $where, $countOnly = false)
{
$results = new Collection();
$proto = $collection[0]->_data;
Method commit
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function commit()
{
// Determine the type of SQL instruction to run
if ($this->delete) {
$mode = 'delete';
Function __get
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function &__get($var)
{
/* This property is a native database column, return it */
if (isset($this->data[$var])) {
return $this->data[$var];
- 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 join
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function join($var, array $where = [])
{
if (array_key_exists($var, $this->external)) {
if ($this->external[$var] instanceof Collection) {
return $this->external[$var]->filter($where);
- 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 joinCount
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function joinCount($var, $where = [])
{
if (!is_null($this->external[$var]) && !$this->external[$var] instanceof Collection) {
return 1;
}
- 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 duplicate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function duplicate($cloneExternalProps = false, Model $newParent = null)
{
$clone = clone $this;
$clone->new = true;
$clone->delete = 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
Function __set
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function __set($var, $value)
{
// Cannot change data if it is locked (i.e. it is attached to a Model object)
if ($this->locked) {
throw new Exception\Model('MODEL_DATA:SET_WHEN_LOCKED', array($var, $value));
- 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
Avoid too many return
statements within this method. Open
return static::groupJoinM2M($collection, $var, $where, $onlyCount);
Avoid too many return
statements within this method. Open
return $this->joinM2M($var, $where);
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $this->joinM21($var);
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return new Collection();
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $this->joinM21($var, true);
Avoid too many return
statements within this method. Open
return $this->joinM2M($var, $where, true);
Avoid too many return
statements within this method. Open
return $this->join12M($var, $where, true);
Avoid too many return
statements within this method. Open
return $this->join12M($var, $where);
Avoid too many return
statements within this method. Open
return null;
Function setManyToManyData
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function setManyToManyData($var, $value)
{
$this->updateExternal[$var] = true;
if (is_null($value)) {
- 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 commit
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function commit()
{
// Determine the type of SQL instruction to run
if ($this->delete) {
$mode = 'delete';
- 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 groupJoinM2M
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected static function groupJoinM2M(Collection $collection, $var, $where, $countOnly = false)
{
$results = new Collection();
$proto = $collection[0]->_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
Function __isset
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function __isset($var)
{
// Is it already set in local array?
if (array_key_exists($var, $this->data)) {
return true;
- 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 groupJoin12M
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected static function groupJoin12M(Collection $collection, $var, $where, $countOnly = false)
{
$proto = $collection[0]->_data;
$table = $proto->model['one-to-many'][$var]['table'];
- 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
Avoid using undefined variables such as '$external' which will lead to PHP notices. Open
$external[$obj->$column][] = $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 '$external' which will lead to PHP notices. Open
$obj->_data->external[$var] = new Collection((array) $external[$obj->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
Missing class import via use statement (line '583', column '64'). Open
return new \DateTimeImmutable('@' . $datetime, new \DateTimeZone('UTC'));
- 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
Missing class import via use statement (line '581', column '61'). Open
return new \DateTimeImmutable('@' . $value, new \DateTimeZone('UTC'));
- 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
Missing class import via use statement (line '48', column '41'). Open
$this->data[$key] = new \DateTimeImmutable($value, new \DateTimeZone('UTC'));
- 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
Missing class import via use statement (line '48', column '72'). Open
$this->data[$key] = new \DateTimeImmutable($value, new \DateTimeZone('UTC'));
- 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
Missing class import via use statement (line '581', column '24'). Open
return new \DateTimeImmutable('@' . $value, new \DateTimeZone('UTC'));
- 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
Missing class import via use statement (line '583', column '24'). Open
return new \DateTimeImmutable('@' . $datetime, new \DateTimeZone('UTC'));
- 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 '582', column '30'). Open
protected function setDateTimeColumnData($var, $value)
{
if ($value instanceof \DateTimeInterface) {
return $value;
} elseif (is_int($value)) { // Fall back to unix timestamp
- 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
Found a return statement with a value in the implementation of the magic method \Automatorm\Orm\Data::__set,
expected void return type Open
public function __set($var, $value)
- Exclude checks
Variable $external
was undeclared, but array fields are being added to it. Open
$external[$obj->$column][] = $obj;
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
return static::factoryDataCount($where + [$column => $this->data['id']], Schema::underscoreCase($table), $schema);
- Exclude checks