Completed
Push — master ( 8df0ed...8bb3f1 )
by Andrea
09:53
created

FiCrudController::updateAction()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 67
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 5.2331

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 67
ccs 30
cts 38
cp 0.7895
rs 8.5896
cc 5
eloc 41
nc 6
nop 2
crap 5.2331

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
9
10
class FiCrudController extends Controller
11
{
12
13
    public static $namespace;
14
    public static $bundle;
15
    public static $controller;
16
    public static $action;
17
    public static $parametrigriglia;
18
19
    /**
20
     * Lists all tables entities.
21
     */
22
    public function indexAction(Request $request)
23
    {
24
        /* @var $em \Doctrine\ORM\EntityManager */
25
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
26
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
27
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
28
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
29
        $container = $this->container;
30
31
        $gestionepermessi = $this->get('ficorebundle.gestionepermessi');
32
        $canRead = ($gestionepermessi->leggere(array('modulo' => $controller)) ? 1 : 0);
33
        if (!$canRead) {
34
            throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto");
35
        }
36
        $idpassato = $request->get('id');
37
38
        $nomebundle = $namespace . $bundle . 'Bundle';
39
40
        $repotabelle = $this->get('OpzioniTabella_repository');
41
42
        $paricevuti = array('nomebundle' => $nomebundle, 'nometabella' => $controller, 'container' => $container);
43
44
        $testatagriglia = Griglia::testataPerGriglia($paricevuti);
45
46
        $testatagriglia['multisearch'] = 1;
47
        $testatagriglia['showconfig'] = 1;
48
        $testatagriglia['overlayopen'] = 1;
49
50
        $testatagriglia['parametritesta'] = json_encode($paricevuti);
51
52
        $this->setParametriGriglia(array('request' => $request));
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setParametriGriglia() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
53
        $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia);
54
55
        $testata = $repotabelle->editTestataFormTabelle($testatagriglia, $controller, $container);
56
        return $this->render(
57
            $nomebundle . ':' . $controller . ':index.html.twig',
58
            array(
59
                    'nomecontroller' => $controller,
60
                    'testata' => $testata,
61
                    'canread' => $canRead,
62
                    'idpassato' => $idpassato,
63
                        )
64
        );
65
    }
66
67
    /**
68
     * Creates a new table entity.
69
     */
70 2
    public function createAction(Request $request)
71
    {
72 2
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
73 2
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
74 2
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
75 2
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
76
77 2
        $nomebundle = $namespace . $bundle . 'Bundle';
78 2
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
79 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
80
81 2
        $entity = new $classbundle();
82 2
        $formType = $formbundle . 'Type';
83
84 2
        $form = $this->createForm(
85 2
            $formType,
86 2
            $entity,
87
            array('attr' => array(
88 2
                'id' => 'formdati' . $controller,
89
                ),
90 2
                'action' => $this->generateUrl($controller . '_create'),
91
                )
92
        );
93
94 2
        $form->submit($request->request->get($form->getName()));
95
96 2
        if ($form->isValid()) {
97 2
            $em = $this->getDoctrine()->getManager();
98 2
            $em->persist($entity);
99 2
            $em->flush();
100
101 2
            $continua = $request->get('continua');
102 2
            if ($continua == 0) {
103 2
                return new Response('OK');
104
            } else {
105
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId())));
106
            }
107
        }
108
109
        return $this->render(
110
            $nomebundle . ':' . $controller . ':new.html.twig',
111
            array(
112
                    'nomecontroller' => $controller,
113
                    'entity' => $entity,
114
                    'form' => $form->createView(),
115
                        )
116
        );
117
    }
118
119
    /**
120
     * Displays a form to create a new table entity.
121
     */
122 2
    public function newAction(Request $request)
123
    {
124 2
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
125 2
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
126 2
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
127 2
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
128
129 2
        $nomebundle = $namespace . $bundle . 'Bundle';
130 2
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
131 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
132 2
        $formType = $formbundle . 'Type';
133
134 2
        $entity = new $classbundle();
135
136 2
        $form = $this->createForm(
137 2
            $formType,
138 2
            $entity,
139
            array('attr' => array(
140 2
                'id' => 'formdati' . $controller,
141
                ),
142 2
                'action' => $this->generateUrl($controller . '_create'),
143
                )
144
        );
145
146 2
        return $this->render(
147 2
            $nomebundle . ':' . $controller . ':new.html.twig',
148
            array(
149 2
                    'nomecontroller' => $controller,
150 2
                    'entity' => $entity,
151 2
                    'form' => $form->createView(),
152
                        )
153
        );
154
    }
155
156
    /**
157
     * Displays a form to edit an existing table entity.
158
     */
159 2
    public function editAction(Request $request, $id)
160
    {
161
        /* @var $em \Doctrine\ORM\EntityManager */
162 2
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
163 2
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
164 2
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
165 2
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
166
167 2
        $nomebundle = $namespace . $bundle . 'Bundle';
168 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
169 2
        $formType = $formbundle . 'Type';
170
171 2
        $elencomodifiche = $this->elencoModifiche($nomebundle, $controller, $id);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method elencoModifiche() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
172
173 2
        $em = $this->getDoctrine()->getManager();
174
175 2
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
176
177 2
        if (!$entity) {
178
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
179
        }
180
181 2
        $editForm = $this->createForm(
182 2
            $formType,
183 2
            $entity,
184
            array('attr' => array(
185 2
                'id' => 'formdati' . $controller,
186
                ),
187 2
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
188
                )
189
        );
190
191 2
        $deleteForm = $this->createDeleteForm($id);
192
193 2
        return $this->render(
194 2
            $nomebundle . ':' . $controller . ':edit.html.twig',
195
            array(
196 2
                    'entity' => $entity,
197 2
                    'nomecontroller' => $controller,
198 2
                    'edit_form' => $editForm->createView(),
199 2
                    'delete_form' => $deleteForm->createView(),
200 2
                    'elencomodifiche' => $elencomodifiche,
201
                        )
202
        );
203
    }
