These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace NotificationChannels\Trello; |
||
4 | |||
5 | use GuzzleHttp\Client; |
||
6 | use Illuminate\Notifications\Notification; |
||
7 | use Illuminate\Support\Arr; |
||
8 | use NotificationChannels\Trello\Exceptions\CouldNotAddComment; |
||
9 | use NotificationChannels\Trello\Exceptions\CouldNotSendNotification; |
||
10 | use NotificationChannels\Trello\Exceptions\InvalidConfiguration; |
||
11 | |||
12 | class TrelloChannel |
||
13 | { |
||
14 | const API_ENDPOINT = 'https://api.trello.com/1/cards/'; |
||
15 | |||
16 | /** @var Client */ |
||
17 | protected $client; |
||
18 | |||
19 | /** @var key trello key */ |
||
20 | protected $key; |
||
21 | |||
22 | /** @param Client $client */ |
||
23 | public function __construct(Client $client) |
||
24 | { |
||
25 | $this->client = $client; |
||
26 | $this->key = config('services.trello.key'); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Send the given notification. |
||
31 | * |
||
32 | * @param mixed $notifiable |
||
33 | * @param \Illuminate\Notifications\Notification $notification |
||
34 | * |
||
35 | * @throws \NotificationChannels\Trello\Exceptions\InvalidConfiguration |
||
36 | * @throws \NotificationChannels\Trello\Exceptions\CouldNotSendNotification |
||
37 | * @throws \NotificationChannels\Trello\Exceptions\CouldAddComment |
||
38 | */ |
||
39 | public function send($notifiable, Notification $notification) |
||
40 | { |
||
41 | if (!$routing = collect($notifiable->routeNotificationFor('Trello'))) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | if (is_null($this->key)) { |
||
46 | throw InvalidConfiguration::configurationNotSet(); |
||
47 | } |
||
48 | |||
49 | $trelloParameters = $notification->toTrello($notifiable)->toArray(); |
||
50 | $trelloCardComments = $notification->toTrello($notifiable)->getComments(); |
||
51 | |||
52 | $response = $this->client->post(self::API_ENDPOINT . '?key=' . $this->key . '&token=' . $routing->get('token'), [ |
||
53 | 'form_params' => Arr::set($trelloParameters, 'idList', $routing->get('idList')), |
||
54 | ]); |
||
55 | |||
56 | if ($response->getStatusCode() !== 200) { |
||
57 | throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
||
58 | } |
||
59 | |||
60 | if ($trelloCardComments) { |
||
61 | $this->addComments($notifiable, $trelloCardComments, $response); |
||
0 ignored issues
–
show
|
|||
62 | } |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Add comments to newly created card. |
||
67 | * @param mixed $notifiable |
||
68 | * @param array $trelloCardComments array holding the comments to add |
||
69 | * @param Response $response response object from the trello api |
||
70 | * |
||
71 | * @throws \NotificationChannels\Trello\Exceptions\CouldAddComment |
||
72 | */ |
||
73 | public function addComments($notifiable, array $trelloCardComments, $response) |
||
74 | { |
||
75 | if (!$routing = collect($notifiable->routeNotificationFor('Trello'))) { |
||
76 | return; |
||
77 | } |
||
78 | |||
79 | $cardId = json_decode($response->getBody()->getContents())->id; |
||
80 | foreach ($trelloCardComments as $comment) { |
||
81 | $response = $this->client->post(self::API_ENDPOINT . $cardId . '/actions/comments?key=' . $this->key . '&token=' . $routing->get('token'), [ |
||
82 | 'form_params' => ['text' => $comment], |
||
83 | ]); |
||
84 | if ($response->getStatusCode() !== 200) { |
||
85 | throw CouldNotAddComment::serviceRespondedWithAnError($response); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | } |
||
91 |
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: