Skip to content

Commit

Permalink
Fix deprecation notices
Browse files Browse the repository at this point in the history
  • Loading branch information
Plokko committed Sep 5, 2023
1 parent 7f19386 commit 8438115
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 133 deletions.
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
"license": "MIT",
"require": {
"php": ">=7.1",
"psr/cache": "^1|^2|^3",
"google/auth": "^1.21.0",
"psr/cache": "^1.0||^2.0||^3.0",
"google/auth": "^1.29.0",
"guzzlehttp/guzzle": "^7.4.2",
"firebase/php-jwt": "^6.4"
},
"require-dev": {
},

"require-dev": {},
"autoload": {
"psr-4": {
"Plokko\\Firebase\\": "src/"
Expand All @@ -23,4 +21,4 @@
"Plokko\\Firebase\\Tests\\": "tests/"
}
}
}
}
59 changes: 33 additions & 26 deletions src/FCM/Message.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Plokko\Firebase\FCM;

use GuzzleHttp\Exception\GuzzleException;
Expand All @@ -24,7 +25,8 @@
* @property ApnsConfig $apns Apple Push Notification Service specific options.
* @property Target $target
*/
class Message implements JsonSerializable {
class Message implements JsonSerializable
{
private
/**@var string**/
$name,
Expand All @@ -48,9 +50,9 @@ function __construct()

function __get($name)
{
if(!$this->{$name}){
if (!$this->{$name}) {
//Lazy creation
switch($name){
switch ($name) {
case 'data':
$this->data = new Data();
break;
Expand All @@ -72,50 +74,52 @@ function __get($name)
return $this->{$name};
}

function __set($k,$v){
switch($k){
function __set($k, $v)
{
switch ($k) {
case 'data':
$this->data = $v==null||$v instanceof Data?$v:new Data($v);
$this->data = $v == null || $v instanceof Data ? $v : new Data($v);
return;
case 'notification':
if($v!==null&& !$v instanceof Notification )
if ($v !== null && !$v instanceof Notification)
break;
$this->notification = $v;
return;
case 'android':
if($v!==null && !$v instanceof AndroidConfig)
if ($v !== null && !$v instanceof AndroidConfig)
break;
$this->android = $v;
return;
case 'webpush':
if($v!==null && !$v instanceof WebpushConfig)
if ($v !== null && !$v instanceof WebpushConfig)
break;
$this->webpush = $v;
return;
case 'apns':
if($v!==null && !$v instanceof ApnsConfig )
if ($v !== null && !$v instanceof ApnsConfig)
break;
$this->apns = $v;
return;
case 'target':
if($v!==null && !$v instanceof Target)
if ($v !== null && !$v instanceof Target)
break;
$this->target = $v;
return;
default:

}
throw new UnexpectedValueException('Invalid value type for propriety '.$k);
throw new UnexpectedValueException('Invalid value type for propriety ' . $k);
}

function setTarget(Target $target){
function setTarget(Target $target)
{
$this->target = $target;
}


function getPayload(){
if(!$this->target){
throw new UnexpectedValueException('FCMMEssage target not specified!','TARGET_NOT_SPECIFIED');
function getPayload()
{
if (!$this->target) {
throw new UnexpectedValueException('FCMMEssage target not specified!', 'TARGET_NOT_SPECIFIED');
}

$data = array_filter([
Expand All @@ -125,7 +129,7 @@ function getPayload(){
'webpush' => $this->webpush,
'apns' => $this->apns,
]);
return array_merge($data,$this->target->jsonSerialize());
return array_merge($data, $this->target->jsonSerialize());
}

/**
Expand All @@ -134,9 +138,10 @@ function getPayload(){
* @throws FcmErrorException
* @throws GuzzleException
*/
public function send(Request $request){
public function send(Request $request)
{
$name = $request->submit($this);
if(!$request->validate_only)
if (!$request->validate_only)
$this->name = $name;
}

Expand All @@ -147,16 +152,17 @@ public function send(Request $request){
* @throws GuzzleException
* @throws FcmErrorException
*/
public function validate(Request $request){
public function validate(Request $request)
{
$request = clone $request;
$request->validate_only=true;
$request->validate_only = true;

$request->submit($this);

return true;
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
$data = array_filter([
'name' => $this->name,
Expand All @@ -167,7 +173,7 @@ public function jsonSerialize()
'apns' => $this->apns,
]);

return $this->target?array_merge($data,$this->target->jsonSerialize()):$data;
return $this->target ? array_merge($data, $this->target->jsonSerialize()) : $data;
}

function __toString()
Expand All @@ -179,7 +185,8 @@ function __toString()
* Tells if the request was already submitted (if it has an id)
* @return bool
*/
function isSubmitted(){
function isSubmitted()
{
return !!$this->name;
}
}
}
41 changes: 24 additions & 17 deletions src/FCM/Message/AndroidConfig.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Plokko\Firebase\FCM\Message;

use InvalidArgumentException;
Expand All @@ -19,8 +20,8 @@
class AndroidConfig implements JsonSerializable
{
const
PRIORITY_NORMAL='normal',
PRIORITY_HIGH='high';
PRIORITY_NORMAL = 'normal',
PRIORITY_HIGH = 'high';


private
Expand All @@ -39,63 +40,69 @@ class AndroidConfig implements JsonSerializable
* @param string $ttl Ttl expressed as string (ex: '3.5s')
* @return $this
*/
function ttl($ttl){
$this->ttl=$ttl;
function ttl($ttl)
{
$this->ttl = $ttl;
return $this;
}

function __get($k){
switch($k){
function __get($k)
{
switch ($k) {
case 'data':
if(!$this->data)
if (!$this->data)
$this->data = new Data();
break;
case 'notification':
if(!$this->notification)
if (!$this->notification)
$this->notification = new AndroidNotification();
break;
default:
}
return $this->{$k};
}

function __set($k,$v){
switch($k){
function __set($k, $v)
{
switch ($k) {
case 'priority':
$this->setPriority($v);
break;
default:
}
$this->{$k}=$v;
$this->{$k} = $v;
}

/**
* @param string $p
* @throws InvalidArgumentException
* @return AndroidConfig
*/
function setPriority($p){
switch ($p){
function setPriority($p)
{
switch ($p) {
default:
throw new InvalidArgumentException('Invalid Android message priority!');
case self::PRIORITY_NORMAL:
case self::PRIORITY_HIGH:
$this->priority=$p;
$this->priority = $p;
}
return $this;
}

function setPriorityHigh(){
function setPriorityHigh()
{
$this->priority = self::PRIORITY_HIGH;
return $this;
}

function setPriorityNormal(){
function setPriorityNormal()
{
$this->priority = self::PRIORITY_NORMAL;
return $this;
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array_filter([
'collapse_key' => $this->collapse_key,
Expand Down
15 changes: 11 additions & 4 deletions src/FCM/Message/AndroidNotification.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Plokko\Firebase\FCM\Message;

use JsonSerializable;
Expand Down Expand Up @@ -34,10 +35,16 @@ class AndroidNotification implements JsonSerializable
/**@var array**/
$title_loc_args;

function __get($k){return $this->{$k};}
function __set($k,$v){$this->{$k}=$v;}
function __get($k)
{
return $this->{$k};
}
function __set($k, $v)
{
$this->{$k} = $v;
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array_filter([
'title' => $this->title,
Expand All @@ -53,4 +60,4 @@ public function jsonSerialize()
'title_loc_args' => $this->title_loc_args,
]);
}
}
}
8 changes: 4 additions & 4 deletions src/FCM/Message/Apns/ApnsAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ApnsAlert implements JsonSerializable
/** @var string **/
$launch_image;

function __construct($title='',$body='')
function __construct($title = '', $body = '')
{
$this->title = $title;
$this->body = $body;
Expand All @@ -50,10 +50,10 @@ function __get($k)

function __set($k, $v)
{
$this->{$k}=$v;
$this->{$k} = $v;
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array_filter([
'title' => $this->title,
Expand All @@ -66,4 +66,4 @@ public function jsonSerialize()
'launch-image' => $this->launch_image,
]);
}
}
}
19 changes: 10 additions & 9 deletions src/FCM/Message/Apns/ApnsPayload.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Plokko\Firebase\FCM\Message\Apns;

use JsonSerializable;
Expand All @@ -17,30 +18,30 @@ class ApnsPayload implements JsonSerializable
$aps;
private
/**@var array Custom data for app (acme)**/
$app_data=[];
$app_data = [];

function __get($k)
{
if($k==='aps'){
if(!$this->aps)
if ($k === 'aps') {
if (!$this->aps)
$this->aps = new ApsData();
return $this->aps;
}
return array_key_exists($k,$this->app_data)?$this->app_data[$k]:null;
return array_key_exists($k, $this->app_data) ? $this->app_data[$k] : null;
}

function __set($k, $v)
{
if($k==='aps'){
if ($k === 'aps') {
throw new \InvalidArgumentException('aps is a reserved keyword');
}
$this->app_data[$k] = $v;
}

public function jsonSerialize()
public function jsonSerialize(): mixed
{
return array_filter(array_merge($this->app_data,[
'aps'=>$this->aps,
return array_filter(array_merge($this->app_data, [
'aps' => $this->aps,
]));
}
}
}
Loading

0 comments on commit 8438115

Please sign in to comment.