Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
ctwillie authored and actions-user committed Oct 15, 2021
1 parent 8231825 commit aa119e3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
54 changes: 35 additions & 19 deletions src/ExpoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class ExpoMessage
*/
private $mutableContent = false;

public function __construct(array $attributes = []) {
public function __construct(array $attributes = [])
{
foreach ($attributes as $key => $value) {
$method = 'set' . ucfirst($key);

Expand All @@ -152,7 +153,8 @@ public function __construct(array $attributes = []) {
*
* @return $this
*/
public function setTo($tokens): self {
public function setTo($tokens): self
{
$this->to = Utils::validateTokens($tokens);

return $this;
Expand All @@ -169,8 +171,9 @@ public function setTo($tokens): self {
*
* @return $this
*/
public function setData($data = null): self {
if ($data !== null && !is_object($data) && !Utils::isAssoc($data)) {
public function setData($data = null): self
{
if ($data !== null && ! is_object($data) && ! Utils::isAssoc($data)) {
throw new ExpoMessageException('Message data must be either an associative array, object or null.');
}

Expand All @@ -188,7 +191,8 @@ public function setData($data = null): self {
*
* @return $this
*/
public function setTitle(string $title = null): self {
public function setTitle(string $title = null): self
{
$this->title = $title;

return $this;
Expand All @@ -203,7 +207,8 @@ public function setTitle(string $title = null): self {
*
* @return $this
*/
public function setBody(string $body = null): self {
public function setBody(string $body = null): self
{
$this->body = $body;

return $this;
Expand All @@ -218,7 +223,8 @@ public function setBody(string $body = null): self {
*
* @return $this
*/
public function setTtl(int $ttl = null): self {
public function setTtl(int $ttl = null): self
{
$this->ttl = $ttl;

return $this;
Expand All @@ -233,7 +239,8 @@ public function setTtl(int $ttl = null): self {
*
* @return $this
*/
public function setExpiration(int $expiration = null): self {
public function setExpiration(int $expiration = null): self
{
$this->expiration = $expiration;

return $this;
Expand All @@ -250,10 +257,11 @@ public function setExpiration(int $expiration = null): self {
*
* @return $this
*/
public function setPriority(string $priority = 'default'): self {
public function setPriority(string $priority = 'default'): self
{
$priority = strtolower($priority);

if (!in_array($priority, ['default', 'normal', 'high'])) {
if (! in_array($priority, ['default', 'normal', 'high'])) {
throw new ExpoMessageException('Priority must be default, normal or high.');
}

Expand All @@ -271,7 +279,8 @@ public function setPriority(string $priority = 'default'): self {
*
* @return $this
*/
public function setSubtitle(string $subtitle = null): self {
public function setSubtitle(string $subtitle = null): self
{
$this->subtitle = $subtitle;

return $this;
Expand All @@ -284,7 +293,8 @@ public function setSubtitle(string $subtitle = null): self {
*
* @return $this
*/
public function playSound(): self {
public function playSound(): self
{
$this->sound = 'default';

return $this;
Expand All @@ -300,7 +310,8 @@ public function playSound(): self {
*
* @return $this
*/
public function setSound(string $sound = null): self {
public function setSound(string $sound = null): self
{
$this->sound = $sound;

return $this;
Expand All @@ -315,7 +326,8 @@ public function setSound(string $sound = null): self {
*
* @return $this
*/
public function setBadge(int $badge = null): self {
public function setBadge(int $badge = null): self
{
$this->badge = $badge;

return $this;
Expand All @@ -330,7 +342,8 @@ public function setBadge(int $badge = null): self {
*
* @return $this
*/
public function setChannelId(string $channelId = null): self {
public function setChannelId(string $channelId = null): self
{
$this->channelId = $channelId;

return $this;
Expand All @@ -345,7 +358,8 @@ public function setChannelId(string $channelId = null): self {
*
* @return $this
*/
public function setCategoryId(string $categoryId = null): self {
public function setCategoryId(string $categoryId = null): self
{
$this->categoryId = $categoryId;

return $this;
Expand All @@ -360,7 +374,8 @@ public function setCategoryId(string $categoryId = null): self {
*
* @return $this
*/
public function setMutableContent(bool $mutable): self {
public function setMutableContent(bool $mutable): self
{
$this->mutableContent = $mutable;

return $this;
Expand All @@ -372,11 +387,12 @@ public function setMutableContent(bool $mutable): self {
*
* @return array
*/
public function toArray(): array {
public function toArray(): array
{
$attributes = [];

foreach ($this as $key => $value) {
if (!is_null($value)) {
if (! is_null($value)) {
$attributes[$key] = $value;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public static function arrayWrap($data): array
*
* @return string[]
*/
public static function validateTokens($tokens): array {
if (!is_array($tokens) && !is_string($tokens)) {
public static function validateTokens($tokens): array
{
if (! is_array($tokens) && ! is_string($tokens)) {
throw new InvalidTokensException(sprintf(
'Tokens must be a string or non empty array, %s given.',
gettype($tokens)
Expand Down
3 changes: 2 additions & 1 deletion tests/ExpoMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function throws_exception_providing_unsupported_priority()
}

/** @test */
public function can_create_message_from_array() {
public function can_create_message_from_array()
{
$message = (new ExpoMessage([
'title' => 'test title',
'body' => 'test body',
Expand Down
9 changes: 5 additions & 4 deletions tests/ExpoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ public function throws_exception_when_push_called_with_no_messages()
}

/** @test */
public function converts_arrays_to_expo_messages() {
public function converts_arrays_to_expo_messages()
{
$messages = [
[
"to" => ['ExponentPushToken[valid-token]'],
Expand All @@ -262,7 +263,7 @@ public function converts_arrays_to_expo_messages() {
"categoryId" => "category-id",
"mutableContent" => true,
],
(new ExpoMessage)->setData(['foo' => 'bar'])
(new ExpoMessage())->setData(['foo' => 'bar'])
->setTtl(10)
->setTo(['ExponentPushToken[valid-token]', 'invalid-token]'])
->setExpiration(10)
Expand All @@ -274,7 +275,7 @@ public function converts_arrays_to_expo_messages() {
->setMutableContent(true),
];

$expoMessages = (new Expo)->send($messages)->getMessages();
$expoMessages = (new Expo())->send($messages)->getMessages();

foreach ($expoMessages as $message) {
if (! $message instanceof ExpoMessage) {
Expand All @@ -294,7 +295,7 @@ public function converts_arrays_to_expo_messages() {
/** @test */
public function throws_exception_if_any_message_does_not_have_recpients()
{
$message1 = (new ExpoMessage)
$message1 = (new ExpoMessage())
->setTitle('Title')
->setBody('Message body')
->setData(['foo' => 'bar'])
Expand Down

0 comments on commit aa119e3

Please sign in to comment.