src/Constraint/Format.php
Method validationError
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public static function validationError($format, $data)
{
switch ($format) {
case self::DATE_TIME:
return self::dateTimeError($data);
Function dateTimeError
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
Open
public static function dateTimeError($data)
{
if (!preg_match('/^' . self::$dateRegexPart . 'T' . self::$timeRegexPart . '$/i', $data)) {
return 'Invalid date-time format: ' . $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
Avoid too many return
statements within this method. Open
Open
return Iri::validationError($data);
Avoid too many return
statements within this method. Open
Open
return Iri::validationError($data, Uri::IS_URI_REFERENCE);
Avoid too many return
statements within this method. Open
Open
return count(explode('@', $data, 3)) === 2 ? null : 'Invalid email';
Avoid too many return
statements within this method. Open
Open
return filter_var($data, FILTER_VALIDATE_EMAIL) ? null : 'Invalid email';
Avoid too many return
statements within this method. Open
Open
return preg_match(Uri::HOSTNAME_REGEX, $data) ? null : 'Invalid hostname';
Avoid too many return
statements within this method. Open
Open
return null;
Avoid too many return
statements within this method. Open
Open
return self::jsonPointerError($data, true);
Avoid too many return
statements within this method. Open
Open
return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ? null : 'Invalid ipv4';
Avoid too many return
statements within this method. Open
Open
return Uri::validationError($data, Uri::IS_URI_REFERENCE);
Avoid too many return
statements within this method. Open
Open
return self::jsonPointerError($data);
Avoid too many return
statements within this method. Open
Open
return 'Invalid hostname (too long)';
Avoid too many return
statements within this method. Open
Open
return IdnHostname::validationError($data);
Avoid too many return
statements within this method. Open
Open
return filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ? null : 'Invalid ipv6';
Avoid too many return
statements within this method. Open
Open
return self::regexError($data);
Avoid too many return
statements within this method. Open
Open
return Uri::validationError($data, Uri::IS_URI_TEMPLATE);