Skip to content

Commit

Permalink
Apply PHP CS fixers
Browse files Browse the repository at this point in the history
  • Loading branch information
aalbarca committed May 29, 2022
1 parent 8569961 commit 2d76cee
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_successor_space' => false,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
Expand Down
5 changes: 2 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use Netflie\WhatsAppCloudApi\Http\ClientHandler;
use Netflie\WhatsAppCloudApi\Http\GuzzleClientHandler;
use Netflie\WhatsAppCloudApi\Response;

class Client
{
/**
* @const string Production Graph API URL.
*/
const BASE_GRAPH_URL = 'https://graph.facebook.com';
public const BASE_GRAPH_URL = 'https://graph.facebook.com';

/**
* @var ClientHandler The HTTP client handler to send the request.
Expand Down Expand Up @@ -80,4 +79,4 @@ private function buildRequestUri(Request $request): string
{
return $this->buildBaseUri() . '/' . $request->fromPhoneNumberId() . '/messages';
}
}
}
2 changes: 1 addition & 1 deletion src/Http/ClientHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ interface ClientHandler
* @throws Netflie\WhatsAppCloudApi\Response\ResponseException
*/
public function send(string $url, string $body, array $headers, int $timeout): RawResponse;
}
}
2 changes: 1 addition & 1 deletion src/Http/GuzzleClientHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public function send(string $url, string $body, array $headers, int $timeout): R
$raw_handler_response->getStatusCode()
);
}
}
}
2 changes: 1 addition & 1 deletion src/Http/RawResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ protected function setHeadersFromString($raw_headers)
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Message/Contact/ContactName.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public function lastName(): string
{
return $this->last_name;
}
}
}
2 changes: 1 addition & 1 deletion src/Message/Contact/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public function type(): PhoneType
{
return $this->type;
}
}
}
2 changes: 1 addition & 1 deletion src/Message/Contact/PhoneType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class PhoneType extends Enum
private const IPHONE = 'iphone';
private const HOME = 'home';
private const WORK = 'work';
}
}
11 changes: 7 additions & 4 deletions src/Message/Contact/Phones.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ class Phones implements \Countable, \IteratorAggregate
{
private array $phones;

public function __construct(Phone ...$phones) {
public function __construct(Phone ...$phones)
{
$this->phones = $phones;
}

public function count() : int {
public function count(): int
{
return count($this->phones);
}

public function getIterator() : \ArrayIterator {
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->phones);
}
}
}
2 changes: 0 additions & 2 deletions src/Message/LocationMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Netflie\WhatsAppCloudApi\Message\Error\InvalidMessage;


class LocationMessage extends Message
{
/**
Expand All @@ -28,7 +27,6 @@ class LocationMessage extends Message
*/
public function __construct(string $to, float $longitude, float $latitude, string $name = '', string $address = '')
{

if ($address && !$name) {
throw new InvalidMessage('Name is required.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Message/Media/LinkID.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class LinkID extends MediaID
*/
public function __construct(string $url)
{
if (! filter_var($url, FILTER_VALIDATE_URL)) {
if (!filter_var($url, FILTER_VALIDATE_URL)) {
throw new InvalidMessage();
}

parent::__construct($url);
}
}
}
2 changes: 1 addition & 1 deletion src/Message/Media/MediaID.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public function value(): string
{
return $this->value;
}
}
}
2 changes: 1 addition & 1 deletion src/Message/Media/MediaObjectID.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class MediaObjectID extends MediaID
* {@inheritdoc}
*/
protected string $type = 'id';
}
}
2 changes: 1 addition & 1 deletion src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public function recipientType(): string
{
return $this->recipient_type;
}
}
}
2 changes: 1 addition & 1 deletion src/Message/Template/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public function buttons(): array
{
return $this->buttons;
}
}
}
2 changes: 1 addition & 1 deletion src/Message/TemplateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ public function buttons(): array
? $this->components->buttons()
: [];
}
}
}
3 changes: 1 addition & 2 deletions src/Message/TextMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ private function assertTextIsValid(string $text): void
{
if (strlen($text) > self::MAXIMUM_LENGTH) {
throw new \LengthException('The maximun length for a message text is ' . self::MAXIMUM_LENGTH . ' characters');

}
}
}
}
5 changes: 2 additions & 3 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Request
/**
* @const int The timeout in seconds for a normal request.
*/
const DEFAULT_REQUEST_TIMEOUT = 60;
public const DEFAULT_REQUEST_TIMEOUT = 60;

/**
* @var Message WhatsApp Message to be sent.
Expand Down Expand Up @@ -132,7 +132,7 @@ public function timeout(): int
*
* @return array
*/
protected abstract function makeBody(): void;
abstract protected function makeBody(): void;

