Method __get
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Confirmed
public function __get($var)
{
switch ($var) {
case "bytes":
return $this->bytes;
- Create a ticketCreate a ticket
Function __get
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Confirmed
public function __get($var)
{
switch ($var) {
case "bytes":
return $this->bytes;
- Read upRead up
- Create a ticketCreate a ticket
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 nameGenerator
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected static function nameGenerator($ver, $node, $namespace)
{
// if the namespace UUID isn't binary, make it so
$namespace = static::makeBinary($namespace, 16);
$version = null;
- Read upRead up
- Create a ticketCreate a ticket
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 "urn:uuid:" . $this->__toString();
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (int) 0;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (int) 2;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return null;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (string) $this->__toString();
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (int) 3;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (int) 1;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (int) (hexdec($time) - static::INTERVAL) / 10000000;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return (int) ord($this->bytes[6]) >> 4;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return null;
- Create a ticketCreate a ticket
The method __get() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function __get($var)
{
switch ($var) {
case "bytes":
return $this->bytes;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
protected static function makeBinary($str, $len)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
public static function generate($ver = null, $node = null, $namespace = null)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Reduce the number of returns of this function 14, down to the maximum allowed 3. Open
public function __get($var)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
The method __get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return (int) 0;
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method makeBinary uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// strip URN scheme and namespace
$str = preg_replace('/^urn:uuid:/is', '', $str);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method __get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return null;
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method makeBinary uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return pack("H*", $str);
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method __get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return null;
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Add a "case default" clause to this "switch" statement. Open
switch ($ver) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
The requirement for a final case default
clause is defensive programming. The clause should either take appropriate action, or contain
a suitable comment as to why no action is taken. Even when the switch
covers all current values of an enum
, a default case
should still be used because there is no guarantee that the enum
won't be extended.
Noncompliant Code Example
switch ($param) { //missing default clause case 0: do_something(); break; case 1: do_something_else(); break; } switch ($param) { default: // default clause should be the last one error(); break; case 0: do_something(); break; case 1: do_something_else(); break; }
Compliant Solution
switch ($param) { case 0: do_something(); break; case 1: do_something_else(); break; default: error(); break; }
See
- MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
- MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
- MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
- MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
- MISRA C:2012, 16.1 - All switch statements shall be well-formed
- MISRA C:2012, 16.4 - Every switch statement shall have a default label
- MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
- MITRE, CWE-478 - Missing Default Case in Switch Statement
- CERT, MSC01-C. - Strive for logical completeness
- CERT, MSC01-CPP. - Strive for logical completeness
Argument 1 (get_as_float)
is 1
but \microtime()
takes bool
Open
$time = microtime(1) * 10000000 + static::INTERVAL;
- Create a ticketCreate a ticket
- Exclude checks
Returning type ?string|array{6:string}|array{8:string}
but nameGenerator()
is declared to return string
Open
return ($uuid);
- Create a ticketCreate a ticket
- Exclude checks
Return type of __get()
is undeclared type \TakeawayTown\LaravelUuid\Classes\number
Open
public function __get($var)
- Create a ticketCreate a ticket
- Exclude checks
Returning type int
but __get()
is declared to return \TakeawayTown\LaravelUuid\Classes\number|null|string
Open
return (int) ord($this->bytes[6]) >> 4;
- Create a ticketCreate a ticket
- Exclude checks
Saw an @param annotation for ns,
but it was not found in the param list of function nameGenerator(int $ver, string $node, $namespace) : string
Open
* @param string $ns Binary namespace is required for version 3 or 5 UUIDs
- Create a ticketCreate a ticket
- Exclude checks
Reference to undeclared property \TakeawayTown\LaravelUuid\Classes\Uuid->string
Open
$this->string = bin2hex(substr($uuid, 0, 4)) . "-" .
- Create a ticketCreate a ticket
- Exclude checks
Saw an @param annotation for ns,
but it was not found in the param list of function generate(int $ver = null, string $node = null, mixed $namespace = null) : \TakeawayTown\LaravelUuid\Classes\Uuid
Open
* @param string $ns Binary namespace is required for version 3 or 5 UUIDs
- Create a ticketCreate a ticket
- Exclude checks
Returning type int
but __get()
is declared to return \TakeawayTown\LaravelUuid\Classes\number|null|string
Open
return (int) 0;
- Create a ticketCreate a ticket
- Exclude checks
Returning type int
but __get()
is declared to return \TakeawayTown\LaravelUuid\Classes\number|null|string
Open
return (int) (hexdec($time) - static::INTERVAL) / 10000000;
- Create a ticketCreate a ticket
- Exclude checks
Returning type int
but __get()
is declared to return \TakeawayTown\LaravelUuid\Classes\number|null|string
Open
return (int) 2;
- Create a ticketCreate a ticket
- Exclude checks
Call to method __construct
from undeclared class \TakeawayTown\LaravelUuid\Classes\UnexpectedValueException
(Did you mean class \UnexpectedValueException) Open
throw new UnexpectedValueException('Version ' . $ver . ' is unsupported.');
- Create a ticketCreate a ticket
- Exclude checks
Possibly zero references to use statement for classlike/namespace Config
(\Illuminate\Support\Facades\Config)
Open
use Illuminate\Support\Facades\Config;
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Confirmed
$ver = $ver !== null ? $ver : config('uuid.default_version');
- Create a ticketCreate a ticket
- Exclude checks
Call to undeclared function \config()
Confirmed
$node = $node !== null ? $node : config('uuid.default_node');
- Create a ticketCreate a ticket
- Exclude checks
Suspicious array access to ?string
Open
$uuid[8] = chr(ord($uuid[8]) & static::CLEAR_VAR | static::VAR_RFC);
- Create a ticketCreate a ticket
- Exclude checks
Reference to undeclared property \TakeawayTown\LaravelUuid\Classes\Uuid->bytes
Open
$this->bytes = $uuid;
- Create a ticketCreate a ticket
- Exclude checks
Call to method __construct
from undeclared class \TakeawayTown\LaravelUuid\Classes\UnexpectedValueException
(Did you mean class \UnexpectedValueException) Open
throw new UnexpectedValueException('Version ' . $ver . ' is unsupported.');
- Create a ticketCreate a ticket
- Exclude checks
Possibly zero references to use statement for classlike/namespace UuidServiceProvider
(\TakeawayTown\LaravelUuid\Providers\UuidServiceProvider)
Open
use TakeawayTown\LaravelUuid\Providers\UuidServiceProvider;
- Create a ticketCreate a ticket
- Exclude checks
Call to method __construct
from undeclared class \TakeawayTown\LaravelUuid\Classes\InvalidArgumentException
(Did you mean class \InvalidArgumentException) Open
throw new InvalidArgumentException('A binary namespace is required for Version 3 or 5 UUIDs.');
- Create a ticketCreate a ticket
- Exclude checks
Call to method __construct
from undeclared class \TakeawayTown\LaravelUuid\Classes\InvalidArgumentException
(Did you mean class \InvalidArgumentException) Open
throw new InvalidArgumentException('A name-string is required for Version 3 or 5 UUIDs.');
- Create a ticketCreate a ticket
- Exclude checks
Argument 2 (raw_output)
is 1
but \sha1()
takes bool
Open
$uuid = substr(sha1($namespace . $node, 1), 0, 16);
- Create a ticketCreate a ticket
- Exclude checks
Argument 2 (raw_output)
is 1
but \md5()
takes bool
Open
$uuid = md5($namespace . $node, 1);
- Create a ticketCreate a ticket
- Exclude checks
Returning type int
but __get()
is declared to return \TakeawayTown\LaravelUuid\Classes\number|null|string
Open
return (int) 1;
- Create a ticketCreate a ticket
- Exclude checks
Returning type int
but __get()
is declared to return \TakeawayTown\LaravelUuid\Classes\number|null|string
Open
return (int) 3;
- Create a ticketCreate a ticket
- Exclude checks
Call to method __construct
from undeclared class \TakeawayTown\LaravelUuid\Classes\InvalidArgumentException
(Did you mean class \InvalidArgumentException) Open
throw new InvalidArgumentException('Input must be a 128-bit integer.');
- Create a ticketCreate a ticket
- Exclude checks
Usage of ELSE IF is discouraged; use ELSEIF instead Open
} else if (is_null($namespace)) {
- Create a ticketCreate a ticket
- Exclude checks