These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace JwPersistentUser; |
||
4 | |||
5 | use JwPersistentUser\Listener\WriteTokenToCookie, |
||
6 | JwPersistentUser\Service\CookieAuthenticationService; |
||
7 | |||
8 | use Zend\ModuleManager\Feature, |
||
9 | Zend\EventManager\EventManager, |
||
10 | Zend\EventManager\EventInterface; |
||
11 | use Zend\ServiceManager\ServiceManager; |
||
12 | |||
13 | class Module implements |
||
14 | Feature\ConfigProviderInterface, |
||
15 | Feature\BootstrapListenerInterface, |
||
16 | Feature\AutoloaderProviderInterface |
||
17 | { |
||
18 | public function getConfig() |
||
19 | { |
||
20 | return include __DIR__ . '/config/module.config.php'; |
||
21 | } |
||
22 | |||
23 | public function onBootstrap(EventInterface $e) |
||
24 | { |
||
25 | /** @var EventManager $em */ |
||
26 | $em = $e->getApplication()->getEventManager(); |
||
0 ignored issues
–
show
$em is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
27 | |||
28 | /** @var ServiceManager $sm */ |
||
29 | $sm = $e->getApplication()->getServiceManager(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\EventManager\EventInterface as the method getApplication() does only exist in the following implementations of said interface: Zend\Mvc\MvcEvent .
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
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
30 | |||
31 | $request = $e->getApplication()->getRequest(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\EventManager\EventInterface as the method getApplication() does only exist in the following implementations of said interface: Zend\Mvc\MvcEvent .
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
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
32 | $response = $e->getApplication()->getResponse(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Zend\EventManager\EventInterface as the method getApplication() does only exist in the following implementations of said interface: Zend\Mvc\MvcEvent .
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
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
33 | |||
34 | // Try to login from Cookie if applicable |
||
35 | $service = new CookieAuthenticationService($sm); |
||
36 | $service->loginFrom($request, $response); |
||
37 | } |
||
38 | |||
39 | public function getAutoloaderConfig() |
||
40 | { |
||
41 | return [ |
||
42 | 'Zend\Loader\StandardAutoloader' => [ |
||
43 | 'namespaces' => [ |
||
44 | __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, |
||
45 | ], |
||
46 | ], |
||
47 | ]; |
||
48 | } |
||
49 | } |
||
50 |
Let’s take a look at an example:
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
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: