JouwWeb /
JwPersistentUser
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 | |||
| 12 | class Module implements |
||
| 13 | Feature\ConfigProviderInterface, |
||
| 14 | Feature\BootstrapListenerInterface, |
||
| 15 | Feature\AutoloaderProviderInterface |
||
| 16 | { |
||
| 17 | public function getConfig() |
||
| 18 | { |
||
| 19 | return include __DIR__ . '/config/module.config.php'; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function onBootstrap(EventInterface $e) |
||
| 23 | { |
||
| 24 | /** @var EventManager $em */ |
||
| 25 | $em = $e->getApplication()->getEventManager(); |
||
|
0 ignored issues
–
show
|
|||
| 26 | |||
| 27 | $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.
Loading history...
|
|||
| 28 | $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.
Loading history...
|
|||
| 29 | |||
| 30 | // Write token to cookie after valid authentication |
||
| 31 | $placeCookie = new WriteTokenToCookie; |
||
| 32 | $placeCookie->setRequest($request); |
||
| 33 | $placeCookie->setResponse($response); |
||
| 34 | $placeCookie->setServiceLocator($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.
Loading history...
|
|||
| 35 | $em->getSharedManager()->attachAggregate($placeCookie); |
||
|
0 ignored issues
–
show
The method
attachAggregate() does not exist on Zend\EventManager\SharedEventManagerInterface. Did you maybe mean attach()?
This check marks calls to methods that do not seem to exist on an object. This is most likely the result of a method being renamed without all references to it being renamed likewise. Loading history...
|
|||
| 36 | |||
| 37 | // Try to login from Cookie if applicable |
||
| 38 | $service = new CookieAuthenticationService; |
||
| 39 | $service->setServiceLocator($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.
Loading history...
|
|||
| 40 | $service->loginFrom($request, $response); |
||
| 41 | } |
||
| 42 | |||
| 43 | public function getAutoloaderConfig() |
||
| 44 | { |
||
| 45 | return [ |
||
| 46 | 'Zend\Loader\StandardAutoloader' => [ |
||
| 47 | 'namespaces' => [ |
||
| 48 | __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, |
||
| 49 | ], |
||
| 50 | ], |
||
| 51 | ]; |
||
| 52 | } |
||
| 53 | } |
||
| 54 |
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: