Skip to content

Commit

Permalink
Execute Rector after PHP 8.2 upgrade (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarStark authored Aug 29, 2024
1 parent cc7e743 commit 55275c9
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 184 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
__DIR__.'/src',
__DIR__.'/tests',
])
->withPhp74Sets()
->withPhpSets(php82: true)
->withTypeCoverageLevel(0);
10 changes: 4 additions & 6 deletions src/Api/Glances/Glance.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
*/
class Glance
{
private Application $application;
private ?Recipient $recipient = null;
private GlanceDataFields $glanceDataFields;

public function __construct(Application $application, GlanceDataFields $glanceDataFields)
{
$this->application = $application;
$this->glanceDataFields = $glanceDataFields;
public function __construct(
private Application $application,
private GlanceDataFields $glanceDataFields,
) {
}

public function getApplication(): Application
Expand Down
1 change: 0 additions & 1 deletion src/Api/Glances/GlanceDataFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Serhiy\Pushover\Exception\InvalidArgumentException;

/**
* Glance Data Fields.
* Currently the following fields are available for updating. Each field is shown differently on different screens,
* so you may need to experiment with them to find out which field works for you given your screen and type of data.
* For example, each watch face on the Apple Watch uses a different sized complication,
Expand Down
19 changes: 4 additions & 15 deletions src/Api/Groups/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,6 @@
*/
class Group
{
/**
* Group key.
*/
private string $key;

/**
* Pushover application this group belongs to.
*/
private Application $application;

/**
* Name of the group.
*/
Expand All @@ -68,14 +58,13 @@ class Group
*
* @throws InvalidArgumentException
*/
public function __construct(string $key, Application $application)
{
public function __construct(
private readonly string $key,
private readonly Application $application,
) {
if (1 !== preg_match('/^[a-zA-Z0-9]{30}$/', $key)) {
throw new InvalidArgumentException(sprintf('Group identifiers are 30 characters long, case-sensitive, and may contain the character set [A-Za-z0-9]. "%s" given."', $key));
}

$this->key = $key;
$this->application = $application;
}

public function getKey(): string
Expand Down
16 changes: 6 additions & 10 deletions src/Api/Licensing/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,25 @@ class License
* License for any device type.
*/
public const OS_ANY = null;
private Application $application;

/**
* (required unless email supplied) - the user's Pushover user key.
*/
private ?Recipient $recipient;
private ?Recipient $recipient = null;

/**
* (required unless user supplied) - the user's e-mail address.
*/
private ?string $email;
private ?string $email = null;

/**
* Can be left blank, or one of Android, iOS, or Desktop.
*/
private ?string $os;
private ?string $os = null;

public function __construct(Application $application)
{
$this->application = $application;
$this->recipient = null;
$this->email = null;
$this->os = null;
public function __construct(
private Application $application,
) {
}

public function getApplication(): Application
Expand Down
15 changes: 4 additions & 11 deletions src/Api/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use Serhiy\Pushover\Exception\InvalidArgumentException;

/**
* Pushover Message.
*
* Messages must contain a message parameter that contains the message body and an optional title parameter.
* If the title is not specified, the application's name will be shown by default.
* See {@link https://pushover.net/api#messages} for more information.
Expand All @@ -39,12 +37,12 @@ class Message
/**
* A supplementary URL to show with your message.
*/
private ?string $url;
private ?string $url = null;

/**
* A title for your supplementary URL, otherwise just the URL is shown.
*/
private ?string $urlTitle;
private ?string $urlTitle = null;

/**
* Message Priority.
Expand All @@ -53,7 +51,7 @@ class Message
* or 2 to also require confirmation from the user.
* See {@link https://pushover.net/api#priority} for more information.
*/
private ?Priority $priority;
private ?Priority $priority = null;

/**
* HTML Message.
Expand Down Expand Up @@ -82,7 +80,7 @@ class Message
*
* The ttl value must be a positive number of seconds, and is counted from the time the message is received by our API.
*/
private ?int $ttl;
private ?int $ttl = null;

public function __construct(string $message, ?string $title = null)
{
Expand All @@ -93,11 +91,6 @@ public function __construct(string $message, ?string $title = null)
}

$this->timestamp = new \DateTime();

$this->ttl = null;
$this->priority = null;
$this->url = null;
$this->urlTitle = null;
}

public function getMessage(): string
Expand Down
25 changes: 9 additions & 16 deletions src/Api/Message/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,15 @@
*/
class Notification
{
private Application $application;
private Recipient $recipient;
private Message $message;
private ?Sound $sound;
private ?CustomSound $customSound;
private ?Attachment $attachment;

public function __construct(Application $application, Recipient $recipient, Message $message)
{
$this->application = $application;
$this->recipient = $recipient;
$this->message = $message;

$this->sound = null;
$this->customSound = null;
$this->attachment = null;
private ?Sound $sound = null;
private ?CustomSound $customSound = null;
private ?Attachment $attachment = null;

public function __construct(
private Application $application,
private Recipient $recipient,
private Message $message,
) {
}

public function getApplication(): Application
Expand Down
34 changes: 12 additions & 22 deletions src/Api/Message/Priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Serhiy\Pushover\Exception\LogicException;

/**
* Message Priority.
* By default, messages have normal priority (a priority of 0).
* Messages may be sent with a different priority that affects how the message is presented to the user.
* Please use your best judgement when sending messages to other users and specifying a message priority.
Expand Down Expand Up @@ -77,37 +76,28 @@ class Priority
*/
public const EMERGENCY = 2;

/**
* Priority of the message.
*/
private int $priority;

/**
* Specifies how often (in seconds) the Pushover servers will send the same notification to the user.
* Used only and required with Emergency Priority.
*/
private ?int $retry = null;

/**
* Specifies how many seconds your notification will continue to be retried for (every "retry" seconds).
* Used only and required with Emergency Priority.
*/
private ?int $expire = null;

/**
* (Optional) may be supplied with a publicly-accessible URL that our servers will send a request to when the user has acknowledged your notification.
* Used only but not required with Emergency Priority.
*/
private ?string $callback = null;

public function __construct(int $priority = self::NORMAL, ?int $retry = null, ?int $expire = null)
{
/**
* @param int $priority priority of the message
* @param null|int $retry Specifies how often (in seconds) the Pushover servers will send the same notification to the user.
* Used only and required with Emergency Priority.
* @param null|int $expire Specifies how many seconds your notification will continue to be retried for (every "retry" seconds).
* Used only and required with Emergency Priority.
*/
public function __construct(
private readonly int $priority = self::NORMAL,
private ?int $retry = null,
private ?int $expire = null,
) {
if (!(self::LOWEST <= $priority && $priority <= self::EMERGENCY)) {
throw new InvalidArgumentException(sprintf('Message priority must be within range -2 and 2. "%s" was given.', $priority));
}

$this->priority = $priority;

if ($priority === self::EMERGENCY) {
if (null === $retry || null === $expire) {
throw new LogicException('To send an emergency-priority notification, the retry and expire parameters must be supplied. Either of them was not supplied.');
Expand Down
13 changes: 6 additions & 7 deletions src/Api/Message/Sound.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ class Sound
public const NONE = 'none';

/**
* Notification Sound
* Users can choose from 22 different default sounds to play when receiving notifications, rather than our standard Pushover tone.
* Applications can override a user's default tone choice on a per-notification basis.
* @param string $sound Users can choose from 22 different default sounds to play when receiving notifications,
* rather than our standard Pushover tone.
* Applications can override a user's default tone choice on a per-notification basis.
*/
private string $sound;

public function __construct(string $sound)
{
public function __construct(
private string $sound,
) {
$this->setSound($sound);
}

Expand Down
8 changes: 3 additions & 5 deletions src/Api/Receipts/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
*/
class Receipt
{
private Application $application;

public function __construct(Application $application)
{
$this->application = $application;
public function __construct(
private readonly Application $application,
) {
}

public function getApplication(): Application
Expand Down
13 changes: 5 additions & 8 deletions src/Api/Subscription/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@
/**
* @author Serhiy Lunak
*/
class Subscription
readonly class Subscription
{
private Application $application;
private string $subscriptionCode;

public function __construct(Application $application, string $subscriptionCode)
{
$this->application = $application;
$this->subscriptionCode = $subscriptionCode;
public function __construct(
private readonly Application $application,
private readonly string $subscriptionCode,
) {
}

public function getApplication(): Application
Expand Down
8 changes: 3 additions & 5 deletions src/Api/UserGroupValidation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
*/
class Validation
{
private Application $application;

public function __construct(Application $application)
{
$this->application = $application;
public function __construct(
private readonly Application $application,
) {
}

public function getApplication(): Application
Expand Down
12 changes: 4 additions & 8 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
class Application
{
/**
* API Token.
* (required) - your application's API token.
* @param string $token API Token (required) - your application's API token
*/
private string $token;

public function __construct(string $token)
{
public function __construct(
private readonly string $token,
) {
if (1 !== preg_match('/^[a-zA-Z0-9]{30}$/', $token)) {
throw new InvalidArgumentException(sprintf('Application tokens are case-sensitive, 30 characters long, and may contain the character set [A-Za-z0-9]. "%s" given with "%s" characters."', $token, \strlen($token)));
}

$this->token = $token;
}

public function getToken(): string
Expand Down
10 changes: 4 additions & 6 deletions src/Client/CancelRetryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
class CancelRetryClient extends Client implements ClientInterface
{
/**
* 30 character string.
* @param string $receipt 30 character string
*/
private string $receipt;

public function __construct(string $receipt)
{
$this->receipt = $receipt;
public function __construct(
private readonly string $receipt,
) {
}

public function buildApiUrl(): string
Expand Down
7 changes: 3 additions & 4 deletions src/Client/CheckLicenseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
class CheckLicenseClient extends Client implements ClientInterface
{
public const API_PATH = 'licenses.json';
private License $license;

public function __construct(License $license)
{
$this->license = $license;
public function __construct(
private readonly License $license,
) {
}

public function buildApiUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Client/GlancesClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function buildApiUrl(): string
*
* @return array<string, string>
*/
public function buildCurlPostFields(Glance $glance)
public function buildCurlPostFields(Glance $glance): array
{
if (!$glance->hasRecipient()) {
throw new LogicException('Glance recipient is not set.');
Expand Down
Loading

0 comments on commit 55275c9

Please sign in to comment.