Broadcast::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Api;
6
7
use Kerox\Messenger\Exception\InvalidOptionException;
8
use Kerox\Messenger\Helper\ValidatorTrait;
9
use Kerox\Messenger\Request\BroadcastRequest;
10
use Kerox\Messenger\Response\BroadcastResponse;
11
use Kerox\Messenger\SendInterface;
12
13
/**
14
 * @deprecated Since version 3.2.0 and will be removed in version 4.0.0.
15
 */
16
class Broadcast extends AbstractApi implements SendInterface
17
{
18
    use ValidatorTrait;
19
20
    /**
21
     * @param string|\Kerox\Messenger\Model\Message $message
22
     *
23
     * @throws \Exception
24
     */
25 1 View Code Duplication
    public function create($message): BroadcastResponse
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27 1
        $message = $this->isValidMessage($message);
28
29 1
        $request = new BroadcastRequest($this->pageToken, $message);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Request\BroadcastRequest has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
30 1
        $response = $this->client->post('me/message_creatives', $request->build());
31
32 1
        return new BroadcastResponse($response);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Response\BroadcastResponse has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
33
    }
34
35
    /**
36
     * @throws \Kerox\Messenger\Exception\MessengerException
37
     */
38 1 View Code Duplication
    public function send(string $messageCreativeId, array $options = []): BroadcastResponse
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40 1
        $this->isValidOptions($options);
41
42 1
        $request = new BroadcastRequest($this->pageToken, null, $messageCreativeId, $options);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Request\BroadcastRequest has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
43 1
        $response = $this->client->post('me/broadcast_messages', $request->build());
44
45 1
        return new BroadcastResponse($response);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Response\BroadcastResponse has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
46
    }
47
48
    /**
49
     * @throws \Kerox\Messenger\Exception\MessengerException
50
     */
51 1
    private function isValidOptions(array $options): void
52
    {
53 1
        $allowedOptionsKeys = $this->getAllowedOptionsKeys();
54 1
        foreach ($options as $key => $value) {
55 View Code Duplication
            if (!\in_array($key, $allowedOptionsKeys, true)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
                throw new InvalidOptionException(sprintf('Only "%s" are allowed keys for options.', implode(', ', $allowedOptionsKeys)));
57
            }
58
59
            if ($key === self::OPTION_NOTIFICATION_TYPE) {
60
                $this->isValidNotificationType($value);
61
            } elseif ($key === self::OPTION_TAG) {
62
                $this->isValidTag($value);
63
            }
64
        }
65 1
    }
66
67 1
    private function getAllowedOptionsKeys(): array
68
    {
69
        return [
70 1
            self::OPTION_NOTIFICATION_TYPE,
71 1
            self::OPTION_TAG,
72
        ];
73
    }
74
}
75