Method buildForm
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function buildForm(FormBuilderInterface $builder, array $options)
{
$sitesId = array();
$disabled = false;
if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {
- Create a ticketCreate a ticket
Method configureOptions
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'edit_groups' => true,
- Create a ticketCreate a ticket
Function buildForm
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function buildForm(FormBuilderInterface $builder, array $options)
{
$sitesId = array();
$disabled = false;
if (array_key_exists('data', $options) && ($user = $options['data']) 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 __construct
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
$class,
array $availableLanguages,
EventSubscriberInterface $userProfilSubscriber,
EventSubscriberInterface $userGroupSubscriber,
TranslatorInterface $translator,
- Create a ticketCreate a ticket
The method buildForm uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$allowedToSetPlatformAdmin = $this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
$allowedToSetDeveloper = $this->authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);
$this
->addPlainPasswordField($builder, $options)
- 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
Avoid assigning values to variables in if clauses and the like (line '58', column '52'). Open
public function buildForm(FormBuilderInterface $builder, array $options)
{
$sitesId = array();
$disabled = false;
if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {
- 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
Parameter $resolver
has undeclared type \Symfony\Component\OptionsResolver\OptionsResolver
Open
public function configureOptions(OptionsResolver $resolver)
- Create a ticketCreate a ticket
- Exclude checks
Call to method trans
from undeclared class \Symfony\Component\Translation\TranslatorInterface
Open
'help_text' => $this->translator->trans('open_orchestra_user.form.registration_user.complex_user_password', array(), 'validators'),
- Create a ticketCreate a ticket
- Exclude checks
Parameter $authorizationChecker
has undeclared type \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open
public function __construct(
- Create a ticketCreate a ticket
- Exclude checks
Call to method add
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$builder
- Create a ticketCreate a ticket
- Exclude checks
Return type of addPlainPasswordField()
is undeclared type \Symfony\Component\Form\FormBuilderInterface
Open
protected function addPlainPasswordField(FormBuilderInterface $builder, array $options)
- Create a ticketCreate a ticket
- Exclude checks
Call to method add
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$this
- Create a ticketCreate a ticket
- Exclude checks
Call to method isGranted
from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open
$allowedToSetPlatformAdmin = $this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
- Create a ticketCreate a ticket
- Exclude checks
Call to method addEventSubscriber
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$builder->addEventSubscriber($this->userProfileSubscriber);
- Create a ticketCreate a ticket
- Exclude checks
Call to method addEventSubscriber
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$builder->addEventSubscriber($this->userGroupSubscriber);
- Create a ticketCreate a ticket
- Exclude checks
Call to method setDefaults
from undeclared class \Symfony\Component\OptionsResolver\OptionsResolver
Open
$resolver->setDefaults(array(
- Create a ticketCreate a ticket
- Exclude checks
Call to method add
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$builder->add('accountLocked', 'checkbox', array(
- Create a ticketCreate a ticket
- Exclude checks
Parameter $builder
has undeclared type \Symfony\Component\Form\FormBuilderInterface
Open
protected function addPlainPasswordField(FormBuilderInterface $builder, array $options)
- Create a ticketCreate a ticket
- Exclude checks
Class extends undeclared class \Symfony\Component\Form\AbstractType
Open
class UserType extends AbstractType
- Create a ticketCreate a ticket
- Exclude checks
Parameter $builder
has undeclared type \Symfony\Component\Form\FormBuilderInterface
Open
public function buildForm(FormBuilderInterface $builder, array $options)
- Create a ticketCreate a ticket
- Exclude checks
Parameter $userProfilSubscriber
has undeclared type \Symfony\Component\EventDispatcher\EventSubscriberInterface
Open
public function __construct(
- Create a ticketCreate a ticket
- Exclude checks
Call to method setAttribute
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$builder->setAttribute('disabled', $options['disabled']);
- Create a ticketCreate a ticket
- Exclude checks
Call to method add
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
return $builder->add('plainPassword', 'repeated', array(
- Create a ticketCreate a ticket
- Exclude checks
Parameter $translator
has undeclared type \Symfony\Component\Translation\TranslatorInterface
Open
public function __construct(
- Create a ticketCreate a ticket
- Exclude checks
Call to method add
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$builder
- Create a ticketCreate a ticket
- Exclude checks
Call to method add
from undeclared class \Symfony\Component\Form\FormBuilderInterface
Open
$this
- Create a ticketCreate a ticket
- Exclude checks
Checking instanceof against undeclared class \OpenOrchestra\UserBundle\Model\UserInterface
Open
if (array_key_exists('data', $options) && ($user = $options['data']) instanceof UserInterface) {
- Create a ticketCreate a ticket
- Exclude checks
Call to method isGranted
from undeclared class \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open
$allowedToSetDeveloper = $this->authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);
- Create a ticketCreate a ticket
- Exclude checks
Parameter $userGroupSubscriber
has undeclared type \Symfony\Component\EventDispatcher\EventSubscriberInterface
Open
public function __construct(
- Create a ticketCreate a ticket
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
$resolver->setDefaults(array(
'data_class' => $this->class,
'edit_groups' => true,
'self_editing' => false,
'group_enabled' => true,
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 200.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $allowedToSetPlatformAdmin. Keep variable name length under 20. Open
$allowedToSetPlatformAdmin = $this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
- 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
$allowedToSetDeveloper = $this->authorizationChecker->isGranted(ContributionRoleInterface::DEVELOPER);
- 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 $userProfileSubscriber. Keep variable name length under 20. Open
protected $userProfileSubscriber;
- 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
Line exceeds 120 characters; contains 123 characters Open
$allowedToSetPlatformAdmin = $this->authorizationChecker->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);
- Create a ticketCreate a ticket
- Exclude checks
Line exceeds 120 characters; contains 159 characters Open
'help_text' => $this->translator->trans('open_orchestra_user.form.registration_user.complex_user_password', array(), 'validators'),
- Create a ticketCreate a ticket
- Exclude checks
Expected 1 space after FOREACH keyword; 0 found Open
foreach($this->availableLanguages as $language) {
- Create a ticketCreate a ticket
- Exclude checks
Expected 0 spaces before closing bracket; newline found Open
return $builder->add('plainPassword', 'repeated', array(
- Create a ticketCreate a ticket
- Exclude checks