liverbool /
dos-sms-bundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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 DoS\SMSBundle\SMS; |
||
| 4 | |||
| 5 | use DoS\SMSBundle\Provider\RecordProvider; |
||
| 6 | use SmsSender\DelayedSenderInterface; |
||
| 7 | use SmsSender\SmsSender; |
||
| 8 | use SmsSender\SmsSenderInterface; |
||
| 9 | |||
| 10 | class StorableSender implements DelayedSenderInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var RecordProvider |
||
| 14 | */ |
||
| 15 | protected $recordProvider; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var SmsSenderInterface |
||
| 19 | */ |
||
| 20 | protected $sender; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Logger |
||
| 24 | */ |
||
| 25 | protected $logger; |
||
| 26 | |||
| 27 | public function __construct(RecordProvider $recordProvider, SmsSender $sender, Logger $logger = null) |
||
| 28 | { |
||
| 29 | $this->recordProvider = $recordProvider; |
||
| 30 | $this->sender = $sender; |
||
| 31 | $this->logger = $logger; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritDoc} |
||
| 36 | */ |
||
| 37 | public function flush() |
||
| 38 | { |
||
| 39 | if ($this->sender instanceof DelayedSenderInterface) { |
||
| 40 | list($sentMessages, $errors) = $this->sender->flush(); |
||
|
0 ignored issues
–
show
|
|||
| 41 | |||
| 42 | foreach ($errors as $error) { |
||
| 43 | $this->logger->logError($error, $this->getProviderClass()); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function send($recipient, $body, $originator = '') |
||
| 52 | { |
||
| 53 | $this->activateProvider(); |
||
| 54 | |||
| 55 | if ($this->logger) { |
||
| 56 | $time = microtime(true); |
||
| 57 | $result = $this->sender->send($recipient, $body, $originator); |
||
| 58 | $duration = microtime(true) - $time; |
||
| 59 | |||
| 60 | $this->logger->logMessage($result, $duration, $this->getProviderClass()); |
||
| 61 | } else { |
||
| 62 | $result = $this->sender->send($recipient, $body, $originator); |
||
| 63 | } |
||
| 64 | |||
| 65 | $this->recordProvider->storeResult($result); |
||
| 66 | |||
| 67 | return $result; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Activate default provider. |
||
| 72 | */ |
||
| 73 | public function activateProvider() |
||
| 74 | { |
||
| 75 | $provider = $this->recordProvider->getProvider()->getActivedProvider(); |
||
| 76 | $this->using($provider->getName()); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param $name |
||
| 81 | * |
||
| 82 | * @return $this |
||
| 83 | */ |
||
| 84 | public function using($name) |
||
| 85 | { |
||
| 86 | $this->sender->using($name); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
SmsSender\SmsSenderInterface as the method using() does only exist in the following implementations of said interface: DoS\SMSBundle\SMS\StorableSender, SmsSender\SmsSender.
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...
|
|||
| 87 | |||
| 88 | $pvd = $this->recordProvider->getProvider()->findByName($name); |
||
| 89 | $provider = $this->sender->getProvider(); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
SmsSender\SmsSenderInterface as the method getProvider() does only exist in the following implementations of said interface: SmsSender\SmsSender.
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...
|
|||
| 90 | |||
| 91 | if ($provider instanceof ProviderInterface && $pvd) { |
||
| 92 | $provider->applyOptions($pvd->getParameters()); |
||
| 93 | } |
||
| 94 | |||
| 95 | return $this; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * {@inheritdoc} |
||
| 100 | */ |
||
| 101 | public function acceptCallback($provider, array $response) |
||
| 102 | { |
||
| 103 | $provider = $this->using($provider)->sender->getProvider(); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
SmsSender\SmsSenderInterface as the method getProvider() does only exist in the following implementations of said interface: SmsSender\SmsSender.
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...
|
|||
| 104 | |||
| 105 | if ($provider instanceof ProviderInterface) { |
||
| 106 | $provider->processCallback($response); |
||
| 107 | $provider->accept($this->recordProvider); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Allows to proxy method calls to the real SMS sender. |
||
| 113 | * |
||
| 114 | * @param $name |
||
| 115 | * @param $arguments |
||
| 116 | * |
||
| 117 | * @return StorableSender|SmsSenderInterface |
||
| 118 | */ |
||
| 119 | public function __call($name, $arguments) |
||
| 120 | { |
||
| 121 | if (is_callable(array($this->sender, $name))) { |
||
| 122 | $result = call_user_func_array(array($this->sender, $name), $arguments); |
||
| 123 | |||
| 124 | // don't break fluid interfaces |
||
| 125 | return $result instanceof SmsSenderInterface ? $this : $result; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return null|string |
||
| 131 | */ |
||
| 132 | protected function getProviderClass() |
||
| 133 | { |
||
| 134 | return ($provider = $this->sender->getProvider()) ? get_class($provider) : null; |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
SmsSender\SmsSenderInterface as the method getProvider() does only exist in the following implementations of said interface: SmsSender\SmsSender.
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...
|
|||
| 135 | } |
||
| 136 | } |
||
| 137 |
This checks looks for assignemnts to variables using the
list(...)function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$aand$care used. There was no need to assign$b.Instead, the list call could have been.