Function preSubmit
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
$user = $event->getForm()->getData();
if ($user instanceof UserInterface) {
- 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 preSetData
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function preSetData(FormEvent $event)
{
$form = $event->getForm();
$user = $event->getData();
- Create a ticketCreate a ticket
The method preSubmit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$user->removeRole(ContributionRoleInterface::DEVELOPER);
}
- 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 preSubmit uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$user->removeRole(ContributionRoleInterface::PLATFORM_ADMIN);
}
- 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
Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
if ($user instanceof UserInterface) {
- Create a ticketCreate a ticket
- Exclude checks
Call to method removeRole
from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
$user->removeRole(ContributionRoleInterface::DEVELOPER);
- Create a ticketCreate a ticket
- Exclude checks
Call to method addRole
from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
$user->addRole(ContributionRoleInterface::PLATFORM_ADMIN);
- Create a ticketCreate a ticket
- Exclude checks
Parameter $authorizationChecker
has undeclared type \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
- Create a ticketCreate a ticket
- Exclude checks
Call to method isGranted
from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open
$this->allowedToSetPlatformAdmin = $authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
- Create a ticketCreate a ticket
- Exclude checks
Call to method hasRole
from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
'data' => $user->hasRole(ContributionRoleInterface::PLATFORM_ADMIN),
- Create a ticketCreate a ticket
- Exclude checks
Class implements undeclared interface \Symfony\Component\EventDispatcher\EventSubscriberInterface
Open
class UserProfilSubscriber implements EventSubscriberInterface
- Create a ticketCreate a ticket
- Exclude checks
Parameter $event
has undeclared type \Symfony\Component\Form\FormEvent
Open
public function preSetData(FormEvent $event)
- Create a ticketCreate a ticket
- Exclude checks
Call to method addRole
from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
$user->addRole(ContributionRoleInterface::DEVELOPER);
- Create a ticketCreate a ticket
- Exclude checks
Reference to constant PRE_SET_DATA
from undeclared class \Symfony\Component\Form\FormEvents
Open
FormEvents::PRE_SET_DATA => 'preSetData',
- Create a ticketCreate a ticket
- Exclude checks
Call to method getData
from undeclared class \Symfony\Component\Form\FormEvent
Open
$data = $event->getData();
- Create a ticketCreate a ticket
- Exclude checks
Call to method getData
from undeclared class \Symfony\Component\Form\FormEvent
Open
$user = $event->getData();
- Create a ticketCreate a ticket
- Exclude checks
Call to method hasRole
from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
'data' => $user->hasRole(ContributionRoleInterface::DEVELOPER),
- Create a ticketCreate a ticket
- Exclude checks
Call to method isGranted
from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open
$this->allowedToSetDeveloper = $authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);
- Create a ticketCreate a ticket
- Exclude checks
Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
if ($user instanceof UserInterface) {
- Create a ticketCreate a ticket
- Exclude checks
Call to method removeRole
from undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
$user->removeRole(ContributionRoleInterface::PLATFORM_ADMIN);
- Create a ticketCreate a ticket
- Exclude checks
Call to method getForm
from undeclared class \Symfony\Component\Form\FormEvent
Open
$user = $event->getForm()->getData();
- Create a ticketCreate a ticket
- Exclude checks
Call to method getForm
from undeclared class \Symfony\Component\Form\FormEvent
Open
$form = $event->getForm();
- Create a ticketCreate a ticket
- Exclude checks
Reference to constant PRE_SUBMIT
from undeclared class \Symfony\Component\Form\FormEvents
Open
FormEvents::PRE_SUBMIT => 'preSubmit',
- Create a ticketCreate a ticket
- Exclude checks
Parameter $event
has undeclared type \Symfony\Component\Form\FormEvent
Open
public function preSubmit(FormEvent $event)
- Create a ticketCreate a ticket
- Exclude checks
Avoid excessively long variable names like $allowedToSetPlatformAdmin. Keep variable name length under 20. Open
protected $allowedToSetPlatformAdmin;
- Read upRead up
- Create a ticketCreate a ticket
- 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 $allowedToSetDeveloper. Keep variable name length under 20. Open
protected $allowedToSetDeveloper;
- Read upRead up
- Create a ticketCreate a ticket
- 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
Closing brace indented incorrectly; expected 11 spaces, found 12 Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 20 spaces, found 16 Open
}
- Create a ticketCreate a ticket
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 11 Open
if ($this->allowedToSetPlatformAdmin) {
- Create a ticketCreate a ticket
- Exclude checks