Completed
Pull Request — master (#9)
by
unknown
08:00 queued 02:34
created

InterfaxMessage::sleep()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace NotificationChannels\Interfax;
4
5
use Illuminate\Support\Arr;
6
7
class InterfaxMessage
8
{
9
    protected $files;
10
    protected $stream;
11
    protected $filename;
12
    protected $method;
13
    protected $statusCheck = false;
14
    public $user;
15
16
    const FILES = 'files';
17
    const STREAM = 'stream';
18
19
    const POLLING_INTERVAL_DEFAULT = 15;
20
    const POLLING_INTERVAL_MINIMUM = 10;
21
22 8
    public function file(string $file)
23
    {
24 8
        $this->files = Arr::wrap($file);
25 8
        $this->method = static::FILES;
26
27 8
        return $this;
28
    }
29
30 3
    public function files(array $files)
31
    {
32 3
        $this->files = $files;
33 3
        $this->method = static::FILES;
34
35 3
        return $this;
36
    }
37
38 2
    public function stream($stream, string $filename)
39
    {
40 2
        $this->stream = $stream;
41 2
        $this->filename = $filename;
42 2
        $this->method = static::STREAM;
43
44 2
        return $this;
45
    }
46
47 8
    public function checkStatus(bool $shouldCheck = true)
48
    {
49 8
        $this->statusCheck = $shouldCheck;
50
51 8
        return $this;
52
    }
53
54 9
    public function shouldCheckStatus(): bool
55
    {
56 9
        return $this->statusCheck;
57
    }
58
59
    /**
60
     * Set a user who can be notified in case the fax fails to send.
61
     * @param  mixed $notifiable [description]
62
     * @return InterfaxMessage
63
     */
64 13
    public function user($notifiable)
65
    {
66 13
        $this->user = $notifiable;
67
68 13
        return $this;
69
    }
70
71 6
    public function makeFiles(): array
72
    {
73 6
        if ($this->method === static::STREAM) {
74
            return [
75
                [
76 2
                    $this->stream,
77
                    [
78 2
                        'name' => $this->filename,
79 2
                        'mime_type' => app('filesystem')->mimeType(pathinfo($this->filename, PATHINFO_BASENAME)),
80
                    ],
81
                ],
82
            ];
83
        }
84
85 4
        return $this->files;
86
    }
87
88 2
    public function sleep(): void
89
    {
90 2
        $interval = config('services.interfax.interval', static::POLLING_INTERVAL_DEFAULT);
91 2
        sleep(max($interval, static::POLLING_INTERVAL_MINIMUM));
92 2
    }
93
}
94