File CloudFlare.php
has 255 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace SteadLane\Cloudflare;
use Psr\Log\LoggerInterface;
- Create a ticketCreate a ticket
Method fetchZoneID
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function fetchZoneID()
{
if (!$this->hasCFCredentials()) {
return null;
}
- Create a ticketCreate a ticket
Function fetchZoneID
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function fetchZoneID()
{
if (!$this->hasCFCredentials()) {
return 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
Method curlRequest
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function curlRequest($url, $data = null, $method = 'DELETE')
{
$curlTimeout = $this->getCurlTimeout();
$curl = curl_init();
- Create a ticketCreate a ticket
Function getServerName
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function getServerName()
{
$serverName = '';
if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
$serverName = Convert::raw2xml($_SERVER['HTTP_HOST']); // "Fixes" #1 (what?)
- 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 $zoneID;
- Create a ticketCreate a ticket
Function prependServerName
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function prependServerName($input)
{
$serverName = CloudFlare::singleton()->getServerName();
if (is_array($input)) {
- 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 assigning values to variables in if clauses and the like (line '334', column '20'). Open
public function getAuthHeaders()
{
if (getenv('TRAVIS')) {
$auth = array(
'email' => getenv('AUTH_EMAIL'),
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid assigning values to variables in if clauses and the like (line '135', column '30'). Open
public function fetchZoneID()
{
if (!$this->hasCFCredentials()) {
return null;
}
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid unused parameters such as '$member'. Open
public function canUser($member)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
The method getAuthHeaders() contains an exit expression. Open
exit;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}