/**
* Encodes the raw body of the request.
Expand All @@ -144,4 +144,3 @@ private function encodeBody(): void
$this->encoded_body = json_encode($this->body());
}
}

4 changes: 2 additions & 2 deletions src/Request/RequestTemplateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ protected function makeBody(): void
if ($this->message->header()) {
$this->body['template']['components'][] = [
'type' => 'header',
'parameters' => $this->message->header()
'parameters' => $this->message->header(),
];
}

if ($this->message->body()) {
$this->body['template']['components'][] = [
'type' => 'body',
'parameters' => $this->message->body()
'parameters' => $this->message->body(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Request/RequestTextMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ protected function makeBody(): void
],
];
}
}
}
4 changes: 2 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function graphVersion()
/**
* Returns true if Graph returned an error message.
*
* @return boolean
* @return bool
*/
public function isError()
{
Expand Down Expand Up @@ -169,4 +169,4 @@ public function decodeBody()
$this->throwException();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Response/ResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ public function response()
{
return $this->response;
}
}
}
6 changes: 3 additions & 3 deletions src/WhatsAppCloudApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Netflie\WhatsAppCloudApi;

use Netflie\WhatsAppCloudApi\Message\AudioMessage;
use Netflie\WhatsAppCloudApi\Message\ContactMessage;
use Netflie\WhatsAppCloudApi\Message\Contact\ContactName;
use Netflie\WhatsAppCloudApi\Message\Contact\Phone;
use Netflie\WhatsAppCloudApi\Message\DocumentMessage;
use Netflie\WhatsAppCloudApi\Message\ContactMessage;
use Netflie\WhatsAppCloudApi\Message\Document\Document;
use Netflie\WhatsAppCloudApi\Message\DocumentMessage;
use Netflie\WhatsAppCloudApi\Message\ImageMessage;
use Netflie\WhatsAppCloudApi\Message\LocationMessage;
use Netflie\WhatsAppCloudApi\Message\Media\MediaID;
use Netflie\WhatsAppCloudApi\Message\StickerMessage;
use Netflie\WhatsAppCloudApi\Message\TemplateMessage;
use Netflie\WhatsAppCloudApi\Message\Template\Component;
use Netflie\WhatsAppCloudApi\Message\TemplateMessage;
use Netflie\WhatsAppCloudApi\Message\TextMessage;
use Netflie\WhatsAppCloudApi\Message\VideoMessage;
use Netflie\WhatsAppCloudApi\Request\RequestAudioMessage;
Expand Down
6 changes: 3 additions & 3 deletions src/WhatsAppCloudApiApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class WhatsAppCloudApiApp
/**
* @const string The name of the environment variable that contains the app from phone number ID.
*/
const APP_FROM_PHONE_NUMBER_ENV_NAME = 'WHATSAPP_CLOUD_API_FROM_PHONE_NUMBER';
public const APP_FROM_PHONE_NUMBER_ENV_NAME = 'WHATSAPP_CLOUD_API_FROM_PHONE_NUMBER';

/**
* @const string The name of the environment variable that contains the app access token.
*/
const APP_TOKEN_ENV_NAME = 'WHATSAPP_CLOUD_API_TOKEN';
public const APP_TOKEN_ENV_NAME = 'WHATSAPP_CLOUD_API_TOKEN';

/**
* @const string Facebook Phone Number ID.
Expand Down Expand Up @@ -71,4 +71,4 @@ private function loadEnv(): void
$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
}
}
}
2 changes: 1 addition & 1 deletion tests/Integration/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public function test_send_text_message()
$this->assertEquals($request, $response->request());
$this->assertEquals(false, $response->isError());
}
}
}
12 changes: 5 additions & 7 deletions tests/Integration/WhatsAppCloudApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Netflie\WhatsAppCloudApi\Message\Contact\ContactName;
use Netflie\WhatsAppCloudApi\Message\Contact\Phone;
use Netflie\WhatsAppCloudApi\Message\Contact\PhoneType;
use Netflie\WhatsAppCloudApi\Message\Document\DocumentId;
use Netflie\WhatsAppCloudApi\Message\Document\DocumentLink;
use Netflie\WhatsAppCloudApi\Message\Media\LinkID;
use Netflie\WhatsAppCloudApi\Message\Media\MediaObjectID;
use Netflie\WhatsAppCloudApi\Message\Template\Component;
Expand Down Expand Up @@ -97,8 +95,8 @@ public function test_send_template_with_components()
[
'type' => 'text',
'text' => 'Yes',
]
]
],
],
],
[
'type' => 'button',
Expand All @@ -108,9 +106,9 @@ public function test_send_template_with_components()
[
'type' => 'text',
'text' => 'No',
]
]
]
],
],
],
];

$components = new Component([], $component_body, $component_buttons);
Expand Down
Loading

0 comments on commit 2d76cee

Please sign in to comment.