Showing 85 of 85 total issues
Avoid using undefined variables such as '$dimensions' which will lead to PHP notices. Open
foreach ($dimensions['service'] as $service) {
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Method generateAppointment
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
$issuerId,
$businessId,
$contactId,
$serviceId,
Carbon $startAt,
The parameter $round_method is not named in camelCase. Open
public function getMinutes($round_method = null)
{
$result = $this->interval / (1000 * 60);
return $this->round($result, $round_method);
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $round_method is not named in camelCase. Open
public function getHours($round_method = null)
{
$result = $this->interval / (1000 * 60 * 60);
return $this->round($result, $round_method);
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $round_method is not named in camelCase. Open
public function getSeconds($round_method = null)
{
$result = $this->interval / 1000;
return $this->round($result, $round_method);
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $round_method is not named in camelCase. Open
private function round($result, $round_method = null)
{
if ($round_method === PHP_ROUND_HALF_UP) {
$result = ceil($result);
} elseif ($round_method === PHP_ROUND_HALF_DOWN) {
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $calendar_link is not named in camelCase. Open
public function setCalendarLinkAttribute($calendar_link)
{
return $this->attributes['calendar_link'] = trim($calendar_link) ?: null;
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Function format
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function format($format = [])
{
$this->tempInterval = $this->interval;
$hours = $this->getHours(PHP_ROUND_HALF_DOWN);
$this->interval = $this->tempInterval % (1000 * 60 * 60);
- 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 cast
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function cast($value, $type)
{
switch ($type) {
case 'bool':
return boolval($value);
- 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
The class Business has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open
class Business extends EloquentModel implements HasPresenter
{
use SoftDeletes, Preferenceable, IsIntoDomain;
/**
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Method publish
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function publish($date, Carbon $startAt, Carbon $finishAt, $serviceId, $capacity = 1)
The method setTimezone has a boolean flag argument $timezone, which is a certain sign of a Single Responsibility Principle violation. Open
public function setTimezone($timezone = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Avoid too many return
statements within this method. Open
return unserialize($value);
Missing class import via use statement (line '71', column '21'). Open
$born = new \DateTime($this->wrappedObject->birthdate);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid too many return
statements within this method. Open
return $value;
Missing class import via use statement (line '70', column '26'). Open
$reference = new \DateTime();
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid too many return
statements within this method. Open
return serialize($value);
Function init
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function init()
{
$this->timetable = [];
$dimensions['service'] = $this->inflateServices();
- 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 buildVacancies
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function buildVacancies(array $vacancyParameters)
{
$services = $this->services($vacancyParameters['services']);
$days = $this->dates($vacancyParameters['days']);
$hourRanges = $this->hours($vacancyParameters['hours']);
- 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 processServiceStatements
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function processServiceStatements($business, $date, $services)
{
$changed = false;
foreach ($services as $serviceSlug => $statements) {
$service = $business->services()->where('slug', $serviceSlug)->get()->first();
- 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"