FakeSmsSender   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 11 2
A __construct() 0 3 1
A getBalance() 0 3 1
1
<?php
2
3
namespace HoomanMirghasemi\Sms\Drivers;
4
5
use HoomanMirghasemi\Sms\Abstracts\Driver;
6
7
class FakeSmsSender extends Driver
8
{
9
    /**
10
     * The Faker sms send sms success of fail.
11
     *
12
     * @var bool
13
     */
14
    public static bool $successSend = true;
15
16
    public function __construct(protected array $settings)
17
    {
18
        $this->from = data_get($this->settings, 'from');
19
    }
20
21
    /**
22
     * Send sms method for Magfa.
23
     *
24
     * This method send sms and save log to db.
25
     *
26
     * @return bool
27
     */
28
    public function send(): bool
29
    {
30
        if (!self::$successSend) {
31
            $this->webserviceResponse = 'An error happened !';
32
            $this->success = false;
33
        } else {
34
            $this->webserviceResponse = 'Message has been successfully sent ; MessageId : '.rand(1, 1000000);
35
            $this->success = true;
36
        }
37
38
        return parent::send();
39
    }
40
41
    /**
42
     * Return fake balance :D.
43
     *
44
     * @return string
45
     */
46
    public function getBalance(): string
47
    {
48
        return rand(0, 250000);
49
    }
50
}
51