hooman-mirghasemi /
Laravel-iran-sms
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace HoomanMirghasemi\Sms\Drivers; |
||||||
| 4 | |||||||
| 5 | use HoomanMirghasemi\Sms\Abstracts\Driver; |
||||||
| 6 | use Kavenegar\KavenegarApi; |
||||||
| 7 | |||||||
| 8 | class Kavenegar extends Driver |
||||||
| 9 | { |
||||||
| 10 | protected string $from = ''; |
||||||
| 11 | |||||||
| 12 | public function __construct(protected array $settings, private KavenegarApi $kavenegarApi) |
||||||
| 13 | { |
||||||
| 14 | } |
||||||
| 15 | |||||||
| 16 | public function getBalance(): string |
||||||
| 17 | { |
||||||
| 18 | return ''; |
||||||
| 19 | } |
||||||
| 20 | |||||||
| 21 | public function send(): bool |
||||||
| 22 | { |
||||||
| 23 | try { |
||||||
| 24 | if ($this->message->usesTemplate()) { |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 25 | $template = $this->message->getTemplate(); |
||||||
|
0 ignored issues
–
show
The method
getTemplate() does not exist on HoomanMirghasemi\Sms\Contracts\Message. Since it exists in all sub-types, consider adding an abstract or default implementation to HoomanMirghasemi\Sms\Contracts\Message.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 26 | $identifier = $template['identifier']; |
||||||
| 27 | $params = $template['params']; |
||||||
| 28 | $token1 = str_replace(' ', '-', $params['token1'] ?? ''); |
||||||
| 29 | $token2 = str_replace(' ', '-', $params['token2'] ?? ''); |
||||||
| 30 | $token3 = str_replace(' ', '-', $params['token3'] ?? ''); |
||||||
| 31 | |||||||
| 32 | $token10 = $this->replaceExtraSpace($params['token10'] ?? '', 4); |
||||||
| 33 | $token20 = $this->replaceExtraSpace($params['token20'] ?? '', 8); |
||||||
| 34 | |||||||
| 35 | $result = $this->kavenegarApi->VerifyLookup( |
||||||
| 36 | $this->recipient, |
||||||
| 37 | $token1, |
||||||
| 38 | $token2, |
||||||
| 39 | $token3, |
||||||
| 40 | $identifier, |
||||||
| 41 | null, |
||||||
| 42 | $token10, |
||||||
| 43 | $token20 |
||||||
| 44 | ); |
||||||
| 45 | } else { |
||||||
| 46 | $result = $this->kavenegarApi->Send(null, $this->recipient, $this->message->toString()); |
||||||
| 47 | } |
||||||
| 48 | |||||||
| 49 | $this->success = true; |
||||||
| 50 | $this->from = $result[0]->sender; |
||||||
| 51 | $this->message = $result[0]->message; |
||||||
| 52 | $this->webserviceResponse = print_r($result, true); |
||||||
|
0 ignored issues
–
show
It seems like
print_r($result, true) can also be of type true. However, the property $webserviceResponse is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||||||
| 53 | } catch (\Exception $exception) { |
||||||
| 54 | $this->webserviceResponse = $exception->getMessage(); |
||||||
| 55 | $this->success = false; |
||||||
| 56 | } |
||||||
| 57 | |||||||
| 58 | return parent::send(); |
||||||
| 59 | } |
||||||
| 60 | |||||||
| 61 | private function replaceExtraSpace($string, $maxSpace) |
||||||
| 62 | { |
||||||
| 63 | $spaceCount = substr_count($string, ' '); |
||||||
| 64 | if ($spaceCount > $maxSpace) { |
||||||
| 65 | $string = strrev(preg_replace('/ /', '-', strrev($string), $spaceCount - $maxSpace)); |
||||||
| 66 | } |
||||||
| 67 | |||||||
| 68 | return $string; |
||||||
| 69 | } |
||||||
| 70 | } |
||||||
| 71 |