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\Provider; |
||
| 4 | |||
| 5 | use Doctrine\ORM\EntityManager; |
||
| 6 | use DoS\ResourceBundle\Doctrine\ORM\EntityRepository; |
||
| 7 | use DoS\ResourceBundle\Factory\ResourceFactoryAware; |
||
| 8 | use DoS\SMSBundle\Model\RecordInterface; |
||
| 9 | use DoS\SMSBundle\SMS\ProviderInterface; |
||
| 10 | use libphonenumber\PhoneNumberUtil; |
||
| 11 | use SmsSender\Result\ResultInterface; |
||
| 12 | use Symfony\Component\EventDispatcher\Event; |
||
| 13 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
| 14 | use Symfony\Component\EventDispatcher\GenericEvent; |
||
| 15 | |||
| 16 | class RecordProvider extends ResourceFactoryAware |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var ProviderProvider |
||
| 20 | */ |
||
| 21 | protected $provider; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var EventDispatcherInterface |
||
| 25 | */ |
||
| 26 | protected $eventDispatcher; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var EntityManager |
||
| 30 | */ |
||
| 31 | protected $manager; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var EntityRepository |
||
| 35 | */ |
||
| 36 | protected $repository; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $dataClass; |
||
| 42 | |||
| 43 | public function __construct( |
||
| 44 | EventDispatcherInterface $eventDispatcher, |
||
| 45 | ProviderProvider $provider, |
||
| 46 | EntityManager $manager, |
||
|
0 ignored issues
–
show
|
|||
| 47 | $dataClass |
||
| 48 | ) { |
||
| 49 | $this->eventDispatcher = $eventDispatcher; |
||
| 50 | $this->provider = $provider; |
||
| 51 | $this->manager = $manager; |
||
| 52 | $this->dataClass = $dataClass; |
||
| 53 | $this->repository = $manager->getRepository($dataClass); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return ProviderProvider |
||
| 58 | */ |
||
| 59 | public function getProvider() |
||
| 60 | { |
||
| 61 | return $this->provider; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param $name |
||
| 66 | * |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | public function getProviderParameters($name) |
||
| 70 | { |
||
| 71 | return $this->provider->getParameters($name); |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return RecordInterface |
||
| 76 | */ |
||
| 77 | public function createNew() |
||
| 78 | { |
||
| 79 | return $this->factory->createNew(); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param $transactionId |
||
| 84 | * |
||
| 85 | * @return null|RecordInterface |
||
| 86 | */ |
||
| 87 | public function findTransactionId($transactionId) |
||
| 88 | { |
||
| 89 | return $this->repository->findOneBy( |
||
| 90 | array( |
||
| 91 | 'transactionId' => $transactionId, |
||
| 92 | ) |
||
| 93 | ); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param ResultInterface $result |
||
| 98 | * |
||
| 99 | * @return RecordInterface |
||
| 100 | */ |
||
| 101 | public function storeResult(ResultInterface $result) |
||
| 102 | { |
||
| 103 | $number = PhoneNumberUtil::getInstance()->parse($result->getRecipient(), 'TH'); |
||
| 104 | $provider = $this->provider->getActivedProvider(); |
||
| 105 | $object = $this->createNew(); |
||
| 106 | |||
| 107 | $object->setMessage($result->getBody()); |
||
| 108 | $object->setTransactionId($result->getId()); |
||
| 109 | $object->setNumber($number); |
||
| 110 | $object->setState($object::STATE_SENT); |
||
| 111 | $object->setPrice($provider->getPrice()); |
||
| 112 | $object->setProvider($provider); |
||
| 113 | $object->setCurrency($provider->getCurrency()); |
||
| 114 | |||
| 115 | $event = new GenericEvent($object); |
||
| 116 | |||
| 117 | $this->dispatchEvent('dos_sms_record_pre_store', $event); |
||
| 118 | |||
| 119 | $this->manager->persist($object); |
||
| 120 | $this->manager->flush(); |
||
| 121 | |||
| 122 | $this->dispatchEvent('dos_sms_record_post_store', $event); |
||
| 123 | |||
| 124 | return $object; |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param string $name |
||
| 129 | * @param Event $event |
||
| 130 | * |
||
| 131 | * @return Event |
||
| 132 | */ |
||
| 133 | public function dispatchEvent($name, Event $event) |
||
| 134 | { |
||
| 135 | return $this->eventDispatcher->dispatch($name, $event); |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param ProviderInterface $provider |
||
| 140 | */ |
||
| 141 | public function visit(ProviderInterface $provider) |
||
| 142 | { |
||
| 143 | foreach ($provider->getCallbackResults() as $result) { |
||
| 144 | if ($record = $this->findTransactionId($result->getMessageId())) { |
||
|
0 ignored issues
–
show
Are you sure the assignment to
$record is correct as $this->findTransactionId($result->getMessageId()) (which targets DoS\SMSBundle\Provider\R...er::findTransactionId()) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 145 | $record->responded($result->getData(), $result->isSuccess()); |
||
| 146 | $record->setPrice($result->getPrice()); |
||
| 147 | |||
| 148 | $event = new GenericEvent($record); |
||
| 149 | |||
| 150 | $this->dispatchEvent('dos_sms_record_pre_response', $event); |
||
| 151 | |||
| 152 | $this->manager->persist($record); |
||
| 153 | $this->manager->flush(); |
||
| 154 | |||
| 155 | $this->dispatchEvent('dos_sms_record_post_response', $event); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 |
The
EntityManagermight become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManageris closed. Any other code which depends on the same instance of theEntityManagerduring this request will fail.On the other hand, if you instead inject the
ManagerRegistry, thegetManager()method guarantees that you will always get a usable manager instance.