From 9296eafffc64ea5d2b5fd79d00e86849a96d65c5 Mon Sep 17 00:00:00 2001 From: Romain Monteil Date: Wed, 21 Aug 2019 13:17:03 +0200 Subject: [PATCH] [#138] fix issue with seq paramter in webhook Events, update API version to v3.3, add deprecation warning, add PHPStan to dev dependencies --- .editorconfig | 4 +++- .gitignore | 1 + .travis.yml | 6 +----- CHANGELOG.md | 10 ++++++++++ composer.json | 10 ++++++---- phpstan.neon | 9 +++++++++ src/Api/Broadcast.php | 13 ++++++------- src/Api/Code.php | 3 +++ src/Api/Nlp.php | 18 +++++++++--------- src/Api/Send.php | 18 +++++++----------- src/Api/User.php | 4 ++-- src/Event/AccountLinkingEvent.php | 2 +- src/Event/AppRolesEvent.php | 2 +- src/Event/DeliveryEvent.php | 2 +- src/Event/PolicyEnforcementEvent.php | 2 +- src/Event/ReadEvent.php | 2 +- src/Helper/UtilityTrait.php | 6 +++--- src/Helper/ValidatorTrait.php | 8 ++++---- src/Messenger.php | 2 +- src/Model/Callback/Delivery.php | 19 ++----------------- src/Model/Callback/Message.php | 18 +----------------- src/Model/Callback/MessageEcho.php | 5 +---- src/Model/Callback/Read.php | 19 ++----------------- src/Model/Callback/Referral.php | 10 +++++----- src/Model/Common/Button/Nested.php | 3 +++ src/Model/Common/Button/Share.php | 3 +++ src/Model/Data/Value.php | 4 ++-- src/Model/Message.php | 4 ++-- src/Model/Message/Attachment/Audio.php | 12 ++++++------ src/Model/Message/Attachment/File.php | 8 ++++---- src/Model/Message/Attachment/Image.php | 4 ++-- .../Template/Element/AbstractElement.php | 8 +++----- .../Template/Element/MediaElement.php | 16 ++++++++-------- .../Attachment/Template/ListTemplate.php | 8 +++++--- .../Attachment/Template/OpenGraphTemplate.php | 3 +++ src/Model/Message/Attachment/Video.php | 2 +- src/Model/Message/QuickReply.php | 4 +++- src/Response/AbstractResponse.php | 2 +- tests/Mocks/Callback/invalid_message.json | 1 - tests/Mocks/Callback/message.json | 3 +-- tests/Mocks/Callback/stand_by.json | 3 +-- tests/TestCase/Api/WebhookTest.php | 6 ++---- .../TestCase/Model/Callback/DeliveryTest.php | 3 +-- tests/TestCase/Model/Callback/EntryTest.php | 3 +-- .../Model/Callback/MessageEchoTest.php | 8 ++++++-- tests/TestCase/Model/Callback/MessageTest.php | 17 +++++++++++++---- tests/TestCase/Model/Callback/ReadTest.php | 3 +-- 47 files changed, 153 insertions(+), 168 deletions(-) create mode 100644 phpstan.neon diff --git a/.editorconfig b/.editorconfig index 8b5891e..fbedcb3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,5 +15,7 @@ trim_trailing_whitespace = true trim_trailing_whitespace = false [*.{json,yml}] -indent_style = space indent_size = 2 + +[*.neon] +indent_style = tab diff --git a/.gitignore b/.gitignore index e19247f..ba9bc44 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ vendor/ composer.lock .php_cs .php_cs.cache +.phpunit.result.cache phpunit.xml diff --git a/.travis.yml b/.travis.yml index af02d7f..61655a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,6 @@ env: matrix: fast_finish: true - allow_failures: - - php: 7.2 before_install: - composer self-update @@ -32,10 +30,8 @@ before_script: script: - vendor/bin/php-cs-fixer fix --diff --dry-run + - vendor/bin/phpstan --level=max --memory-limit="-1" --no-progress analyze - vendor/bin/phpunit --stderr --coverage-clover build/coverage/xml -after_script: - - vendor/bin/codacycoverage clover build/coverage/xml - notifications: email: false diff --git a/CHANGELOG.md b/CHANGELOG.md index af6ad4a..b3ee986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ The Messenger library follows [SemVer](http://semver.org/). ## 3.x +**Changelog** (since [`3.2.0`](https://github.com/ker0x/messenger/compare/3.1.1...3.2.0)) + +- 3.2.0 (2019-08) + - Update API version to `v3.3` + - Remove parameter `seq` from webhook Events (Thanks to @SoleneLms) + - Api Broadcast and Code are now deprecated (see [CHANGELOG](https://developers.facebook.com/docs/messenger-platform/changelog)) + - Template List and Open Graph are now deprecated (see [CHANGELOG](https://developers.facebook.com/docs/messenger-platform/changelog)) + - Button Share, Nested and Location for Quickreply are now deprecated (see [CHANGELOG](https://developers.facebook.com/docs/messenger-platform/changelog)) + - Add PHPStan for tests + **Changelog** (since [`3.1.0`](https://github.com/ker0x/messenger/compare/3.1.0...3.1.1)) - 3.1.1 (2018-12) diff --git a/composer.json b/composer.json index b3689a5..24d0f89 100644 --- a/composer.json +++ b/composer.json @@ -26,8 +26,9 @@ "psr/http-message": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.4", - "friendsofphp/php-cs-fixer": "^2.5" + "friendsofphp/php-cs-fixer": "^2.5", + "phpstan/phpstan": "^0.11.12", + "phpunit/phpunit": "^7.5" }, "autoload": { "psr-4": { @@ -40,8 +41,9 @@ } }, "scripts": { - "test": "phpunit", - "csfix": "php-cs-fixer fix --diff --verbose --config=.php_cs" + "php-stan": "vendor/bin/phpstan --level=max --memory-limit=\"-1\" --no-progress analyze", + "php-cs-fixer": "php-cs-fixer fix --diff --verbose --config=.php_cs", + "test": "phpunit" }, "config": { "optimize-autoloader": true, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..27fd438 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + paths: + - src + + ignoreErrors: + - '#Call to an undefined method GuzzleHttp\\ClientInterface::[a-zA-Z0-9_]+\(\)#' + + fileExtensions: + - php diff --git a/src/Api/Broadcast.php b/src/Api/Broadcast.php index 8e74e8a..723b15d 100644 --- a/src/Api/Broadcast.php +++ b/src/Api/Broadcast.php @@ -10,6 +10,9 @@ use Kerox\Messenger\Response\BroadcastResponse; use Kerox\Messenger\SendInterface; +/** + * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. + */ class Broadcast extends AbstractApi implements SendInterface { use ValidatorTrait; @@ -35,13 +38,13 @@ public function create($message): BroadcastResponse * @param string $messageCreativeId * @param array $options * - * @throws \Kerox\Messenger\Exception\InvalidOptionException + * @throws \Kerox\Messenger\Exception\MessengerException * * @return \Kerox\Messenger\Response\BroadcastResponse */ public function send(string $messageCreativeId, array $options = []): BroadcastResponse { - $options = $this->isValidOptions($options); + $this->isValidOptions($options); $request = new BroadcastRequest($this->pageToken, null, $messageCreativeId, $options); $response = $this->client->post('me/broadcast_messages', $request->build()); @@ -53,10 +56,8 @@ public function send(string $messageCreativeId, array $options = []): BroadcastR * @param array $options * * @throws \Kerox\Messenger\Exception\MessengerException - * - * @return array */ - private function isValidOptions(array $options): array + private function isValidOptions(array $options): void { $allowedOptionsKeys = $this->getAllowedOptionsKeys(); foreach ($options as $key => $value) { @@ -73,8 +74,6 @@ private function isValidOptions(array $options): array $this->isValidTag($value); } } - - return $options; } /** diff --git a/src/Api/Code.php b/src/Api/Code.php index fb0fb8d..c930812 100644 --- a/src/Api/Code.php +++ b/src/Api/Code.php @@ -10,6 +10,9 @@ use Kerox\Messenger\Request\CodeRequest; use Kerox\Messenger\Response\CodeResponse; +/** + * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. + */ class Code extends AbstractApi { private const CODE_TYPE_STANDARD = 'standard'; diff --git a/src/Api/Nlp.php b/src/Api/Nlp.php index ec65507..2844828 100644 --- a/src/Api/Nlp.php +++ b/src/Api/Nlp.php @@ -55,12 +55,12 @@ private function isValidConfigs(array $configs): void } /** - * @param string $key - * @param mixed $value + * @param int|string $key + * @param mixed $value * * @throws \Kerox\Messenger\Exception\MessengerException */ - private function isBool(string $key, $value): void + private function isBool($key, $value): void { if (!\is_bool($value) && \in_array($key, [self::CONFIG_KEY_NLP_ENABLED, self::CONFIG_KEY_VERBOSE], true) @@ -70,12 +70,12 @@ private function isBool(string $key, $value): void } /** - * @param string $key - * @param mixed $value + * @param int|string $key + * @param mixed $value * * @throws \Kerox\Messenger\Exception\MessengerException */ - private function isString(string $key, $value): void + private function isString($key, $value): void { if (!\is_string($value) && \in_array($key, [self::CONFIG_KEY_CUSTOM_TOKEN, self::CONFIG_KEY_MODEL], true) @@ -85,12 +85,12 @@ private function isString(string $key, $value): void } /** - * @param string $key - * @param mixed $value + * @param int|string $key + * @param mixed $value * * @throws \Kerox\Messenger\Exception\MessengerException */ - private function isValidNBest(string $key, $value): void + private function isValidNBest($key, $value): void { if ($key === self::CONFIG_KEY_N_BEST && (!\is_int($value) || $value < 1 || $value > 8)) { throw new InvalidTypeException(sprintf('%s must be an integer between 1 and 8.', $key)); diff --git a/src/Api/Send.php b/src/Api/Send.php index 90f4379..15845ca 100644 --- a/src/Api/Send.php +++ b/src/Api/Send.php @@ -17,9 +17,9 @@ class Send extends AbstractApi implements SendInterface use ValidatorTrait; /** - * @param string $recipient - * @param string|\Kerox\Messenger\Model\Message $message - * @param array $options + * @param string $recipient + * @param mixed $message + * @param array $options * * @throws \Exception * @@ -27,8 +27,8 @@ class Send extends AbstractApi implements SendInterface */ public function message(string $recipient, $message, array $options = []): SendResponse { + $this->isValidOptions($options, $message); $message = $this->isValidMessage($message); - $options = $this->isValidOptions($options, $message); $request = new SendRequest($this->pageToken, $message, $recipient, $options); $response = $this->client->post('me/messages', $request->build()); @@ -48,7 +48,7 @@ public function message(string $recipient, $message, array $options = []): SendR public function action(string $recipient, string $action, array $options = []): SendResponse { $this->isValidSenderAction($action); - $options = $this->isValidOptions($options, $action); + $this->isValidOptions($options); $request = new SendRequest($this->pageToken, $action, $recipient, $options, SendRequest::REQUEST_TYPE_ACTION); $response = $this->client->post('me/messages', $request->build()); @@ -75,13 +75,11 @@ public function attachment(Attachment $attachment): SendResponse /** * @param array $options - * @param $message + * @param mixed $message * * @throws \Kerox\Messenger\Exception\MessengerException - * - * @return array */ - private function isValidOptions(array $options, $message): array + private function isValidOptions(array $options, $message = null): void { $allowedOptionsKeys = $this->getAllowedOptionsKeys(); foreach ($options as $key => $value) { @@ -100,8 +98,6 @@ private function isValidOptions(array $options, $message): array $this->isValidTag($value, $message); } } - - return $options; } /** diff --git a/src/Api/User.php b/src/Api/User.php index 66dacd4..8e94cd6 100644 --- a/src/Api/User.php +++ b/src/Api/User.php @@ -12,8 +12,8 @@ class User extends AbstractApi implements UserInterface { /** - * @param string $userId - * @param array|null $fields + * @param string $userId + * @param array $fields * * @throws \Kerox\Messenger\Exception\MessengerException * diff --git a/src/Event/AccountLinkingEvent.php b/src/Event/AccountLinkingEvent.php index ba2cd9d..96cb289 100644 --- a/src/Event/AccountLinkingEvent.php +++ b/src/Event/AccountLinkingEvent.php @@ -61,7 +61,7 @@ public function getName(): string } /** - * @param $payload + * @param array $payload * * @return \Kerox\Messenger\Event\AccountLinkingEvent */ diff --git a/src/Event/AppRolesEvent.php b/src/Event/AppRolesEvent.php index e1c0925..e5ab23d 100644 --- a/src/Event/AppRolesEvent.php +++ b/src/Event/AppRolesEvent.php @@ -61,7 +61,7 @@ public function getName(): string } /** - * @param $payload + * @param array $payload * * @return \Kerox\Messenger\Event\AppRolesEvent */ diff --git a/src/Event/DeliveryEvent.php b/src/Event/DeliveryEvent.php index d38f7b5..7d25ff5 100644 --- a/src/Event/DeliveryEvent.php +++ b/src/Event/DeliveryEvent.php @@ -46,7 +46,7 @@ public function getName(): string } /** - * @param $payload + * @param array $payload * * @return \Kerox\Messenger\Event\DeliveryEvent */ diff --git a/src/Event/PolicyEnforcementEvent.php b/src/Event/PolicyEnforcementEvent.php index acd1fe1..4607493 100644 --- a/src/Event/PolicyEnforcementEvent.php +++ b/src/Event/PolicyEnforcementEvent.php @@ -65,7 +65,7 @@ public function getName(): string } /** - * @param $payload + * @param array $payload * * @return \Kerox\Messenger\Event\PolicyEnforcementEvent */ diff --git a/src/Event/ReadEvent.php b/src/Event/ReadEvent.php index 7a66567..bbfccfe 100644 --- a/src/Event/ReadEvent.php +++ b/src/Event/ReadEvent.php @@ -61,7 +61,7 @@ public function getName(): string } /** - * @param $payload + * @param array $payload * * @return \Kerox\Messenger\Event\ReadEvent */ diff --git a/src/Helper/UtilityTrait.php b/src/Helper/UtilityTrait.php index a11918d..79bab0b 100644 --- a/src/Helper/UtilityTrait.php +++ b/src/Helper/UtilityTrait.php @@ -9,12 +9,12 @@ trait UtilityTrait /** * Enhanced version of array_filter which allow to filter recursively. * - * @param array $array - * @param callable|array $callback + * @param array $array + * @param mixed $callback * * @return array */ - public function arrayFilter(array $array, array $callback = ['self', 'filter']): array + public function arrayFilter(array $array, $callback = ['self', 'filter']): array { foreach ($array as $k => $v) { if (\is_array($v)) { diff --git a/src/Helper/ValidatorTrait.php b/src/Helper/ValidatorTrait.php index c939f68..4ed4856 100644 --- a/src/Helper/ValidatorTrait.php +++ b/src/Helper/ValidatorTrait.php @@ -190,7 +190,7 @@ protected function isValidButtons(array $buttons, array $allowedButtonsType): vo } /** - * @param $message + * @param mixed $message * * @throws \Exception * @@ -246,13 +246,13 @@ protected function isValidNotificationType(string $notificationType): void } /** - * @param string $tag - * @param \Kerox\Messenger\Model\Message $message + * @param string $tag + * @param mixed $message * * @throws \Kerox\Messenger\Exception\InvalidClassException * @throws \Kerox\Messenger\Exception\InvalidKeyException */ - protected function isValidTag(string $tag, Message $message = null): void + protected function isValidTag(string $tag, $message = null): void { $allowedTag = $this->getAllowedTag(); if (!\in_array($tag, $allowedTag, true)) { diff --git a/src/Messenger.php b/src/Messenger.php index bd64ece..c70daa6 100644 --- a/src/Messenger.php +++ b/src/Messenger.php @@ -22,7 +22,7 @@ class Messenger { public const API_URL = 'https://graph.facebook.com/'; - public const API_VERSION = 'v3.2'; + public const API_VERSION = 'v3.3'; /** * @var string diff --git a/src/Model/Callback/Delivery.php b/src/Model/Callback/Delivery.php index 17b7cd1..bdee2b1 100644 --- a/src/Model/Callback/Delivery.php +++ b/src/Model/Callback/Delivery.php @@ -11,11 +11,6 @@ class Delivery */ protected $watermark; - /** - * @var int - */ - protected $sequence; - /** * @var array */ @@ -26,12 +21,10 @@ class Delivery * * @param array $messageIds * @param int $watermark - * @param int $sequence */ - public function __construct(int $watermark, int $sequence, array $messageIds = []) + public function __construct(int $watermark, array $messageIds = []) { $this->watermark = $watermark; - $this->sequence = $sequence; $this->messageIds = $messageIds; } @@ -43,14 +36,6 @@ public function getWatermark(): int return $this->watermark; } - /** - * @return int - */ - public function getSequence(): int - { - return $this->sequence; - } - /** * @return array */ @@ -68,6 +53,6 @@ public static function create(array $callbackData): self { $messageIds = $callbackData['mids'] ?? []; - return new self($callbackData['watermark'], $callbackData['seq'], $messageIds); + return new self($callbackData['watermark'], $messageIds); } } diff --git a/src/Model/Callback/Message.php b/src/Model/Callback/Message.php index 6be4e13..96461c7 100644 --- a/src/Model/Callback/Message.php +++ b/src/Model/Callback/Message.php @@ -11,11 +11,6 @@ class Message */ protected $messageId; - /** - * @var int - */ - protected $sequence; - /** * @var string|null */ @@ -40,7 +35,6 @@ class Message * Message constructor. * * @param string $messageId - * @param int $sequence * @param string $text * @param string $quickReply * @param array $attachments @@ -48,14 +42,12 @@ class Message */ public function __construct( string $messageId, - int $sequence, ?string $text = null, ?string $quickReply = null, array $attachments = [], array $entities = [] ) { $this->messageId = $messageId; - $this->sequence = $sequence; $this->text = $text; $this->quickReply = $quickReply; $this->attachments = $attachments; @@ -70,14 +62,6 @@ public function getMessageId(): string return $this->messageId; } - /** - * @return int - */ - public function getSequence(): int - { - return $this->sequence; - } - /** * @return string|null */ @@ -154,6 +138,6 @@ public static function create(array $callbackData) $attachments = $callbackData['attachments'] ?? []; $entities = $callbackData['nlp']['entities'] ?? []; - return new self($callbackData['mid'], $callbackData['seq'], $text, $quickReply, $attachments, $entities); + return new self($callbackData['mid'], $text, $quickReply, $attachments, $entities); } } diff --git a/src/Model/Callback/MessageEcho.php b/src/Model/Callback/MessageEcho.php index f0cfff3..9051777 100644 --- a/src/Model/Callback/MessageEcho.php +++ b/src/Model/Callback/MessageEcho.php @@ -27,7 +27,6 @@ class MessageEcho extends Message * @param bool $isEcho * @param int|null $appId * @param string $messageId - * @param int $sequence * @param string|null $metadata * @param string|null $text * @param string|null $quickReply @@ -37,13 +36,12 @@ public function __construct( bool $isEcho, ?int $appId, string $messageId, - int $sequence, ?string $metadata = null, ?string $text = null, ?string $quickReply = null, array $attachments = [] ) { - parent::__construct($messageId, $sequence, $text, $quickReply, $attachments); + parent::__construct($messageId, $text, $quickReply, $attachments); $this->isEcho = $isEcho; $this->appId = $appId; @@ -91,7 +89,6 @@ public static function create(array $callbackData) true, $appId, $callbackData['mid'], - $callbackData['seq'], $metadata, $text, $quickReply, diff --git a/src/Model/Callback/Read.php b/src/Model/Callback/Read.php index 19a7671..123a0c7 100644 --- a/src/Model/Callback/Read.php +++ b/src/Model/Callback/Read.php @@ -11,21 +11,14 @@ class Read */ protected $watermark; - /** - * @var int - */ - protected $sequence; - /** * Read constructor. * * @param int $watermark - * @param int $sequence */ - public function __construct(int $watermark, int $sequence) + public function __construct(int $watermark) { $this->watermark = $watermark; - $this->sequence = $sequence; } /** @@ -36,14 +29,6 @@ public function getWatermark(): int return $this->watermark; } - /** - * @return int - */ - public function getSequence(): int - { - return $this->sequence; - } - /** * @param array $callbackData * @@ -51,6 +36,6 @@ public function getSequence(): int */ public static function create(array $callbackData): self { - return new self($callbackData['watermark'], $callbackData['seq']); + return new self($callbackData['watermark']); } } diff --git a/src/Model/Callback/Referral.php b/src/Model/Callback/Referral.php index 4e6e864..31cba23 100644 --- a/src/Model/Callback/Referral.php +++ b/src/Model/Callback/Referral.php @@ -7,7 +7,7 @@ class Referral { /** - * @var mixed + * @var string|null */ protected $ref; @@ -24,11 +24,11 @@ class Referral /** * Referral constructor. * - * @param $ref + * @param string|null $ref * @param string|null $source * @param string|null $type */ - public function __construct($ref, ?string $source, ?string $type) + public function __construct(?string $ref, ?string $source, ?string $type) { $this->ref = $ref; $this->source = $source; @@ -36,9 +36,9 @@ public function __construct($ref, ?string $source, ?string $type) } /** - * @return mixed + * @return string|null */ - public function getRef() + public function getRef(): ?string { return $this->ref; } diff --git a/src/Model/Common/Button/Nested.php b/src/Model/Common/Button/Nested.php index 3483474..55aa406 100644 --- a/src/Model/Common/Button/Nested.php +++ b/src/Model/Common/Button/Nested.php @@ -4,6 +4,9 @@ namespace Kerox\Messenger\Model\Common\Button; +/** + * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. + */ class Nested extends AbstractButton { /** diff --git a/src/Model/Common/Button/Share.php b/src/Model/Common/Button/Share.php index be65b45..a9dc2f2 100644 --- a/src/Model/Common/Button/Share.php +++ b/src/Model/Common/Button/Share.php @@ -7,6 +7,9 @@ use Kerox\Messenger\Helper\UtilityTrait; use Kerox\Messenger\Model\Message\Attachment\Template\GenericTemplate; +/** + * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. + */ class Share extends AbstractButton { use UtilityTrait; diff --git a/src/Model/Data/Value.php b/src/Model/Data/Value.php index 71e45d8..03fdf23 100644 --- a/src/Model/Data/Value.php +++ b/src/Model/Data/Value.php @@ -29,8 +29,8 @@ public function __construct($value, string $endTime) } /** - * @param $value - * @param string $endTime + * @param int|array $value + * @param string $endTime * * @return \Kerox\Messenger\Model\Data\Value */ diff --git a/src/Model/Message.php b/src/Model/Message.php index 010312d..5b53929 100644 --- a/src/Model/Message.php +++ b/src/Model/Message.php @@ -62,7 +62,7 @@ public function __construct($message) } /** - * @param $message + * @param \Kerox\Messenger\Model\Message\Attachment|string $message * * @throws \Exception * @@ -106,7 +106,7 @@ public function addQuickReply(QuickReply $quickReply): self } /** - * @param mixed $metadata + * @param string $metadata * * @throws \Kerox\Messenger\Exception\MessengerException * diff --git a/src/Model/Message/Attachment/Audio.php b/src/Model/Message/Attachment/Audio.php index 6048529..95ecce1 100644 --- a/src/Model/Message/Attachment/Audio.php +++ b/src/Model/Message/Attachment/Audio.php @@ -11,25 +11,25 @@ class Audio extends File /** * Audio constructor. * - * @param string|int $url - * @param bool|null $reusable + * @param string $url + * @param bool|null $reusable * * @throws \Kerox\Messenger\Exception\MessengerException */ - public function __construct($url, ?bool $reusable = null) + public function __construct(string $url, ?bool $reusable = null) { parent::__construct($url, $reusable, Attachment::TYPE_AUDIO); } /** - * @param string|int $url - * @param bool|null $reusable + * @param string $url + * @param bool|null $reusable * * @throws \Kerox\Messenger\Exception\MessengerException * * @return \Kerox\Messenger\Model\Message\Attachment\File */ - public static function create($url, ?bool $reusable = null): File + public static function create(string $url, ?bool $reusable = null): File { return new self($url, $reusable); } diff --git a/src/Model/Message/Attachment/File.php b/src/Model/Message/Attachment/File.php index d99f7be..4bc4bca 100644 --- a/src/Model/Message/Attachment/File.php +++ b/src/Model/Message/Attachment/File.php @@ -32,7 +32,7 @@ class File extends Attachment * * @throws \Kerox\Messenger\Exception\MessengerException */ - public function __construct($url, ?bool $reusable = null, $type = Attachment::TYPE_FILE) + public function __construct(string $url, ?bool $reusable = null, $type = Attachment::TYPE_FILE) { parent::__construct($type); @@ -54,17 +54,17 @@ public function __construct($url, ?bool $reusable = null, $type = Attachment::TY * * @return \Kerox\Messenger\Model\Message\Attachment\File */ - public static function create($url, ?bool $reusable = null): self + public static function create(string $url, ?bool $reusable = null): self { return new self($url, $reusable); } /** - * @param $value + * @param string $value * * @return bool */ - private function isAttachmentId($value): bool + private function isAttachmentId(string $value): bool { return (bool) preg_match('/^[\d]+$/', $value); } diff --git a/src/Model/Message/Attachment/Image.php b/src/Model/Message/Attachment/Image.php index d20a175..7616791 100644 --- a/src/Model/Message/Attachment/Image.php +++ b/src/Model/Message/Attachment/Image.php @@ -18,7 +18,7 @@ class Image extends File * * @throws \Kerox\Messenger\Exception\MessengerException */ - public function __construct($url, ?bool $reusable = null) + public function __construct(string $url, ?bool $reusable = null) { $this->isValidExtension($url, $this->getAllowedExtensions()); @@ -33,7 +33,7 @@ public function __construct($url, ?bool $reusable = null) * * @return \Kerox\Messenger\Model\Message\Attachment\File */ - public static function create($url, ?bool $reusable = null): File + public static function create(string $url, ?bool $reusable = null): File { return new self($url, $reusable); } diff --git a/src/Model/Message/Attachment/Template/Element/AbstractElement.php b/src/Model/Message/Attachment/Template/Element/AbstractElement.php index 527966c..f4d898d 100644 --- a/src/Model/Message/Attachment/Template/Element/AbstractElement.php +++ b/src/Model/Message/Attachment/Template/Element/AbstractElement.php @@ -40,7 +40,7 @@ public function __construct(string $title) } /** - * @param mixed $subtitle + * @param string $subtitle * * @throws \Kerox\Messenger\Exception\MessengerException * @@ -54,7 +54,7 @@ public function setSubtitle(string $subtitle) } /** - * @param mixed $imageUrl + * @param string $imageUrl * * @throws \Kerox\Messenger\Exception\MessengerException * @@ -72,11 +72,9 @@ public function setImageUrl(string $imageUrl) */ public function toArray(): array { - $array = [ + return [ 'title' => $this->title, ]; - - return $array; } /** diff --git a/src/Model/Message/Attachment/Template/Element/MediaElement.php b/src/Model/Message/Attachment/Template/Element/MediaElement.php index f7cc99a..8c1b85c 100644 --- a/src/Model/Message/Attachment/Template/Element/MediaElement.php +++ b/src/Model/Message/Attachment/Template/Element/MediaElement.php @@ -38,12 +38,12 @@ class MediaElement implements \JsonSerializable /** * MediaElement constructor. * - * @param $url + * @param string $url * @param string $mediaType * * @throws \Kerox\Messenger\Exception\MessengerException */ - public function __construct($url, string $mediaType = self::TYPE_IMAGE) + public function __construct(string $url, string $mediaType = self::TYPE_IMAGE) { if ($this->isAttachmentId($url)) { $this->attachmentId = $url; @@ -57,14 +57,14 @@ public function __construct($url, string $mediaType = self::TYPE_IMAGE) } /** - * @param $url + * @param string $url * @param string $mediaType * * @throws \Kerox\Messenger\Exception\MessengerException * * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\MediaElement */ - public static function create($url, string $mediaType = self::TYPE_IMAGE): self + public static function create(string $url, string $mediaType = self::TYPE_IMAGE): self { return new self($url, $mediaType); } @@ -97,21 +97,21 @@ protected function getAllowedButtonsType(): array } /** - * @param $value + * @param string $value * * @return bool */ - private function isAttachmentId($value): bool + private function isAttachmentId(string $value): bool { return (bool) preg_match('/^[\d]+$/', $value); } /** - * @param $mediaType + * @param string $mediaType * * @throws \Kerox\Messenger\Exception\MessengerException */ - private function isValidMediaType($mediaType): void + private function isValidMediaType(string $mediaType): void { $allowedMediaType = $this->getAllowedMediaType(); if (!\in_array($mediaType, $allowedMediaType, true)) { diff --git a/src/Model/Message/Attachment/Template/ListTemplate.php b/src/Model/Message/Attachment/Template/ListTemplate.php index a03e0a3..2e7a069 100644 --- a/src/Model/Message/Attachment/Template/ListTemplate.php +++ b/src/Model/Message/Attachment/Template/ListTemplate.php @@ -7,10 +7,12 @@ use Kerox\Messenger\Exception\InvalidKeyException; use Kerox\Messenger\Model\Message\Attachment\Template; +/** + * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. + */ class ListTemplate extends Template { public const TOP_ELEMENT_STYLE_LARGE = 'large'; - public const TOP_ELEMENT_STYLE_COMPACT = 'compact'; /** @@ -19,7 +21,7 @@ class ListTemplate extends Template protected $topElementStyle; /** - * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListeElement[] + * @var \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement[] */ protected $elements = []; @@ -31,7 +33,7 @@ class ListTemplate extends Template /** * Liste constructor. * - * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListeElement[] $elements + * @param \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement[] $elements * * @throws \Kerox\Messenger\Exception\MessengerException */ diff --git a/src/Model/Message/Attachment/Template/OpenGraphTemplate.php b/src/Model/Message/Attachment/Template/OpenGraphTemplate.php index 8028891..9b0d523 100644 --- a/src/Model/Message/Attachment/Template/OpenGraphTemplate.php +++ b/src/Model/Message/Attachment/Template/OpenGraphTemplate.php @@ -6,6 +6,9 @@ use Kerox\Messenger\Model\Message\Attachment\Template; +/** + * @deprecated Since version 3.2.0 and will be removed in version 4.0.0. + */ class OpenGraphTemplate extends Template { /** diff --git a/src/Model/Message/Attachment/Video.php b/src/Model/Message/Attachment/Video.php index ce3f76b..aba33ec 100644 --- a/src/Model/Message/Attachment/Video.php +++ b/src/Model/Message/Attachment/Video.php @@ -29,7 +29,7 @@ public function __construct(string $url, ?bool $reusable = null) * * @return \Kerox\Messenger\Model\Message\Attachment\File */ - public static function create($url, ?bool $reusable = null): File + public static function create(string $url, ?bool $reusable = null): File { return new self($url, $reusable); } diff --git a/src/Model/Message/QuickReply.php b/src/Model/Message/QuickReply.php index 71134e0..6bd5668 100644 --- a/src/Model/Message/QuickReply.php +++ b/src/Model/Message/QuickReply.php @@ -12,10 +12,12 @@ class QuickReply implements \JsonSerializable use ValidatorTrait; public const CONTENT_TYPE_TEXT = 'text'; - public const CONTENT_TYPE_LOCATION = 'location'; public const CONTENT_TYPE_PHONE = 'user_phone_number'; public const CONTENT_TYPE_EMAIL = 'user_email'; + /** @deprecated Since version 3.2.0 and will be removed in version 4.0.0. */ + public const CONTENT_TYPE_LOCATION = 'location'; + /** * @var string */ diff --git a/src/Response/AbstractResponse.php b/src/Response/AbstractResponse.php index 2818f76..661cd44 100644 --- a/src/Response/AbstractResponse.php +++ b/src/Response/AbstractResponse.php @@ -32,7 +32,7 @@ public function __construct(ResponseInterface $response) */ private function decodeResponse(ResponseInterface $response): array { - return json_decode($response->getBody()->__toString(), true); + return json_decode((string) $response->getBody(), true); } /** diff --git a/tests/Mocks/Callback/invalid_message.json b/tests/Mocks/Callback/invalid_message.json index 2f8fe9c..7100583 100644 --- a/tests/Mocks/Callback/invalid_message.json +++ b/tests/Mocks/Callback/invalid_message.json @@ -15,7 +15,6 @@ "timestamp": 1458692752478, "message": { "mid": "mid.1457764197618:41d102a3e1ae206a38", - "seq": 73, "text": "hello, world!", "quick_reply": { "payload": "DEVELOPER_DEFINED_PAYLOAD" diff --git a/tests/Mocks/Callback/message.json b/tests/Mocks/Callback/message.json index a4a5dee..67ada00 100644 --- a/tests/Mocks/Callback/message.json +++ b/tests/Mocks/Callback/message.json @@ -15,7 +15,6 @@ "timestamp": 1458692752478, "message": { "mid": "mid.1457764197618:41d102a3e1ae206a38", - "seq": 73, "text": "hello, world!", "quick_reply": { "payload": "DEVELOPER_DEFINED_PAYLOAD" @@ -25,4 +24,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/Mocks/Callback/stand_by.json b/tests/Mocks/Callback/stand_by.json index 9ca3713..2408917 100644 --- a/tests/Mocks/Callback/stand_by.json +++ b/tests/Mocks/Callback/stand_by.json @@ -15,7 +15,6 @@ "timestamp": 1458692752478, "message": { "mid": "mid.1457764197618:41d102a3e1ae206a38", - "seq": 73, "text": "hello, world!", "quick_reply": { "payload": "DEVELOPER_DEFINED_PAYLOAD" @@ -25,4 +24,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/tests/TestCase/Api/WebhookTest.php b/tests/TestCase/Api/WebhookTest.php index aab873e..2829848 100644 --- a/tests/TestCase/Api/WebhookTest.php +++ b/tests/TestCase/Api/WebhookTest.php @@ -97,7 +97,6 @@ public function testGetDecodedBody(): void 'timestamp' => 1458692752478, 'message' => [ 'mid' => 'mid.1457764197618:41d102a3e1ae206a38', - 'seq' => 73, 'text' => 'hello, world!', 'quick_reply' => [ 'payload' => 'DEVELOPER_DEFINED_PAYLOAD', @@ -128,7 +127,6 @@ public function testGetCallbackEntries(): void 'timestamp' => 1458692752478, 'message' => [ 'mid' => 'mid.1457764197618:41d102a3e1ae206a38', - 'seq' => 73, 'text' => 'hello, world!', 'quick_reply' => [ 'payload' => 'DEVELOPER_DEFINED_PAYLOAD', @@ -147,7 +145,7 @@ public function testGetCallbackEntries(): void public function testGetCallbackEvents(): void { - $event = new MessageEvent('USER_ID', 'PAGE_ID', 1458692752478, new Message('mid.1457764197618:41d102a3e1ae206a38', 73, 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD')); + $event = new MessageEvent('USER_ID', 'PAGE_ID', 1458692752478, new Message('mid.1457764197618:41d102a3e1ae206a38', 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD')); $events = $this->webhookApi->getCallbackEvents(); @@ -178,7 +176,7 @@ public function testStandbyEntry(): void 'handler' => $handler, ]); - $event = new MessageEvent('USER_ID', 'PAGE_ID', 1458692752478, new Message('mid.1457764197618:41d102a3e1ae206a38', 73, 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD')); + $event = new MessageEvent('USER_ID', 'PAGE_ID', 1458692752478, new Message('mid.1457764197618:41d102a3e1ae206a38', 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD')); $webhookApi = new Webhook($appSecret, $verifyToken, $pageToken, $client, $request); $events = $webhookApi->getCallbackEvents(); diff --git a/tests/TestCase/Model/Callback/DeliveryTest.php b/tests/TestCase/Model/Callback/DeliveryTest.php index e18d9bd..d2f6a3c 100644 --- a/tests/TestCase/Model/Callback/DeliveryTest.php +++ b/tests/TestCase/Model/Callback/DeliveryTest.php @@ -11,10 +11,9 @@ class DeliveryTest extends AbstractTestCase { public function testDeliveryCallback(): void { - $delivery = new Delivery(1458668856253, 35, ['mid.1458668856218:ed81099e15d3f4f233']); + $delivery = new Delivery(1458668856253, ['mid.1458668856218:ed81099e15d3f4f233']); $this->assertSame(1458668856253, $delivery->getWatermark()); - $this->assertSame(35, $delivery->getSequence()); $this->assertSame(['mid.1458668856218:ed81099e15d3f4f233'], $delivery->getMessageIds()); } } diff --git a/tests/TestCase/Model/Callback/EntryTest.php b/tests/TestCase/Model/Callback/EntryTest.php index 8efab9d..f9fea80 100644 --- a/tests/TestCase/Model/Callback/EntryTest.php +++ b/tests/TestCase/Model/Callback/EntryTest.php @@ -27,7 +27,6 @@ public function testEntryCallback(): void 'timestamp' => 1458692752478, 'message' => [ 'mid' => 'mid.1457764197618:41d102a3e1ae206a38', - 'seq' => 73, 'text' => 'hello, world!', 'quick_reply' => [ 'payload' => 'DEVELOPER_DEFINED_PAYLOAD', @@ -37,7 +36,7 @@ public function testEntryCallback(): void ], ]; - $messageEvent = new MessageEvent('USER_ID', 'PAGE_ID', 1458692752478, new Message('mid.1457764197618:41d102a3e1ae206a38', 73, 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD')); + $messageEvent = new MessageEvent('USER_ID', 'PAGE_ID', 1458692752478, new Message('mid.1457764197618:41d102a3e1ae206a38', 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD')); $entry = Entry::create($payload); $this->assertSame('PAGE_ID', $entry->getId()); diff --git a/tests/TestCase/Model/Callback/MessageEchoTest.php b/tests/TestCase/Model/Callback/MessageEchoTest.php index 63fccaf..448840a 100644 --- a/tests/TestCase/Model/Callback/MessageEchoTest.php +++ b/tests/TestCase/Model/Callback/MessageEchoTest.php @@ -11,12 +11,16 @@ class MessageEchoTest extends AbstractTestCase { public function testMessageEchoCallback(): void { - $messageEcho = new MessageEcho(true, 1517776481860111, 'mid.1457764197618:41d102a3e1ae206a38', 73, 'DEVELOPER_DEFINED_METADATA_STRING'); + $messageEcho = new MessageEcho( + true, + 1517776481860111, + 'mid.1457764197618:41d102a3e1ae206a38', + 'DEVELOPER_DEFINED_METADATA_STRING' + ); $this->assertTrue($messageEcho->isEcho()); $this->assertSame(1517776481860111, $messageEcho->getAppId()); $this->assertSame('DEVELOPER_DEFINED_METADATA_STRING', $messageEcho->getMetadata()); $this->assertSame('mid.1457764197618:41d102a3e1ae206a38', $messageEcho->getMessageId()); - $this->assertSame(73, $messageEcho->getSequence()); } } diff --git a/tests/TestCase/Model/Callback/MessageTest.php b/tests/TestCase/Model/Callback/MessageTest.php index 36796a1..89d336f 100644 --- a/tests/TestCase/Model/Callback/MessageTest.php +++ b/tests/TestCase/Model/Callback/MessageTest.php @@ -11,10 +11,21 @@ class MessageTest extends AbstractTestCase { public function testMessageCallback(): void { - $message = new Message('mid.1457764197618:41d102a3e1ae206a38', 73, 'hello, world!', 'DEVELOPER_DEFINED_PAYLOAD', [['type' => 'image', 'payload' => ['url' => 'IMAGE_URL']]]); + $message = new Message( + 'mid.1457764197618:41d102a3e1ae206a38', + 'hello, world!', + 'DEVELOPER_DEFINED_PAYLOAD', + [ + [ + 'type' => 'image', + 'payload' => [ + 'url' => 'IMAGE_URL' + ] + ] + ] + ); $this->assertSame('mid.1457764197618:41d102a3e1ae206a38', $message->getMessageId()); - $this->assertSame(73, $message->getSequence()); $this->assertSame('hello, world!', $message->getText()); $this->assertSame('DEVELOPER_DEFINED_PAYLOAD', $message->getQuickReply()); $this->assertSame([['type' => 'image', 'payload' => ['url' => 'IMAGE_URL']]], $message->getAttachments()); @@ -27,7 +38,6 @@ public function testMessageModelWithEmptyStringAndEmptyQuickReply(): void { $message = Message::create([ 'mid' => 'mid.1457764197618:41d102a3e1ae206a38', - 'seq' => 73, 'text' => '', 'quick_reply' => [ 'payload' => '', @@ -37,7 +47,6 @@ public function testMessageModelWithEmptyStringAndEmptyQuickReply(): void ]); $this->assertSame('mid.1457764197618:41d102a3e1ae206a38', $message->getMessageId()); - $this->assertSame(73, $message->getSequence()); $this->assertSame('', $message->getText()); $this->assertSame('', $message->getQuickReply()); $this->assertSame([], $message->getAttachments()); diff --git a/tests/TestCase/Model/Callback/ReadTest.php b/tests/TestCase/Model/Callback/ReadTest.php index fe5daa0..964609d 100644 --- a/tests/TestCase/Model/Callback/ReadTest.php +++ b/tests/TestCase/Model/Callback/ReadTest.php @@ -11,9 +11,8 @@ class ReadTest extends AbstractTestCase { public function testReadCallback(): void { - $read = new Read(1458668856253, 38); + $read = new Read(1458668856253); $this->assertSame(1458668856253, $read->getWatermark()); - $this->assertSame(38, $read->getSequence()); } }