Completed
Push — master ( 4656f5...b898f3 )
by Hilmi Erdem
01:33
created

JetSmsService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 76
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A sendShortMessage() 0 6 1
A sendShortMessages() 0 13 2
1
<?php
2
3
namespace Erdemkeren\JetSms;
4
5
use Erdemkeren\JetSms\Http\Clients\JetSmsClientInterface;
6
use Erdemkeren\JetSms\Http\Responses\JetSmsResponseInterface;
7
8
/**
9
 * Class JetSmsService.
10
 */
11
final class JetSmsService
12
{
13
    /**
14
     * The jet sms client implementation.
15
     *
16
     * @var JetSmsClientInterface
17
     */
18
    private $client;
19
20
    /**
21
     * The short message factory implementation.
22
     *
23
     * @var ShortMessageFactoryInterface
24
     */
25
    private $factory;
26
27
    /**
28
     * The short message collection factory implementation.
29
     *
30
     * @var ShortMessageFactoryInterface
31
     */
32
    private $collectionFactory;
33
34
    /**
35
     * JetSmsService constructor.
36
     *
37
     * @param  JetSmsClientInterface        $jetSmsClient
38
     * @param  ShortMessageFactoryInterface $shortMessageFactory
39
     * @param  ShortMessageCollectionFactoryInterface $shortMessageCollectionFactory
40
     */
41 3
    public function __construct(
42
        JetSmsClientInterface $jetSmsClient,
43
        ShortMessageFactoryInterface $shortMessageFactory,
44
        ShortMessageCollectionFactoryInterface $shortMessageCollectionFactory
45
    ) {
46 3
        $this->client = $jetSmsClient;
47 3
        $this->factory = $shortMessageFactory;
48 3
        $this->collectionFactory = $shortMessageCollectionFactory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $shortMessageCollectionFactory of type object<Erdemkeren\JetSms...ectionFactoryInterface> is incompatible with the declared type object<Erdemkeren\JetSms...essageFactoryInterface> of property $collectionFactory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49 3
    }
50
51
    /**
52
     * Send the given body to the given receivers.
53
     *
54
     * @param  string       $body      The body of the short message.
55
     * @param  array|string $receivers The receiver(s) of the message.
56
     *
57
     * @return JetSmsResponseInterface The parsed JetSms response object.
58
     */
59 2
    public function sendShortMessage($receivers, $body)
60
    {
61 2
        $shortMessage = $this->factory->create($receivers, $body);
62
63 2
        return $this->client->sendShortMessage($shortMessage);
64
    }
65
66
    /**
67
     * Send the given short messages.
68
     *
69
     * @param  array $messages         An array containing short message arrays.
70
     *
71
     * @return JetSmsResponseInterface The parsed JetSms response object.
72
     */
73 1
    public function sendShortMessages(array $messages)
74
    {
75 1
        $collection = $this->collectionFactory->create();
0 ignored issues
show
Bug introduced by
The call to create() misses some required arguments starting with $receivers.
Loading history...
76
77 1
        foreach ($messages as $message) {
78 1
            $collection->push($this->factory->create(
0 ignored issues
show
Bug introduced by
The method push() does not seem to exist on object<Erdemkeren\JetSms\ShortMessage>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79 1
                $message['recipient'],
80 1
                $message['message']
81 1
            ));
82 1
        }
83
84 1
        return $this->client->sendShortMessages($collection);
0 ignored issues
show
Documentation introduced by
$collection is of type object<Erdemkeren\JetSms\ShortMessage>, but the function expects a object<Erdemkeren\JetSms\ShortMessageCollection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
    }
86
}
87