File DataValidator.php
has 372 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
use SmashPig\Core\ValidationError;
/**
Function validate
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public static function validate( GatewayType $gateway, $data, $check_not_empty = [] ) {
// return the array of errors that should be generated on validate.
// just the same way you'd do it if you were a form passing the error array around.
/**
- 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 validate
has 78 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function validate( GatewayType $gateway, $data, $check_not_empty = [] ) {
// return the array of errors that should be generated on validate.
// just the same way you'd do it if you were a form passing the error array around.
/**
DataValidator
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class DataValidator {
/**
* getErrorToken, intended to be used by classes that exist relatively close
* to the form classes, returns the error token (defined on the forms) that
Method cc_number_exists_in_str
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function cc_number_exists_in_str( string $str ): bool {
$luhnRegex = <<<EOT
/
(?#amex)(3[47][0-9]{13})|
(?#bankcard)(5610[0-9]{12})|(56022[1-5][0-9]{10})|
Function value_appears_in
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function value_appears_in( $needle, $haystack ) {
$needle = ( is_array( $needle ) ) ? $needle : [ $needle ];
$haystack = ( is_array( $haystack ) ) ? $haystack : [ $haystack ];
$plusCheck = array_key_exists( '+', $haystack );
- 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 luhn_check
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function luhn_check( $str ) {
$odd = ( strlen( $str ) % 2 );
$sum = 0;
$len = strlen( $str );
- 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 checkValidationPassed
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected static function checkValidationPassed( $fields, $results ) {
foreach ( $fields as $field ) {
foreach ( $results as $phase => $results_fields ) {
if ( array_key_exists( $field, $results_fields )
&& $results_fields[$field] !== 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
Avoid too many return
statements within this method. Open
return !is_array( $value );
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return (bool)$result;