Completed
Push — master ( efde7d...b6dd08 )
by Alexis
07:32
created

testWithEmptyFirewallName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace AWurth\SilexUser\Tests;
4
5
use AWurth\SilexUser\Provider\SilexUserServiceProvider;
6
use Dflydev\Provider\DoctrineOrm\DoctrineOrmServiceProvider;
7
use LogicException;
8
use Silex\Application;
9
use Silex\Provider\DoctrineServiceProvider;
10
use Silex\Provider\FormServiceProvider;
11
use Silex\Provider\LocaleServiceProvider;
12
use Silex\Provider\SecurityServiceProvider;
13
use Silex\Provider\ServiceControllerServiceProvider;
14
use Silex\Provider\SessionServiceProvider;
15
use Silex\Provider\SwiftmailerServiceProvider;
16
use Silex\Provider\TranslationServiceProvider;
17
use Silex\Provider\TwigServiceProvider;
18
use Silex\Provider\ValidatorServiceProvider;
19
use Silex\WebTestCase;
20
21
class SilexUserServiceProviderConfigurationTest extends WebTestCase
22
{
23
    /**
24
     * @expectedException LogicException
25
     * @expectedExceptionMessage The "user_class" option must be set
26
     */
27
    public function testWithoutUserClass()
28
    {
29
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
30
    }
31
32
    /**
33
     * @expectedException LogicException
34
     * @expectedExceptionMessage The "user_class" option must be set
35
     */
36
    public function testWithEmptyUserClass()
37
    {
38
        $this->app['silex_user.options'] = [
39
            'user_class' => ''
40
        ];
41
42
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
43
    }
44
45
    /**
46
     * @expectedException LogicException
47
     * @expectedExceptionMessage The "firewall_name" option must be set
48
     */
49
    public function testWithoutFirewallName()
50
    {
51
        $this->app['silex_user.options'] = [
52
            'user_class' => 'User'
53
        ];
54
55
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
56
    }
57
58
    /**
59
     * @expectedException LogicException
60
     * @expectedExceptionMessage The "firewall_name" option must be set
61
     */
62
    public function testWithEmptyFirewallName()
63
    {
64
        $this->app['silex_user.options'] = [
65
            'user_class' => 'User',
66
            'firewall_name' => ''
67
        ];
68
69
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
70
    }
71
72
    /**
73
     * @expectedException LogicException
74
     * @expectedExceptionMessage You must configure a mailer to enable email notifications
75
     */
76
    public function testEmailConfirmationWithoutMailer()
77
    {
78
        $this->app['silex_user.options'] = [
79
            'user_class' => 'User',
80
            'firewall_name' => 'main',
81
            'registration.confirmation.enabled' => true
82
        ];
83
84
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
85
    }
86
87
    /**
88
     * @expectedException LogicException
89
     * @expectedExceptionMessage The "registration.confirmation.from_email" option must be set
90
     */
91 View Code Duplication
    public function testEmailConfirmationWithoutFromEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
    {
93
        $this->app->register(new SwiftmailerServiceProvider());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method register() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
94
95
        $this->app['silex_user.options'] = [
96
            'user_class' => 'User',
97
            'firewall_name' => 'main',
98
            'registration.confirmation.enabled' => true
99
        ];
100
101
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
102
    }
103
104
    /**
105
     * @expectedException LogicException
106
     * @expectedExceptionMessage The "registration.confirmation.from_email" option must be set
107
     */
108 View Code Duplication
    public function testEmailConfirmationWithEmptyFromEmail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
    {
110
        $this->app->register(new SwiftmailerServiceProvider());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method register() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
111
112
        $this->app['silex_user.options'] = [
113
            'user_class' => 'User',
114
            'firewall_name' => 'main',
115
            'registration.confirmation.enabled' => true,
116
            'registration.confirmation.from_email' => ''
117
        ];
118
119
        $this->app->boot();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Symfony\Component\HttpKernel\HttpKernelInterface as the method boot() does only exist in the following implementations of said interface: Silex\Application, Silex\Tests\Application\FormApplication, Silex\Tests\Application\MonologApplication, Silex\Tests\Application\SecurityApplication, Silex\Tests\Application\SwiftmailerApplication, Silex\Tests\Application\TranslationApplication, Silex\Tests\Application\TwigApplication, Silex\Tests\Application\UrlGeneratorApplication, Silex\Tests\SpecialApplication, Symfony\Component\HttpKernel\Kernel, Symfony\Component\HttpKe...\CustomProjectDirKernel, Symfony\Component\HttpKe...Collector\KernelForTest, Symfony\Component\HttpKe...s\KernelForOverrideName, Symfony\Component\HttpKe...\Fixtures\KernelForTest, Symfony\Component\HttpKe...es\KernelWithoutBundles, Symfony\Component\HttpKe...Fixtures\_123\Kernel123.

Let’s take a look at an example:

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

class MyUser implements 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 implementation 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 interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
120
    }
121
122
    public function createApplication()
123
    {
124
        $app = new Application([
125
            'debug' => true
126
        ]);
127
128
        $app->register(new ServiceControllerServiceProvider());
129
        $app->register(new TwigServiceProvider());
130
        $app->register(new SessionServiceProvider());
131
        $app->register(new LocaleServiceProvider());
132
        $app->register(new TranslationServiceProvider());
133
        $app->register(new ValidatorServiceProvider());
134
        $app->register(new FormServiceProvider());
135
        $app->register(new DoctrineServiceProvider());
136
        $app->register(new DoctrineOrmServiceProvider());
137
        $app->register(new SecurityServiceProvider());
138
        $app->register(new SilexUserServiceProvider());
139
140
        $app['security.firewalls'] = [
141
            'main' => [
142
                'form' => []
143
            ]
144
        ];
145
146
        return $app;
147
    }
148
}
149