Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This library allows you to quickly and easily use the Buffer Web API v1 via PHP.
## Getting Started

### Prerequisites
- PHP >=7.2
- PHP >=8.2

### Installation
Run into the terminal the next command
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
"Bufferapp"
],
"require": {
"php": ">=7.2",
"php": ">=8.2",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"symfony/http-client": "^4.3"
"symfony/http-client": "^7.2"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*",
"swaggest/json-diff": "^3.4",
"phpunit/phpunit": "^8.3"
"phpunit/phpunit": "^8.3",
"phpstan/phpstan": "^2.0"
},
"type": "library",
"autoload": {
Expand Down
2 changes: 0 additions & 2 deletions lib/Auth/AuthorizationToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public function __construct(string $accessToken)

/**
* Get Access Token.
*
* @return string
*/
public function getAccessToken(): string
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Auth/AuthorizationTokenInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface AuthorizationTokenInterface
{
public function getAccessToken();
public function getAccessToken() : string;
}
20 changes: 7 additions & 13 deletions lib/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,16 @@ class Client implements ClientInterface
*/
public function __construct(AuthorizationTokenInterface $auth)
{
$this->httpClient = HttpClient::create(['headers' => [
'Authorization' => 'Bearer '.$auth->getAccessToken(),
]]);
$this->httpClient = HttpClient::create([
'headers' => [
'Authorization' => 'Bearer ' . $auth->getAccessToken(),
]
]);
}

/**
* Create Http Request and send the request.
*
* @param string $method
* @param string $url
* @param array $options
*
* @return array
*
* @throws TransportExceptionInterface
* @throws DecodingExceptionInterface When the body cannot be decoded to an array
* @throws TransportExceptionInterface When a network error occurs
Expand All @@ -47,9 +43,7 @@ public function __construct(AuthorizationTokenInterface $auth)
*/
public function createHttpRequest(string $method, string $endpoint, array $options = []): array
{
$response = $this->httpClient->request($method, $this->baseURL.$endpoint, $options);
$responseArray = $response->toArray();

return $responseArray;
$response = $this->httpClient->request($method, $this->baseURL . $endpoint, $options);
return $response->toArray();
}
}
28 changes: 14 additions & 14 deletions lib/Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,47 @@ class Schedule
*
* @var array
*/
protected $days = array();
protected $days = [];

/**
* Array of scheduled times.
*
* @var array
*/
protected $times = array();
protected $times = [];

/**
* Create a new Schedule instance.
*
* @param array $days
* @param array $times
* @param array $days
* @param array $times
* @return void
*/
public function __construct($days = array(), $times = array())
public function __construct($days = [], $times = [])
{
if (! empty($days)) {
if (!empty($days)) {
$this->addDay($days);
}

if (! empty($times)) {
if (!empty($times)) {
$this->addTime($times);
}
}

/**
* Schedule a new day.
*
* @param string|array $day
* @param string|array $day
* @return Schedule
*/
public function addDay($day): self
{
$available = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
$available = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];

foreach ((array) $day as $value) {
foreach ((array)$day as $value) {
// only accept valid values
if (! in_array($value, $available)) {
throw new InvalidArgumentException('Day must be a valid value: '.implode(', ', $available));
if (!in_array($value, $available)) {
throw new InvalidArgumentException('Day must be a valid value: ' . implode(', ', $available));
}

$this->days[] = $value;
Expand All @@ -76,9 +76,9 @@ public function addDay($day): self
*/
public function addTime($time): self
{
foreach ((array) $time as $value) {
foreach ((array)$time as $value) {
// only accept valid times (HH:mm)
if (! preg_match('#([01][0-9]|2[0-3]):[0-5][0-9]#', $value)) {
if (!preg_match('#([01][0-9]|2[0-3]):[0-5][0-9]#', $value)) {
throw new InvalidArgumentException('Time must be valid: HH:mm.');
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Model/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Update
/**
* The status update text.
*
* @var string
* @var string|null
*/
public $text = null;

Expand All @@ -28,7 +28,7 @@ class Update
*
* @var array
*/
public $profiles = array();
public $profiles = [];

/**
* If shorten is false links within the text will not be automatically
Expand Down Expand Up @@ -60,14 +60,14 @@ class Update
*
* @var array
*/
public $media = array();
public $media = [];

/**
* A date describing when the update should be posted. Overrides any top or
* now parameter. When using ISO 8601 format, if no UTC offset is specified,
* UTC is assumed.
*
* @var \DateTime
* @var string|null
*/
public $scheduled_at = null;

Expand All @@ -93,11 +93,11 @@ public function addProfile($id): self
*/
public function addMedia($key, $value): self
{
$available = array('link', 'description', 'picture', 'photo');
$available = ['link', 'description', 'picture', 'photo'];

// accept only valid types for media
if (!in_array($key, $available)) {
throw new InvalidArgumentException('Media type must be a valid value: '.implode(', ', $available).'.');
throw new InvalidArgumentException('Media type must be a valid value: ' . implode(', ', $available) . '.');
}

$this->media[$key] = $value;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function schedule($when): self
return $this;
}

public function validate()
public function validate(): void
{
if ((!isset($this->text) || trim($this->text) === '')) {
throw new InvalidArgumentException('text field should be filled');
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/ProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getProfiles(): array
*/
public function getProfile(string $profileID): array
{
return $this->client->createHttpRequest('GET', 'profiles/'.$profileID.'.json');
return $this->client->createHttpRequest('GET', "profiles/{$profileID}.json");
}

/**
Expand All @@ -51,7 +51,7 @@ public function getProfile(string $profileID): array
*/
public function getSchedules(string $profileID): array
{
return $this->client->createHttpRequest('GET', 'profiles/'.$profileID.'/schedules.json');
return $this->client->createHttpRequest('GET', "profiles/{$profileID}/schedules.json");
}

/**
Expand All @@ -64,15 +64,15 @@ public function getSchedules(string $profileID): array
*/
public function updateSchedule(string $profileID, Schedule $schedule): array
{
$payload = array('schedules' => array());
$payload['schedules'][] = array(
'days' => $schedule->getDays(),
$payload = ['schedules' => []];
$payload['schedules'][] = [
'days' => $schedule->getDays(),
'times' => $schedule->getTimes(),
);
];

return $this->client->createHttpRequest(
'POST',
'profiles/'.$profileID.'/schedules/update.json',
"profiles/{$profileID}/schedules/update.json",
[
'body' => $payload,
]
Expand Down
Loading