204
205
    /**
206
     * Edits an existing table entity.
207
     */
208 2
    public function updateAction(Request $request, $id)
209
    {
210
        /* @var $em \Doctrine\ORM\EntityManager */
211 2
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
212 2
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
213 2
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
214 2
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
215
216 2
        $nomebundle = $namespace . $bundle . 'Bundle';
217 2
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
218 2
        $formType = $formbundle . 'Type';
219
220 2
        $repoStorico = $this->container->get('Storicomodifiche_repository');
221
222 2
        $em = $this->getDoctrine()->getManager();
223
224 2
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
225
226 2
        if (!$entity) {
227
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
228
        }
229
230 2
        $deleteForm = $this->createDeleteForm($id);
231
232 2
        $editForm = $this->createForm(
233 2
            $formType,
234 2
            $entity,
235
            array('attr' => array(
236 2
                'id' => 'formdati' . $controller,
237
                ),
238 2
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
239
                )
240
        );
241
242 2
        $editForm->submit($request->request->get($editForm->getName()));
243
244 2
        if ($editForm->isValid()) {
245 2
            $originalData = $em->getUnitOfWork()->getOriginalEntityData($entity);
246
247 2
            $em->persist($entity);
248 2
            $em->flush();
249
250 2
            $newData = $em->getUnitOfWork()->getOriginalEntityData($entity);
251 2
            $changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData);
252
253 2
            if ($changes) {
254 1
                $repoStorico->saveHistory($controller, $changes, $id, $this->getUser());
255
            }
256
257 2
            $continua = $request->get('continua');
258 2
            if ($continua == 0) {
259 2
                return new Response('OK');
260
            } else {
261
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id)));
262
            }
263
        }
264
265
        return $this->render(
266
            $nomebundle . ':' . $controller . ':edit.html.twig',
267
            array(
268
                    'entity' => $entity,
269
                    'edit_form' => $editForm->createView(),
270
                    'delete_form' => $deleteForm->createView(),
271
                    'nomecontroller' => $controller,
272
                        )
273
        );
274
    }
275
276
    /**
277
     * Edits an existing table entity.
278
     */
279
    public function aggiornaAction(Request $request)
280
    {
281
        /* @var $em \Doctrine\ORM\EntityManager */
282
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
283
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
284
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
285
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
286
287
        $nomebundle = $namespace . $bundle . 'Bundle';
288
289
        $id = $this->get('request')->request->get('id');
290
291
        $em = $this->getDoctrine()->getManager();
292
293
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
294
295
        if (!$entity) {
296
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
297
        }
298
299
        throw $this->createNotFoundException("Implementare a seconda dell'esigenza 'aggiornaAction' del controller "
300
                . $nomebundle
301
                . '/'
302
                . $controller);
303
    }
304
305
    /**
306
     * Deletes a table entity.
307
     */
308 2
    public function deleteAction(Request $request)
309
    {
310
        /* @var $em \Doctrine\ORM\EntityManager */
311 2
        $this->setup($request);
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method setup() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
312 2
        $namespace = $this->getNamespace();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getNamespace() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
313 2
        $bundle = $this->getBundle();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getBundle() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
314 2
        $controller = $this->getController();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Fi\CoreBundle\Controller\FiCrudController as the method getController() does only exist in the following sub-classes of Fi\CoreBundle\Controller\FiCrudController: Fi\CoreBundle\Controller\FfprincipaleController, Fi\CoreBundle\Controller\FfsecondariaController, Fi\CoreBundle\Controller\FiController, Fi\CoreBundle\Controller\FiCoreController, Fi\CoreBundle\Controller...uApplicazioneController, Fi\CoreBundle\Controller\MenuController, Fi\CoreBundle\Controller\OperatoriController, Fi\CoreBundle\Controller\OpzioniTabellaController, Fi\CoreBundle\Controller\PermessiController, Fi\CoreBundle\Controller\RuoliController, Fi\CoreBundle\Controller\StampatabellaController, Fi\CoreBundle\Controller...ricomodificheController, Fi\CoreBundle\Controller\TabelleController. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
315
316 2
        $nomebundle = $namespace . $bundle . 'Bundle';
317
318
        //if (!$request->isXmlHttpRequest()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
319
        //    $request->checkCSRFProtection();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
320
        //}
321
        try {
322 2
            $em = $this->getDoctrine()->getManager();
323 2
            $qb = $em->createQueryBuilder();
324 2
            $ids = explode(',', $request->get('id'));
325 2
            $qb->delete($nomebundle . ':' . $controller, 'u')
326 2
                    ->andWhere('u.id IN (:ids)')
327 2
                    ->setParameter('ids', $ids);
328
329 2
            $query = $qb->getQuery();
330 2
            $query->execute();
331
        } catch (\Exception $e) {
332
            $response = new Response();
333
            $response->setStatusCode('200');
334
335
            return new Response('404');
336
        }
337
338 2
        return new Response('OK');
339
    }
340
341
    /**
342
     * Creates a form to delete a table entity by id.
343
     *
344
     * @param mixed $id The entity id
345
     *
346
     * @return \Symfony\Component\Form\Form The form
347
     */
348
    protected function createDeleteForm($id)
349
    {
350
        return $this->createFormBuilder(array('id' => $id))
351
                        ->add('id', get_class(new \Symfony\Component\Form\Extension\Core\Type\HiddenType()))
352
                        ->getForm();
353
    }
354
}
355