File BasicModel.php
has 1106 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*******************************************************************************
Copyright 2013 Whole Foods Co-op
Function normalize
has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring. Open
public function normalize($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
if ($mode != BasicModel::NORMALIZE_MODE_CHECK && $mode != BasicModel::NORMALIZE_MODE_APPLY) {
echo "Error: Unknown mode ($mode)\n";
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
BasicModel
has 54 functions (exceeds 20 allowed). Consider refactoring. Open
class BasicModel
{
/**
Name of the table
*/
Method normalize
has 111 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function normalize($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
if ($mode != BasicModel::NORMALIZE_MODE_CHECK && $mode != BasicModel::NORMALIZE_MODE_APPLY) {
echo "Error: Unknown mode ($mode)\n";
return false;
Function find
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function find($sort='', $reverse=false)
{
if (!is_array($sort)) {
$sort = array($sort);
}
- 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 cli
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public function cli($argc, $argv)
{
if ($argc > 2 && $argv[1] == '--doc') {
array_shift($argv);
array_shift($argv);
- 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 normalizeColumnAttributes
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private function normalizeColumnAttributes($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$dbms = $this->connection->dbmsName();
$recase_columns = 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 create
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
public function create()
{
if ($this->connection->tableExists($this->fq_name)) {
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
Method cli
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function cli($argc, $argv)
{
if ($argc > 2 && $argv[1] == '--doc') {
array_shift($argv);
array_shift($argv);
Function insertRecord
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function insertRecord()
{
$sql = 'INSERT INTO '.$this->fq_name;
$cols = '(';
$vals = '(';
- 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 find
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function find($sort='', $reverse=false)
{
if (!is_array($sort)) {
$sort = array($sort);
}
Function normalizeRename
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private function normalizeRename($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$dbms = $this->connection->dbmsName();
$recase_columns = 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 load
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function load()
{
if (empty($this->unique)) {
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
Function __call
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function __call($name, $arguments)
{
if (!isset($this->columns[$name])) {
foreach ($this->columns as $col => $info) {
if (isset($info['replaces']) && $info['replaces'] == $name) {
- 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 create
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function create()
{
if ($this->connection->tableExists($this->fq_name)) {
return true;
}
Function arrayToSQL
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
protected function arrayToSQL($definition, $dbms)
{
$type = $this->getMeta($definition['type'], $dbms);
$sql = $type;
- 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 normalizeColumnAttributes
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function normalizeColumnAttributes($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$dbms = $this->connection->dbmsName();
$recase_columns = array();
Method printMarkdown
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function printMarkdown($files)
{
$tables = array();
$tables = array_reduce($files,
function ($carry, $file) {
Function normalizeChangeCase
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function normalizeChangeCase($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$lowercase_current = array();
$casemap = 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 updateRecord
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
protected function updateRecord()
{
$sql = 'UPDATE '.$this->fq_name;
$sets = '';
$where = '1=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
Method load
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function load()
{
if (empty($this->unique)) {
return false;
}
Function save
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function save()
{
if (!is_array($this->hooks) || empty($this->hooks)) {
$this->loadHooks();
}
- 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 normalizeChangeCase
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function normalizeChangeCase($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$lowercase_current = array();
$casemap = array();
Method insertRecord
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function insertRecord()
{
$sql = 'INSERT INTO '.$this->fq_name;
$cols = '(';
$vals = '(';
Method updateRecord
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function updateRecord()
{
$sql = 'UPDATE '.$this->fq_name;
$sets = '';
$where = '1=1';
Method normalizeRename
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function normalizeRename($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$dbms = $this->connection->dbmsName();
$recase_columns = array();
Method save
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function save()
{
if (!is_array($this->hooks) || empty($this->hooks)) {
$this->loadHooks();
}
Method toOptions
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function toOptions($selected=0, $id_as_label=false)
{
if (count($this->unique) != 1) {
return '';
}
Consider simplifying this complex logical expression. Open
if (($argc < 3 || $argc > 4) || ($argc == 3 && $argv[1] != "--new" && $argv[1] != '--new-view') || ($argc == 4 && $argv[1] != '--update')) {
echo "Create new Model: php BasicModel.php --new <Model Name>\n";
echo "Create new View Model: php BasicModel.php --new-view <Model Name>\n";
echo "Update Table Structure: php BasicModel.php --update <Database name> <Subclass Filename>\n";
echo "Generate markdown documentation: php BasicModel.php --doc <Model Filename(s)>\n";
Function columnsDoc
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function columnsDoc()
{
$ret = str_pad('Name', 25, ' ') . '|' . str_pad('Type', 15, ' ') . '|Info' . "\n";
$ret .= str_repeat('-', 25) . '|' . str_repeat('-', 15) . '|' . str_repeat('-', 10) . "\n";
foreach ($this->columns as $name => $info) {
- 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 toOptions
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function toOptions($selected=0, $id_as_label=false)
{
if (count($this->unique) != 1) {
return '';
}
- 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 typesDiffer
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function typesDiffer($oldtype, $newtype, $dbms)
{
// primarily, compare upper-cased type names as-is
$newtype = strtoupper($newtype);
if ($newtype == $oldtype) {
- 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 normalizeReplacePK
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function normalizeReplacePK($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK)
{
$current = $this->connection->detailedDefinition($this->name);
$dbms = $this->connection->dbmsName();
echo ($mode==BasicModel::NORMALIZE_MODE_CHECK)?"Need to set primary key":"Setting primary key";
- 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
Consider simplifying this complex logical expression. Open
if ($this->typesDiffer($current[$col_name]['type'], $type, $dbms)) {
printf("%s column %s from %s to %s\n",
($mode==BasicModel::NORMALIZE_MODE_CHECK)?"Need to change":"Changing",
$col_name, $current[$col_name]['type'], $type);
$rebuild = true;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return $carry;
Avoid too many return
statements within this method. Open
return 0;
Avoid too many return
statements within this method. Open
return -1*count($unknown);
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $carry . $item . "\n";
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $alters;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return 1;
Avoid too many return
statements within this method. Open
return 0;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return $carry . '* [' . $item . '](#' . strtolower($item) . ')' . "\n";
Function setColumn
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function setColumn($col, $val)
{
if (!isset($this->instance[$col]) || $this->instance[$col] != $val || (is_null($this->instance[$col]) && !is_null($val))) {
if (!isset($this->columns[$col]['ignore_updates']) || $this->columns[$col]['ignore_updates'] == false) {
$this->record_changed = 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"