Skip to content

Commit

Permalink
Merge pull request #139 from ker0x/hotfix/webhook-events
Browse files Browse the repository at this point in the history
[#138] fix issue with seq paramter in webhook Events, update API vers…
  • Loading branch information
ker0x authored Aug 21, 2019
2 parents 7f2fabf + 9296eaf commit c30bd6f
Show file tree
Hide file tree
Showing 47 changed files with 153 additions and 168 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ trim_trailing_whitespace = true
trim_trailing_whitespace = false

[*.{json,yml}]
indent_style = space
indent_size = 2

[*.neon]
indent_style = tab
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor/
composer.lock
.php_cs
.php_cs.cache
.phpunit.result.cache
phpunit.xml
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ env:

matrix:
fast_finish: true
allow_failures:
- php: 7.2

before_install:
- composer self-update
Expand All @@ -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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
paths:
- src

ignoreErrors:
- '#Call to an undefined method GuzzleHttp\\ClientInterface::[a-zA-Z0-9_]+\(\)#'

fileExtensions:
- php
13 changes: 6 additions & 7 deletions src/Api/Broadcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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) {
Expand All @@ -73,8 +74,6 @@ private function isValidOptions(array $options): array
$this->isValidTag($value);
}
}

return $options;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 9 additions & 9 deletions src/Api/Nlp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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));
Expand Down
18 changes: 7 additions & 11 deletions src/Api/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ 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
*
* @return \Kerox\Messenger\Response\SendResponse
*/
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());
Expand All @@ -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());
Expand All @@ -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) {
Expand All @@ -100,8 +98,6 @@ private function isValidOptions(array $options, $message): array
$this->isValidTag($value, $message);
}
}

return $options;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AccountLinkingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getName(): string
}

/**
* @param $payload
* @param array $payload
*
* @return \Kerox\Messenger\Event\AccountLinkingEvent
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AppRolesEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getName(): string
}

/**
* @param $payload
* @param array $payload
*
* @return \Kerox\Messenger\Event\AppRolesEvent
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Event/DeliveryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getName(): string
}

/**
* @param $payload
* @param array $payload
*
* @return \Kerox\Messenger\Event\DeliveryEvent
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Event/PolicyEnforcementEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getName(): string
}

/**
* @param $payload
* @param array $payload
*
* @return \Kerox\Messenger\Event\PolicyEnforcementEvent
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ReadEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getName(): string
}

/**
* @param $payload
* @param array $payload
*
* @return \Kerox\Messenger\Event\ReadEvent
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Helper/UtilityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Helper/ValidatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected function isValidButtons(array $buttons, array $allowedButtonsType): vo
}

/**
* @param $message
* @param mixed $message
*
* @throws \Exception
*
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Messenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c30bd6f

Please sign in to comment.