Showing 213 of 213 total issues
Avoid excessively long variable names like $subdivisionRepository. Keep variable name length under 20. Open
SubdivisionRepositoryInterface $subdivisionRepository,
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $gmapsAutocompleteService. Keep variable name length under 20. Open
protected $gmapsAutocompleteService;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $addressEmbeddableTypeSubscriber. Keep variable name length under 20. Open
private $addressEmbeddableTypeSubscriber;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $addressEmbeddableTypeSubscriber. Keep variable name length under 20. Open
EventSubscriberInterface $addressEmbeddableTypeSubscriber
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Method preSetData
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function preSetData(FormEvent $event): void
{
/** @var AddressEmbeddable $address */
$address = $event->getData();
$form = $event->getForm();
Method preSubmit
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function preSubmit(FormEvent $event): void
{
$data = $event->getData();
if (!is_array($data) || !array_key_exists('countryCode', $data)) {
return;
Function getValuesForDefault
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
protected function getValuesForDefault(AddressEmbeddable $addressEmbeddable, AddressFormat $address_format) {
$values = [];
foreach (AddressField::getAll() as $field) {
$getter = 'get' . ucfirst($field);
$values[$field] = $addressEmbeddable->$getter();
- 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 preSetData
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function preSetData(FormEvent $event): void
{
/** @var AddressEmbeddable $address */
$address = $event->getData();
$form = $event->getForm();
- 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 initialize
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
initialize: function () {
$(document).ready(function () {
$('.address-embeddable').once('initiate-country-code-change').each(function () {
var id = $(this).attr('id');
Avoid using undefined variables such as '$replacements' which will lead to PHP notices. Open
$replacements[$field] = htmlspecialchars($values[$field], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
- 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
Avoid using undefined variables such as '$replacements' which will lead to PHP notices. Open
return $replacements;
- 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
Avoid using undefined variables such as '$replacements' which will lead to PHP notices. Open
$replacements['country'] = htmlspecialchars($countries[$country_code], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
- 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
Avoid using undefined variables such as '$address' which will lead to PHP notices. Open
$use_local_name = Locale::matchCandidates($address->getLocale(), $subdivision->getLocale());
- 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
Function fillInAddress
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function fillInAddress(place)
{
if (typeof place.name === 'undefined') {
place.name = getPlaceName(place);
}
Function getFieldOverrides
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function getFieldOverrides(FormInterface $form): FieldOverrides
{
if (!$this->validator) {
return new FieldOverrides([]);
}
- 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 getFieldOverrides
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getFieldOverrides(FormInterface $form): FieldOverrides
{
if (!$this->validator) {
return new FieldOverrides([]);
}
The parameter $address_format is not named in camelCase. Open
protected function getValuesForPlain(AddressEmbeddable $addressEmbeddable, AddressFormat $address_format) {
$values = [];
foreach (AddressField::getAll() as $field) {
$getter = 'get' . ucfirst($field);
$values[$field] = $addressEmbeddable->$getter();
- 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 $address_format is not named in camelCase. Open
protected function getValuesForDefault(AddressEmbeddable $addressEmbeddable, AddressFormat $address_format) {
$values = [];
foreach (AddressField::getAll() as $field) {
$getter = 'get' . ucfirst($field);
$values[$field] = $addressEmbeddable->$getter();
- 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 class AddressEmbeddableTypeSubscriber has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open
class AddressEmbeddableTypeSubscriber implements EventSubscriberInterface
{
/**
* @var CountryRepositoryInterface
*/
- 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 __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
FormFactoryInterface $factory,
CountryRepositoryInterface $countryRepository,
AddressFormatRepositoryInterface $addressFormatRepository,
SubdivisionRepositoryInterface $subdivisionRepository,
ValidatorInterface $validator = null