File MemberREST.php
has 1138 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*******************************************************************************
Copyright 2010 Whole Foods Co-op, Duluth, MN
Function postCustdata
has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring. Open
private static function postCustdata($dbc, $id, $json)
{
$config = FannieConfig::factory();
$ret = array('errors' => 0, 'error-msg' => '');
- 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 postAccount
has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring. Open
private static function postAccount($dbc, $id, $json)
{
$ret = array('errors' => 0, 'error-msg' => '');
$config = FannieConfig::factory();
$account = self::getModel($dbc, 'CustomerAccountsModel');
- 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 postCustdata
has 136 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function postCustdata($dbc, $id, $json)
{
$config = FannieConfig::factory();
$ret = array('errors' => 0, 'error-msg' => '');
MemberREST
has 37 functions (exceeds 20 allowed). Consider refactoring. Open
class MemberREST
{
private static $FIELD_INFO = array(
'cardNo' => array('map'=>'CardNo', 'match'=>'strict'),
'memberStatus' => array('map'=>'Type', 'match'=>'strict'),
Method getAllCustdata
has 114 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function getAllCustdata($dbc)
{
// grab supplementary data from new tables if present
$new_available = false;
if ($dbc->tableExists('CustomerAccounts') && $dbc->tableExists('Customers')) {
Method getCustdata
has 83 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function getCustdata($dbc, $id)
{
if ($id == 0) {
return self::getAllCustdata($dbc);
}
Function getAllCustdata
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
private static function getAllCustdata($dbc)
{
// grab supplementary data from new tables if present
$new_available = false;
if ($dbc->tableExists('CustomerAccounts') && $dbc->tableExists('Customers')) {
- 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 postAccount
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function postAccount($dbc, $id, $json)
{
$ret = array('errors' => 0, 'error-msg' => '');
$config = FannieConfig::factory();
$account = self::getModel($dbc, 'CustomerAccountsModel');
Function searchCustdata
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private static function searchCustdata($dbc, $json, $limit=0, $minimal=false)
{
$query = '
SELECT c.CardNo AS cardNo,
' . ($minimal ? 'c.FirstName' : 'MAX(c.FirstName)') . ' AS firstName,
- 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 getCustdataCustomers
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function getCustdataCustomers($dbc, $id)
{
$query = '
SELECT c.personNum,
c.FirstName,
Method fastSearchResults
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function fastSearchResults($dbc, $ids)
{
list($inStr, $args) = $dbc->safeInClause($ids);
$config = FannieConfig::factory();
if ($config->get('CUST_SCHEMA') == 1 && $dbc->tableExists('CustomerAccounts') && $dbc->tableExists('Customers')) {
Method searchCustdata
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function searchCustdata($dbc, $json, $limit=0, $minimal=false)
{
$query = '
SELECT c.CardNo AS cardNo,
' . ($minimal ? 'c.FirstName' : 'MAX(c.FirstName)') . ' AS firstName,
Function getCustdata
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
private static function getCustdata($dbc, $id)
{
if ($id == 0) {
return self::getAllCustdata($dbc);
}
- 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 postMemDates
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function postMemDates($dbc, $id, $json, $ret)
{
if (isset($json['startDate']) || isset($json['endDate'])) {
$dates = self::getModel($dbc, 'MemDatesModel');
if (isset($json['startDate'])) {
- 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 addAccountIDs
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function addAccountIDs($dbc, $id, $ret)
{
$account = new CustomerAccountsModel($dbc);
$account->cardNo($id);
if ($account->load()) {
- 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 autoComplete
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function autoComplete($field, $val, $convertToID=false)
{
$config = FannieConfig::factory();
$dbc = FannieDB::getReadOnly($config->get('OP_DB'));
if (strtolower($field) == 'mfirstname') {
- 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 searchAccount
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function searchAccount($dbc, $json, $limit=0, $minimal=false)
{
$query = '
SELECT a.cardNo,
' . ($minimal ? 'c.firstName' : 'MAX(c.firstName)') . ' AS firstName,
Method autoComplete
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function autoComplete($field, $val, $convertToID=false)
{
$config = FannieConfig::factory();
$dbc = FannieDB::getReadOnly($config->get('OP_DB'));
if (strtolower($field) == 'mfirstname') {
Function getSearchResults
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private static function getSearchResults($dbc, $query, $params, $minimal, $limit)
{
if (count($params) == 0) {
return 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
Method setBlueLines
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function setBlueLines($id)
{
$config = FannieConfig::factory();
$template = $config->get('BLUELINE_TEMPLATE');
if ($template == '') {
Method addAccountIDs
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function addAccountIDs($dbc, $id, $ret)
{
$account = new CustomerAccountsModel($dbc);
$account->cardNo($id);
if ($account->load()) {
Function searchAccount
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private static function searchAccount($dbc, $json, $limit=0, $minimal=false)
{
$query = '
SELECT a.cardNo,
' . ($minimal ? 'c.firstName' : 'MAX(c.firstName)') . ' AS firstName,
- 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 createAccount
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function createAccount($dbc, $config)
{
$max = 1;
if ($config->get('CUST_SCHEMA') == 1 && $dbc->tableExists('CustomerAccounts')) {
$query = 'SELECT MAX(cardNo) FROM customerAccounts';
Function postMemContact
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private static function postMemContact($dbc, $id, $json, $ret)
{
if (isset($json['contactMethod'])) {
$contact = new MemContactModel($dbc);
$contact = self::getModel($dbc, 'MemContactModel');
- 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 setBlueLines
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function setBlueLines($id)
{
$config = FannieConfig::factory();
$template = $config->get('BLUELINE_TEMPLATE');
if ($template == '') {
- 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 buildSearchClause
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function buildSearchClause($query, $params, $json, $field_name, $use_map)
Method getSearchResults
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private static function getSearchResults($dbc, $query, $params, $minimal, $limit)
Function fastSearchResults
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function fastSearchResults($dbc, $ids)
{
list($inStr, $args) = $dbc->safeInClause($ids);
$config = FannieConfig::factory();
if ($config->get('CUST_SCHEMA') == 1 && $dbc->tableExists('CustomerAccounts') && $dbc->tableExists('Customers')) {
- 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 getCustdataCustomers
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function getCustdataCustomers($dbc, $id)
{
$query = '
SELECT c.personNum,
c.FirstName,
- 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 postMemberCards
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function postMemberCards($dbc, $id, $json, $ret)
{
if (isset($json['idCardUPC'])) {
$cards = self::getModel($dbc, 'MemberCardsModel');
$cards->card_no($id);
- 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 getAllAccounts
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static function getAllAccounts($dbc)
{
$account = new CustomerAccountsModel($dbc);
$customers = new CustomersModel($dbc);
$accounts = 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
$ret[$row['cardNo']]['customers'][] = array(
'accountHolder' => $row['accountHolder'],
'firstName' => $row['firstName'],
'lastName' => $row['lastName'],
'chargeAllowed' => $row['chargeAllowed'],
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 102.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach (self::$FIELD_INFO as $field_name => $info) {
list($query, $params) = self::buildSearchClause($query, $params, $json, $field_name, false);
foreach ($json['customers'] as $j) {
list($query, $params) = self::buildSearchClause($query, $params, $j, $field_name, false);
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 93.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach (self::$FIELD_INFO as $field_name => $info) {
list($query, $params) = self::buildSearchClause($query, $params, $json, $field_name, true);
foreach ($json['customers'] as $j) {
list($query, $params) = self::buildSearchClause($query, $params, $j, $field_name, true);
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 93.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76