Completed
Pull Request — master (#216)
by Sergey
03:15 queued 46s
created

Conversations::guardAgainstEmptyData()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 3
nc 2
nop 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
6
use seregazhuk\PinterestBot\Api\Traits\SendsMessages;
7
use seregazhuk\PinterestBot\Exceptions\InvalidRequest;
8
9
class Conversations extends Provider
10
{
11
    use SendsMessages;
12
13
    /**
14
     * @var array
15
     */
16
    protected $loginRequiredFor = [
17
        'last',
18
        'sendMessage',
19
        'sendEmail'
20
    ];
21
22
    /**
23
     * Send message to a user.
24
     *
25
     * @param array|int $userIds
26
     * @param string $text
27
     * @param int|null $pinId
28
     *
29
     * @throws InvalidRequest
30
     *
31
     * @return bool
32
     */
33
    public function sendMessage($userIds, $text, $pinId = null)
34
    {
35
        $messageData = $this->buildMessageData($text, $pinId);
36
37
        return $this->callSendMessage($userIds, [], $messageData);
38
    }
39
40
    /**
41
     * Send email.
42
     *
43
     * @param array|int $emails
44
     * @param string $text
45
     * @param int|null $pinId
46
     *
47
     * @throws InvalidRequest
48
     *
49
     * @return bool
50
     */
51
    public function sendEmail($emails, $text, $pinId = null)
52
    {
53
        $messageData = $this->buildMessageData($text, $pinId);
54
55
        return $this->callSendMessage([], $emails, $messageData);
0 ignored issues
show
Bug introduced by
It seems like $emails defined by parameter $emails on line 51 can also be of type integer; however, seregazhuk\PinterestBot\...ages::callSendMessage() does only seem to accept array|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
56
    }
57
58
    /**
59
     * Get last user conversations.
60
     *
61
     * @return array|bool
62
     */
63
    public function last()
64
    {
65
        return $this->execGetRequest([], UrlBuilder::RESOURCE_GET_LAST_CONVERSATIONS);
66
    }
67
}
68