diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b8822fb..5bc459c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,9 +32,17 @@ jobs: extensions: "${{ env.REQUIRED_PHP_EXTENSIONS }}" tools: "composer:v2" + - name: "Composer install" + uses: "ramsey/composer-install@v1" + with: + dependency-versions: "${{ matrix.dependencies }}" + composer-options: "--prefer-dist" + - name: "Validate composer.json" run: "composer validate" + - name: "Normalize composer.json" + run: "composer normalize" tests: name: "PHP ${{ matrix.php-version }} + ${{ matrix.dependencies }}" diff --git a/.gitignore b/.gitignore index edc2e70..5849a22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ vendor/ composer.lock -.php_cs.cache +.php-cs-fixer.cache +.php-cs-fixer.dist.php .idea/ +.build +.php-version diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..a313262 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,110 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Ergebnis\PhpCsFixer\Config\Factory; +use Ergebnis\PhpCsFixer\Config\Rules; +use Ergebnis\PhpCsFixer\Config\RuleSet\Php74; + +$header = <<<'HEADER' +This file is part of the Pushover package. + +(c) Serhiy Lunak + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +HEADER; + +$ruleSet = Php74::create()->withHeader($header)->withRules(Rules::fromArray([ + 'blank_line_before_statement' => [ + 'statements' => [ + 'break', + 'continue', + 'declare', + 'default', + 'do', + 'exit', + 'for', + 'foreach', + 'goto', + 'if', + 'include', + 'include_once', + 'require', + 'require_once', + 'return', + 'switch', + 'throw', + 'try', + 'while', + ], + ], + 'concat_space' => [ + 'spacing' => 'none', + ], + 'date_time_immutable' => false, + 'error_suppression' => false, + 'final_class' => false, + 'mb_str_functions' => false, + 'native_function_invocation' => [ + 'exclude' => [ + 'sprintf', + ], + 'include' => [ + '@compiler_optimized', + ], + 'scope' => 'all', + 'strict' => false, + ], + 'php_unit_internal_class' => false, + 'php_unit_test_annotation' => [ + 'style' => 'prefix', + ], + 'php_unit_test_class_requires_covers' => false, + 'return_to_yield_from' => false, + 'phpdoc_array_type' => false, + 'phpdoc_list_type' => false, + 'attribute_empty_parentheses' => false, + 'final_public_method_for_abstract_class' => false, + 'class_attributes_separation' => [ + 'elements' => [ + 'const' => 'only_if_meta', + 'property' => 'only_if_meta', + 'trait_import' => 'none', + 'case' => 'none', + ], + ], + + // temp disabled to keep the diff small in the first run + 'declare_strict_types' => false, + 'void_return' => false, + 'ordered_imports' => false, + 'php_unit_test_case_static_method_calls' => false, + 'strict_comparison' => false, + 'yoda_style' => false, + 'phpdoc_to_property_type' => false, + 'phpdoc_summary' => false, + 'nullable_type_declaration_for_default_null_value' => false, +])); + +$config = Factory::fromRuleSet($ruleSet); + +$config->getFinder() + ->append([ + __DIR__.'/.php-cs-fixer.dist.php', + ]) + ->in('src') + ->in('tests'); + +$config->setCacheFile(__DIR__.'/.build/php-cs-fixer/.php-cs-fixer.cache'); + +return $config; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1855db9 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +# vim: set tabstop=8 softtabstop=8 noexpandtab: +.PHONY: help +help: ## Displays this list of targets with descriptions + @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: cs +cs: vendor ## Normalizes composer.json with ergebnis/composer-normalize and fixes code style issues with friendsofphp/php-cs-fixer + symfony composer normalize + mkdir -p .build/php-cs-fixer + symfony php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --verbose diff --git a/composer.json b/composer.json index 4d79b2a..0f4d452 100644 --- a/composer.json +++ b/composer.json @@ -1,28 +1,41 @@ { "name": "serhiy/pushover", "description": "Light, simple and fast, yet comprehensive wrapper for the Pushover API.", - "type": "library", - "keywords": ["pushover", "pushover.net", "wrapper", "client"], - "homepage": "https://github.com/slunak/pushover-php", - "require": { - "php": ">=7.4", - "ext-curl": "*", - "ext-json": "*" - }, "license": "MIT", + "type": "library", + "keywords": [ + "pushover", + "pushover.net", + "wrapper", + "client" + ], "authors": [ { "name": "Serhiy Lunak", "email": "serhiy.lunak@gmail.com", - "role": "Developer" + "role": "Developer" } ], + "homepage": "https://github.com/slunak/pushover-php", + "require": { + "php": ">=7.4", + "ext-curl": "*", + "ext-json": "*" + }, + "require-dev": { + "ergebnis/php-cs-fixer-config": "^6.34", + "friendsofphp/php-cs-fixer": "^3.61", + "phpunit/phpunit": "*", + "ergebnis/composer-normalize": "^2.43" + }, "autoload": { "psr-4": { "Serhiy\\Pushover\\": "src/" } }, - "require-dev": { - "phpunit/phpunit": "*" + "config": { + "allow-plugins": { + "ergebnis/composer-normalize": true + } } } diff --git a/src/Api/Glances/Glance.php b/src/Api/Glances/Glance.php index 3b23b02..229ed69 100644 --- a/src/Api/Glances/Glance.php +++ b/src/Api/Glances/Glance.php @@ -1,6 +1,6 @@ @@ -32,17 +32,17 @@ class Glance { /** - * @var Application Pushover application. + * @var Application pushover application */ private $application; /** - * @var Recipient Pushover user. + * @var Recipient pushover user */ private $recipient; /** - * @var GlanceDataFields Glance Data Fields. + * @var GlanceDataFields glance Data Fields */ private $glanceDataFields; @@ -52,63 +52,42 @@ public function __construct(Application $application, GlanceDataFields $glanceDa $this->glanceDataFields = $glanceDataFields; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; } - /** - * @param Application $application - */ public function setApplication(Application $application): void { $this->application = $application; } - /** - * @return Recipient - */ public function getRecipient(): Recipient { return $this->recipient; } - /** - * @param Recipient $recipient - */ public function setRecipient(Recipient $recipient): void { $this->recipient = $recipient; } - /** - * @return GlanceDataFields - */ public function getGlanceDataFields(): GlanceDataFields { return $this->glanceDataFields; } - /** - * @param GlanceDataFields $glanceDataFields - */ public function setGlanceDataFields(GlanceDataFields $glanceDataFields): void { $this->glanceDataFields = $glanceDataFields; } - /** - * @return bool - */ public function hasAtLeastOneField(): bool { - if (null === $this->getGlanceDataFields()->getTitle() && - null === $this->getGlanceDataFields()->getSubtext() && - null === $this->getGlanceDataFields()->getCount() && - null === $this->getGlanceDataFields()->getPercent() + if (null === $this->getGlanceDataFields()->getTitle() + && null === $this->getGlanceDataFields()->getSubtext() + && null === $this->getGlanceDataFields()->getCount() + && null === $this->getGlanceDataFields()->getPercent() ) { return false; } @@ -116,9 +95,6 @@ public function hasAtLeastOneField(): bool return true; } - /** - * @return bool - */ public function hasRecipient(): bool { if (null === $this->recipient) { diff --git a/src/Api/Glances/GlanceDataFields.php b/src/Api/Glances/GlanceDataFields.php index 54774e7..b28f5f4 100644 --- a/src/Api/Glances/GlanceDataFields.php +++ b/src/Api/Glances/GlanceDataFields.php @@ -1,6 +1,6 @@ @@ -25,27 +25,27 @@ class GlanceDataFields { /** - * @var string|null (100 characters) - a description of the data being shown, such as "Widgets Sold". + * @var null|string (100 characters) - a description of the data being shown, such as "Widgets Sold" */ private $title; /** - * @var string|null (100 characters) - the main line of data, used on most screens. + * @var null|string (100 characters) - the main line of data, used on most screens */ private $text; /** - * @var string|null (100 characters) - a second line of data. + * @var null|string (100 characters) - a second line of data */ private $subtext; /** - * @var int|null (integer, may be negative) - shown on smaller screens; useful for simple counts. + * @var null|int (integer, may be negative) - shown on smaller screens; useful for simple counts */ private $count; /** - * @var int|null (integer 0 through 100, inclusive) - shown on some screens as a progress bar/circle. + * @var null|int (integer 0 through 100, inclusive) - shown on some screens as a progress bar/circle */ private $percent; @@ -53,22 +53,15 @@ public function __construct() { } - /** - * @return string|null - */ public function getTitle(): ?string { return $this->title; } - /** - * @param string|null $title - * @return GlanceDataFields - */ - public function setTitle(?string $title): GlanceDataFields + public function setTitle(?string $title): self { - if ($title !== null && strlen($title) > 100) { - throw new InvalidArgumentException(sprintf("Title can be no more than 100 characters long. %s characters long title provided.", strlen($title))); + if ($title !== null && \strlen($title) > 100) { + throw new InvalidArgumentException(sprintf('Title can be no more than 100 characters long. %s characters long title provided.', \strlen($title))); } $this->title = $title; @@ -76,22 +69,15 @@ public function setTitle(?string $title): GlanceDataFields return $this; } - /** - * @return string|null - */ public function getText(): ?string { return $this->text; } - /** - * @param string|null $text - * @return GlanceDataFields - */ - public function setText(?string $text): GlanceDataFields + public function setText(?string $text): self { - if ($text !== null && strlen($text) > 100) { - throw new InvalidArgumentException(sprintf("Text can be no more than 100 characters long. %s characters long text provided.", strlen($text))); + if ($text !== null && \strlen($text) > 100) { + throw new InvalidArgumentException(sprintf('Text can be no more than 100 characters long. %s characters long text provided.', \strlen($text))); } $this->text = $text; @@ -99,22 +85,15 @@ public function setText(?string $text): GlanceDataFields return $this; } - /** - * @return string|null - */ public function getSubtext(): ?string { return $this->subtext; } - /** - * @param string|null $subtext - * @return GlanceDataFields - */ - public function setSubtext(?string $subtext): GlanceDataFields + public function setSubtext(?string $subtext): self { - if ($subtext !== null && strlen($subtext) > 100) { - throw new InvalidArgumentException(sprintf("Subtext can be no more than 100 characters long. %s characters long subtext provided.", strlen($subtext))); + if ($subtext !== null && \strlen($subtext) > 100) { + throw new InvalidArgumentException(sprintf('Subtext can be no more than 100 characters long. %s characters long subtext provided.', \strlen($subtext))); } $this->subtext = $subtext; @@ -122,41 +101,27 @@ public function setSubtext(?string $subtext): GlanceDataFields return $this; } - /** - * @return int|null - */ public function getCount(): ?int { return $this->count; } - /** - * @param int|null $count - * @return GlanceDataFields - */ - public function setCount(?int $count): GlanceDataFields + public function setCount(?int $count): self { $this->count = $count; return $this; } - /** - * @return int|null - */ public function getPercent(): ?int { return $this->percent; } - /** - * @param int|null $percent - * @return GlanceDataFields - */ - public function setPercent(?int $percent): GlanceDataFields + public function setPercent(?int $percent): self { - if (! ($percent >= 0 && $percent <= 100)) { - throw new InvalidArgumentException(sprintf("Percent should be an integer 0 through 100, inclusive. %s provided.", $percent)); + if (!($percent >= 0 && $percent <= 100)) { + throw new InvalidArgumentException(sprintf('Percent should be an integer 0 through 100, inclusive. %s provided.', $percent)); } $this->percent = $percent; diff --git a/src/Api/Groups/Group.php b/src/Api/Groups/Group.php index fa26a2c..7423fff 100644 --- a/src/Api/Groups/Group.php +++ b/src/Api/Groups/Group.php @@ -1,6 +1,6 @@ @@ -38,22 +38,22 @@ class Group { /** - * @var string Group key. + * @var string group key */ private $key; /** - * @var Application Pushover application this group belongs to. + * @var Application pushover application this group belongs to */ private $application; /** - * @var string Name of the group. + * @var string name of the group */ private $name; /** - * @var Recipient[] Group users. + * @var Recipient[] group users */ private $users; @@ -64,7 +64,7 @@ class Group */ public function __construct(string $key, Application $application) { - if (1 != preg_match("/^[a-zA-Z0-9]{30}$/", $key)) { + 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)); } @@ -72,17 +72,11 @@ public function __construct(string $key, Application $application) $this->application = $application; } - /** - * @return string - */ public function getKey(): string { return $this->key; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; @@ -96,9 +90,6 @@ public function getUsers(): array return $this->users; } - /** - * @return string - */ public function getName(): string { return $this->name; @@ -106,8 +97,6 @@ public function getName(): string /** * Retrieves information about the group from the API and populates the object with it. - * - * @return RetrieveGroupResponse */ public function retrieveGroupInformation(): RetrieveGroupResponse { @@ -148,7 +137,6 @@ public function create(string $name): CreateGroupResponse /** * Adds an existing Pushover user to your Delivery Group. * - * @param Recipient $recipient * @return AddUserToGroupResponse */ public function addUser(Recipient $recipient) @@ -166,9 +154,6 @@ public function addUser(Recipient $recipient) /** * Removes user to from Delivery Group. - * - * @param Recipient $recipient - * @return RemoveUserFromGroupResponse */ public function removeUser(Recipient $recipient): RemoveUserFromGroupResponse { @@ -185,9 +170,6 @@ public function removeUser(Recipient $recipient): RemoveUserFromGroupResponse /** * Enables user in Delivery Group. - * - * @param Recipient $recipient - * @return EnableUserInGroupResponse */ public function enableUser(Recipient $recipient): EnableUserInGroupResponse { @@ -204,9 +186,6 @@ public function enableUser(Recipient $recipient): EnableUserInGroupResponse /** * Disables user in Delivery Group. - * - * @param Recipient $recipient - * @return DisableUserInGroupResponse */ public function disableUser(Recipient $recipient): DisableUserInGroupResponse { @@ -223,9 +202,6 @@ public function disableUser(Recipient $recipient): DisableUserInGroupResponse /** * Renames the group. Reflected in the API and in the group editor on our website. - * - * @param string $name - * @return RenameGroupResponse */ public function rename(string $name): RenameGroupResponse { diff --git a/src/Api/Licensing/License.php b/src/Api/Licensing/License.php index b6d3ca6..f16caee 100644 --- a/src/Api/Licensing/License.php +++ b/src/Api/Licensing/License.php @@ -1,6 +1,6 @@ @@ -25,16 +25,24 @@ */ class License { - /** License for Android devices */ + /** + * License for Android devices + */ public const OS_ANDROID = 'Android'; - /** License for iOS devices */ + /** + * License for iOS devices + */ public const OS_IOS = 'iOS'; - /** License for Desktop devices */ + /** + * License for Desktop devices + */ public const OS_DESKTOP = 'Desktop'; - /** License for any device type */ + /** + * License for any device type + */ public const OS_ANY = null; /** @@ -43,87 +51,63 @@ class License private $application; /** - * @var Recipient|null (required unless email supplied) - the user's Pushover user key. + * @var null|recipient (required unless email supplied) - the user's Pushover user key */ - private $recipient = null; + private $recipient; /** - * @var string|null (required unless user supplied) - the user's e-mail address. + * @var null|string (required unless user supplied) - the user's e-mail address */ - private $email = null; + private $email; /** - * @var string|null can be left blank, or one of Android, iOS, or Desktop. + * @var null|string can be left blank, or one of Android, iOS, or Desktop */ - private $os = null; + private $os; public function __construct(Application $application) { $this->application = $application; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; } - /** - * @param Application $application - */ public function setApplication(Application $application): void { $this->application = $application; } - /** - * @return Recipient|null - */ public function getRecipient(): ?Recipient { return $this->recipient; } - /** - * @param Recipient|null $recipient - */ public function setRecipient(?Recipient $recipient): void { $this->recipient = $recipient; } - /** - * @return string|null - */ public function getEmail(): ?string { return $this->email; } - /** - * @param string|null $email - */ public function setEmail(?string $email): void { $this->email = $email; } - /** - * @return string|null - */ public function getOs(): ?string { return $this->os; } - /** - * @param string|null $os - */ public function setOs(?string $os): void { - if (!in_array($os, $this->getAvailableOsTypes())) { + if (!\in_array($os, $this->getAvailableOsTypes(), true)) { throw new InvalidArgumentException(sprintf('OS type "%s" is not available.', $os)); } @@ -132,8 +116,6 @@ public function setOs(?string $os): void /** * Checks if license is ready to be assigned. - * - * @return bool */ public function canBeAssigned(): bool { @@ -156,6 +138,7 @@ public function canBeAssigned(): bool public static function getAvailableOsTypes(): array { $oClass = new \ReflectionClass(__CLASS__); + return $oClass->getConstants(); } @@ -163,8 +146,6 @@ public static function getAvailableOsTypes(): array * Check remaining credits. * * An API call can be made to return the number of license credits remaining without assigning one. - * - * @return LicenseResponse */ public function checkCredits(): LicenseResponse { @@ -184,8 +165,6 @@ public function checkCredits(): LicenseResponse * * Once your application has at least one license credit available, * you can assign it to a Pushover user by their Pushover account e-mail address or their Pushover user key if known. - * - * @return LicenseResponse */ public function assign(): LicenseResponse { diff --git a/src/Api/Message/Attachment.php b/src/Api/Message/Attachment.php index 40b9c59..a719414 100644 --- a/src/Api/Message/Attachment.php +++ b/src/Api/Message/Attachment.php @@ -1,6 +1,6 @@ @@ -96,6 +96,7 @@ public function __construct(string $filename, string $mimeType) public static function getSupportedAttachmentTypes(): array { $oClass = new \ReflectionClass(__CLASS__); + return $oClass->getConstants(); } @@ -107,46 +108,34 @@ public static function getSupportedAttachmentTypes(): array */ public static function getSupportedAttachmentExtensions(): array { - return array( - 'bmp', 'gif', 'ico', 'jpeg', 'jpg', 'png', 'svg', 'tif', 'tiff', 'webp' - ); + return [ + 'bmp', 'gif', 'ico', 'jpeg', 'jpg', 'png', 'svg', 'tif', 'tiff', 'webp', + ]; } - /** - * @return string - */ public function getMimeType(): string { return $this->mimeType; } - /** - * @param string $mimeType - */ public function setMimeType(string $mimeType): void { - if (!in_array($mimeType, $this->getSupportedAttachmentTypes())) { + if (!\in_array($mimeType, $this->getSupportedAttachmentTypes(), true)) { throw new InvalidArgumentException(sprintf('Attachment type "%s" is not supported.', $mimeType)); } $this->mimeType = $mimeType; } - /** - * @return string - */ public function getFilename(): string { return $this->filename; } - /** - * @param string $filename - */ public function setFilename(string $filename): void { - if (!in_array(pathinfo($filename, PATHINFO_EXTENSION), $this->getSupportedAttachmentExtensions())) { - throw new InvalidArgumentException(sprintf('Attachment extension "%s" is not supported.', pathinfo($filename, PATHINFO_EXTENSION))); + if (!\in_array(pathinfo($filename, \PATHINFO_EXTENSION), $this->getSupportedAttachmentExtensions(), true)) { + throw new InvalidArgumentException(sprintf('Attachment extension "%s" is not supported.', pathinfo($filename, \PATHINFO_EXTENSION))); } $this->filename = $filename; diff --git a/src/Api/Message/CustomSound.php b/src/Api/Message/CustomSound.php index 5393ac9..396bdc6 100644 --- a/src/Api/Message/CustomSound.php +++ b/src/Api/Message/CustomSound.php @@ -1,6 +1,6 @@ @@ -34,24 +34,18 @@ public function __construct(string $customSound) $this->setCustomSound($customSound); } - /** - * @return string - */ public function getCustomSound(): string { return $this->customSound; } - /** - * @param string $customSound - */ public function setCustomSound(string $customSound): void { - if (in_array($customSound, Sound::getAvailableSounds())) { + if (\in_array($customSound, Sound::getAvailableSounds(), true)) { throw new InvalidArgumentException(sprintf('Sound "%s" is not a valid custom sound because it matches the name of a built-in sound.', $customSound)); } - if (1 !== preg_match("/^[a-zA-Z0-9_-]{1,20}$/", $customSound)) { + if (1 !== preg_match('/^[a-zA-Z0-9_-]{1,20}$/', $customSound)) { throw new InvalidArgumentException(sprintf('Sound "%s" is not a valid custom sound. Custom sound name can only contain letters, numbers, underscores, and dashes, and is limited to 20 characters, such as "warning", "door_open", or "long_siren2".', $customSound)); } diff --git a/src/Api/Message/Message.php b/src/Api/Message/Message.php index 27e1fc6..dd8ee98 100644 --- a/src/Api/Message/Message.php +++ b/src/Api/Message/Message.php @@ -1,6 +1,6 @@ @@ -34,21 +34,21 @@ class Message /** * Your message's title, otherwise your app's name is used. * - * @var string|null + * @var null|string */ private $title; /** * A supplementary URL to show with your message. * - * @var string|null + * @var null|string */ private $url; /** * A title for your supplementary URL, otherwise just the URL is shown. * - * @var string|null + * @var null|string */ private $urlTitle; @@ -59,7 +59,7 @@ class Message * or 2 to also require confirmation from the user. * See {@link https://pushover.net/api#priority} for more information. * - * @var Priority|null + * @var null|Priority */ private $priority; @@ -68,7 +68,7 @@ class Message * As of version 2.3 of our device clients, messages can be formatted with HTML tags. * See {@link https://pushover.net/api#html} for more information. * - * @var bool|null + * @var null|bool */ private $isHtml = false; @@ -94,11 +94,10 @@ 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. * - * @var int|null + * @var null|int */ private $ttl; - public function __construct(string $message, string $title = null) { $this->setMessage($message); @@ -110,149 +109,101 @@ public function __construct(string $message, string $title = null) $this->timestamp = new \DateTime(); } - /** - * @return string - */ public function getMessage(): string { return $this->message; } - /** - * @param string $message - */ public function setMessage(string $message): void { - if (strlen($message) > 1024) { - throw new InvalidArgumentException('Message contained ' . strlen($message) . ' characters. Messages are limited to 1024 4-byte UTF-8 characters.'); + if (\strlen($message) > 1024) { + throw new InvalidArgumentException('Message contained '.\strlen($message).' characters. Messages are limited to 1024 4-byte UTF-8 characters.'); } $this->message = $message; } - /** - * @return string|null - */ public function getTitle(): ?string { return $this->title; } - /** - * @param string $title - */ public function setTitle(string $title): void { - if (strlen($title) > 250) { - throw new InvalidArgumentException('Title contained ' . strlen($title) . ' characters. Titles are limited to 250 characters.'); + if (\strlen($title) > 250) { + throw new InvalidArgumentException('Title contained '.\strlen($title).' characters. Titles are limited to 250 characters.'); } $this->title = $title; } - /** - * @return string|null - */ public function getUrl(): ?string { return $this->url; } - /** - * @param string $url - */ public function setUrl(string $url): void { - if (strlen($url) > 512) { - throw new InvalidArgumentException('Supplementary URL contained ' . strlen($url) . ' characters. Supplementary URLs are limited to 512 characters.'); + if (\strlen($url) > 512) { + throw new InvalidArgumentException('Supplementary URL contained '.\strlen($url).' characters. Supplementary URLs are limited to 512 characters.'); } $this->url = $url; } - /** - * @return string|null - */ public function getUrlTitle(): ?string { return $this->urlTitle; } - /** - * @param string $urlTitle - */ public function setUrlTitle(string $urlTitle): void { - if (strlen($urlTitle) > 100) { - throw new InvalidArgumentException('URL title contained ' . strlen($urlTitle) . ' characters. URL titles are limited to 100 characters.'); + if (\strlen($urlTitle) > 100) { + throw new InvalidArgumentException('URL title contained '.\strlen($urlTitle).' characters. URL titles are limited to 100 characters.'); } $this->urlTitle = $urlTitle; } - /** - * @return Priority|null - */ public function getPriority(): ?Priority { return $this->priority; } - /** - * @param Priority|null $priority - */ public function setPriority(?Priority $priority): void { $this->priority = $priority; } - /** - * @return bool|null - */ public function getIsHtml(): ?bool { return $this->isHtml; } - /** - * @param bool|null $isHtml - */ public function setIsHtml(?bool $isHtml): void { $this->isHtml = $isHtml; } - /** - * @return int - */ public function getTimestamp(): int { return $this->timestamp->getTimestamp(); } - /** - * @param \DateTime $timestamp - */ public function setTimestamp(\DateTime $timestamp): void { $this->timestamp = $timestamp; } - /** - * @return int|null - */ public function getTtl(): ?int { return $this->ttl; } - /** - * @param int|null $ttl - */ public function setTtl(?int $ttl): void { if ($ttl <= 0 && null !== $ttl) { - throw new InvalidArgumentException('The ttl value of ' . $ttl . ' is invalid. The ttl value must be a positive number of seconds.'); + throw new InvalidArgumentException('The ttl value of '.$ttl.' is invalid. The ttl value must be a positive number of seconds.'); } $this->ttl = $ttl; diff --git a/src/Api/Message/Notification.php b/src/Api/Message/Notification.php index 555f4fb..75aba77 100644 --- a/src/Api/Message/Notification.php +++ b/src/Api/Message/Notification.php @@ -1,6 +1,6 @@ @@ -43,17 +43,17 @@ class Notification private $message; /** - * @var Sound|null + * @var null|Sound */ private $sound; /** - * @var CustomSound|null + * @var null|CustomSound */ private $customSound; /** - * @var Attachment|null + * @var null|Attachment */ private $attachment; @@ -64,105 +64,66 @@ public function __construct(Application $application, Recipient $recipient, Mess $this->message = $message; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; } - /** - * @param Application $application - */ public function setApplication(Application $application): void { $this->application = $application; } - /** - * @return Recipient - */ public function getRecipient(): Recipient { return $this->recipient; } - /** - * @param Recipient $recipient - */ public function setRecipient(Recipient $recipient): void { $this->recipient = $recipient; } - /** - * @return Message - */ public function getMessage(): Message { return $this->message; } - /** - * @param Message $message - */ public function setMessage(Message $message): void { $this->message = $message; } - /** - * @return Sound|null - */ public function getSound(): ?Sound { return $this->sound; } - /** - * @param Sound|null $sound - */ public function setSound(?Sound $sound): void { $this->sound = $sound; } - /** - * @return CustomSound|null - */ public function getCustomSound(): ?CustomSound { return $this->customSound; } - /** - * @param CustomSound|null $customSound - */ public function setCustomSound(?CustomSound $customSound): void { $this->customSound = $customSound; } - /** - * @return Attachment|null - */ public function getAttachment(): ?Attachment { return $this->attachment; } - /** - * @param Attachment|null $attachment - */ public function setAttachment(?Attachment $attachment): void { $this->attachment = $attachment; } - /** - * @return MessageResponse - */ public function push(): MessageResponse { $client = new MessageClient(); diff --git a/src/Api/Message/Priority.php b/src/Api/Message/Priority.php index 1291a9a..abd7e4a 100644 --- a/src/Api/Message/Priority.php +++ b/src/Api/Message/Priority.php @@ -1,6 +1,6 @@ @@ -86,14 +86,15 @@ class Priority * Specifies how often (in seconds) the Pushover servers will send the same notification to the user. * Used only and required with Emergency Priority. * - * @var int|null + * @var null|int */ private $retry; /** * Specifies how many seconds your notification will continue to be retried for (every "retry" seconds). * Used only and required with Emergency Priority. - * @var int|null + * + * @var null|int */ private $expire; @@ -101,7 +102,7 @@ class Priority * (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. * - * @var string|null + * @var null|string */ private $callback; @@ -131,28 +132,20 @@ public function __construct(int $priority = self::NORMAL, int $retry = null, int public static function getAvailablePriorities(): array { $oClass = new \ReflectionClass(__CLASS__); + return $oClass->getConstants(); } - /** - * @return int - */ public function getPriority(): int { return $this->priority; } - /** - * @return int|null - */ public function getRetry(): ?int { return $this->retry; } - /** - * @param int|null $retry - */ public function setRetry(?int $retry): void { if ($retry < 30) { @@ -162,17 +155,11 @@ public function setRetry(?int $retry): void $this->retry = $retry; } - /** - * @return int|null - */ public function getExpire(): ?int { return $this->expire; } - /** - * @param int|null $expire - */ public function setExpire(?int $expire): void { if ($expire > 10800) { @@ -182,17 +169,11 @@ public function setExpire(?int $expire): void $this->expire = $expire; } - /** - * @return string|null - */ public function getCallback(): ?string { return $this->callback; } - /** - * @param string|null $callback - */ public function setCallback(?string $callback): void { $this->callback = $callback; diff --git a/src/Api/Message/Sound.php b/src/Api/Message/Sound.php index dd99167..636ff5d 100644 --- a/src/Api/Message/Sound.php +++ b/src/Api/Message/Sound.php @@ -1,6 +1,6 @@ @@ -18,73 +18,119 @@ */ class Sound { - /** Pushover (default) */ + /** + * Pushover (default) + */ public const PUSHOVER = 'pushover'; - /** Bike */ + /** + * Bike + */ public const BIKE = 'bike'; - /** Bugle */ + /** + * Bugle + */ public const BUGLE = 'bugle'; - /** Cash Register */ + /** + * Cash Register + */ public const CASHREGISTER = 'cashregister'; - /** Classical */ + /** + * Classical + */ public const CLASSICAL = 'classical'; - /** Cosmic */ + /** + * Cosmic + */ public const COSMIC = 'cosmic'; - /** Falling */ + /** + * Falling + */ public const FALLING = 'falling'; - /** Gamelan */ + /** + * Gamelan + */ public const GAMELAN = 'gamelan'; - /** Incoming */ + /** + * Incoming + */ public const INCOMING = 'incoming'; - /** Intermission */ + /** + * Intermission + */ public const INTERMISSION = 'intermission'; - /** Magic */ + /** + * Magic + */ public const MAGIC = 'magic'; - /** Mechanical */ + /** + * Mechanical + */ public const MECHANICAL = 'mechanical'; - /** Piano Bar */ + /** + * Piano Bar + */ public const PIANOBAR = 'pianobar'; - /** Siren */ + /** + * Siren + */ public const SIREN = 'siren'; - /** Space Alarm */ + /** + * Space Alarm + */ public const SPACEALARM = 'spacealarm'; - /** Tug Boat */ + /** + * Tug Boat + */ public const TUGBOAT = 'tugboat'; - /** Alien Alarm (long) */ + /** + * Alien Alarm (long) + */ public const ALIEN = 'alien'; - /** Climb (long) */ + /** + * Climb (long) + */ public const CLIMB = 'climb'; - /** Persistent (long) */ + /** + * Persistent (long) + */ public const PERSISTENT = 'persistent'; - /** Pushover Echo (long) */ + /** + * Pushover Echo (long) + */ public const ECHO = 'echo'; - /** Up Down (long) */ + /** + * Up Down (long) + */ public const UPDOWN = 'updown'; - /** Vibrate Only */ + /** + * Vibrate Only + */ public const VIBRATE = 'vibrate'; - /** None (silent) */ + /** + * None (silent) + */ public const NONE = 'none'; /** @@ -109,23 +155,18 @@ public function __construct(string $sound) public static function getAvailableSounds(): array { $oClass = new \ReflectionClass(__CLASS__); + return $oClass->getConstants(); } - /** - * @return string - */ public function getSound(): string { return $this->sound; } - /** - * @param string $sound - */ public function setSound(string $sound): void { - if (!in_array($sound, $this->getAvailableSounds())) { + if (!\in_array($sound, $this->getAvailableSounds(), true)) { throw new InvalidArgumentException(sprintf('Sound "%s" is not available.', $sound)); } diff --git a/src/Api/Receipts/Receipt.php b/src/Api/Receipts/Receipt.php index e509459..7ade65f 100644 --- a/src/Api/Receipts/Receipt.php +++ b/src/Api/Receipts/Receipt.php @@ -1,6 +1,6 @@ @@ -38,18 +38,11 @@ public function __construct(Application $application) $this->application = $application; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; } - /** - * @param string $receipt - * @return ReceiptResponse - */ public function query(string $receipt): ReceiptResponse { $client = new ReceiptClient($this->application, $receipt); @@ -63,10 +56,6 @@ public function query(string $receipt): ReceiptResponse return $response; } - /** - * @param string $receipt - * @return CancelRetryResponse - */ public function cancelRetry(string $receipt): CancelRetryResponse { $client = new CancelRetryClient($receipt); diff --git a/src/Api/Subscription/Subscription.php b/src/Api/Subscription/Subscription.php index 5b3435f..adcade8 100644 --- a/src/Api/Subscription/Subscription.php +++ b/src/Api/Subscription/Subscription.php @@ -1,6 +1,6 @@ @@ -28,6 +28,7 @@ class Subscription * @var Application */ private $application; + /** * @var string */ @@ -39,27 +40,16 @@ public function __construct(Application $application, string $subscriptionCode) $this->subscriptionCode = $subscriptionCode; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; } - /** - * @return string - */ public function getSubscriptionCode(): string { return $this->subscriptionCode; } - /** - * @param Recipient $recipient - * @param Sound|null $sound - * @return SubscriptionResponse - */ public function migrate(Recipient $recipient, Sound $sound = null): SubscriptionResponse { $client = new SubscriptionClient(); diff --git a/src/Api/UserGroupValidation/Validation.php b/src/Api/UserGroupValidation/Validation.php index 446de65..6faf584 100644 --- a/src/Api/UserGroupValidation/Validation.php +++ b/src/Api/UserGroupValidation/Validation.php @@ -1,6 +1,6 @@ @@ -36,9 +36,6 @@ public function __construct(Application $application) $this->application = $application; } - /** - * @return Application - */ public function getApplication(): Application { return $this->application; @@ -46,9 +43,6 @@ public function getApplication(): Application /** * Validates recipient and its device, and returns Response object. - * - * @param Recipient $recipient - * @return UserGroupValidationResponse */ public function validate(Recipient $recipient): UserGroupValidationResponse { diff --git a/src/Application.php b/src/Application.php index 4f8186c..5b00264 100644 --- a/src/Application.php +++ b/src/Application.php @@ -1,6 +1,6 @@ @@ -33,16 +33,13 @@ class Application public function __construct(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))); + 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; } - /** - * @return string - */ public function getToken(): string { return $this->token; diff --git a/src/Client/AssignLicenseClient.php b/src/Client/AssignLicenseClient.php index 222dca2..fe25f1d 100644 --- a/src/Client/AssignLicenseClient.php +++ b/src/Client/AssignLicenseClient.php @@ -1,6 +1,6 @@ @@ -20,31 +20,30 @@ */ class AssignLicenseClient extends Client implements ClientInterface { - public const API_PATH = "licenses/assign.json"; + public const API_PATH = 'licenses/assign.json'; /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl() { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/".self::API_PATH; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/'.self::API_PATH; } /** * Builds array for CURLOPT_POSTFIELDS curl argument. * - * @param License $license * @return array[] */ public function buildCurlPostFields(License $license): array { if (!$license->canBeAssigned()) { - throw new LogicException(sprintf('License cannot be assigned because neither recipient nor email is set.')); + throw new LogicException('License cannot be assigned because neither recipient nor email is set.'); } - $curlPostFields = array( - "token" => $license->getApplication()->getToken(), - ); + $curlPostFields = [ + 'token' => $license->getApplication()->getToken(), + ]; if (null !== $license->getRecipient()) { $curlPostFields['user'] = $license->getRecipient()->getUserKey(); diff --git a/src/Client/CancelRetryClient.php b/src/Client/CancelRetryClient.php index 10d8fd8..2f3d76d 100644 --- a/src/Client/CancelRetryClient.php +++ b/src/Client/CancelRetryClient.php @@ -20,7 +20,7 @@ class CancelRetryClient extends Client implements ClientInterface { /** - * @var string 30 character string. + * @var string 30 character string */ private $receipt; @@ -30,23 +30,22 @@ public function __construct(string $receipt) } /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl(): string { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/receipts/".$this->receipt."/cancel.json"; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/receipts/'.$this->receipt.'/cancel.json'; } /** * Builds array for CURLOPT_POSTFIELDS curl argument. * - * @param Receipt $receipt * @return array[] */ public function buildCurlPostFields(Receipt $receipt): array { - return array( + return [ 'token' => $receipt->getApplication()->getToken(), - ); + ]; } } diff --git a/src/Client/CheckLicenseClient.php b/src/Client/CheckLicenseClient.php index 035e2cc..f063cfb 100644 --- a/src/Client/CheckLicenseClient.php +++ b/src/Client/CheckLicenseClient.php @@ -1,6 +1,6 @@ @@ -19,7 +19,7 @@ */ class CheckLicenseClient extends Client implements ClientInterface { - public const API_PATH = "licenses.json"; + public const API_PATH = 'licenses.json'; /** * @var License @@ -33,6 +33,6 @@ public function __construct(License $license) public function buildApiUrl() { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/".self::API_PATH."?token=".$this->license->getApplication()->getToken(); + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/'.self::API_PATH.'?token='.$this->license->getApplication()->getToken(); } } diff --git a/src/Client/Client.php b/src/Client/Client.php index 8151836..8e45310 100644 --- a/src/Client/Client.php +++ b/src/Client/Client.php @@ -1,6 +1,6 @@ diff --git a/src/Client/ClientInterface.php b/src/Client/ClientInterface.php index c83b8c8..c33c0ad 100644 --- a/src/Client/ClientInterface.php +++ b/src/Client/ClientInterface.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Curl/Curl.php b/src/Client/Curl/Curl.php index 2487dcc..f9afc6d 100644 --- a/src/Client/Curl/Curl.php +++ b/src/Client/Curl/Curl.php @@ -1,6 +1,6 @@ @@ -34,18 +34,17 @@ class Curl /** * Performs curl request. * - * @param Request $request * @return mixed */ public static function do(Request $request) { - $curlOptions = array( - CURLOPT_URL => $request->getApiUrl(), - CURLOPT_RETURNTRANSFER => true, - ); + $curlOptions = [ + \CURLOPT_URL => $request->getApiUrl(), + \CURLOPT_RETURNTRANSFER => true, + ]; if (null !== $request->getCurlPostFields()) { - $curlOptions[CURLOPT_POSTFIELDS] = $request->getCurlPostFields(); + $curlOptions[\CURLOPT_POSTFIELDS] = $request->getCurlPostFields(); } curl_setopt_array($ch = curl_init(), $curlOptions); @@ -53,7 +52,7 @@ public static function do(Request $request) $curlResponse = curl_exec($ch); if (false === $curlResponse) { - throw new LogicException('Curl request failed. Curl error: ' . curl_error($ch)); + throw new LogicException('Curl request failed. Curl error: '.curl_error($ch)); } if (true === $curlResponse) { diff --git a/src/Client/GlancesClient.php b/src/Client/GlancesClient.php index d6d1382..bfca337 100644 --- a/src/Client/GlancesClient.php +++ b/src/Client/GlancesClient.php @@ -1,6 +1,6 @@ @@ -20,40 +20,39 @@ */ class GlancesClient extends Client implements ClientInterface { - public const API_PATH = "glances.json"; + public const API_PATH = 'glances.json'; /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl() { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/".self::API_PATH; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/'.self::API_PATH; } /** * Builds array for CURLOPT_POSTFIELDS curl argument. * - * @param Glance $glance * @return array[] */ public function buildCurlPostFields(Glance $glance) { if (!$glance->hasRecipient()) { - throw new LogicException(sprintf('Glance recipient is not set.')); + throw new LogicException('Glance recipient is not set.'); } if (!$glance->hasAtLeastOneField()) { - throw new LogicException(sprintf('At least one of the data fields must be supplied. To clear a previously-updated field, send the field with a blank (empty string) value.')); + throw new LogicException('At least one of the data fields must be supplied. To clear a previously-updated field, send the field with a blank (empty string) value.'); } - $curlPostFields = array( - "token" => $glance->getApplication()->getToken(), - "user" => $glance->getRecipient()->getUserKey(), - ); + $curlPostFields = [ + 'token' => $glance->getApplication()->getToken(), + 'user' => $glance->getRecipient()->getUserKey(), + ]; - if (! empty($glance->getRecipient()->getDevice())) { - if (count($glance->getRecipient()->getDevice()) > 1) { - throw new LogicException(sprintf('Glance can be pushed to only one device. "%s" devices provided.', count($glance->getRecipient()->getDevice()))); + if (!empty($glance->getRecipient()->getDevice())) { + if (\count($glance->getRecipient()->getDevice()) > 1) { + throw new LogicException(sprintf('Glance can be pushed to only one device. "%s" devices provided.', \count($glance->getRecipient()->getDevice()))); } $curlPostFields['device'] = $glance->getRecipient()->getDeviceListCommaSeparated(); @@ -62,15 +61,19 @@ public function buildCurlPostFields(Glance $glance) if (null !== $glance->getGlanceDataFields()->getTitle()) { $curlPostFields['title'] = $glance->getGlanceDataFields()->getTitle(); } + if (null !== $glance->getGlanceDataFields()->getText()) { $curlPostFields['text'] = $glance->getGlanceDataFields()->getText(); } + if (null !== $glance->getGlanceDataFields()->getSubtext()) { $curlPostFields['subtext'] = $glance->getGlanceDataFields()->getSubtext(); } + if (null !== $glance->getGlanceDataFields()->getCount()) { $curlPostFields['count'] = $glance->getGlanceDataFields()->getCount(); } + if (null !== $glance->getGlanceDataFields()->getPercent()) { $curlPostFields['percent'] = $glance->getGlanceDataFields()->getPercent(); } diff --git a/src/Client/GroupsClient.php b/src/Client/GroupsClient.php index d6e06f0..468290e 100644 --- a/src/Client/GroupsClient.php +++ b/src/Client/GroupsClient.php @@ -1,6 +1,6 @@ @@ -21,13 +21,13 @@ */ class GroupsClient extends Client implements ClientInterface { - public const ACTION_RETRIEVE_GROUP = "retrieve_group"; - public const ACTION_ADD_USER = "add_user"; - public const ACTION_REMOVE_USER = "delete_user"; - public const ACTION_DISABLE_USER = "disable_user"; - public const ACTION_ENABLE_USER = "enable_user"; - public const ACTION_RENAME_GROUP = "rename"; - public const ACTION_CREATE_GROUP = "create"; + public const ACTION_RETRIEVE_GROUP = 'retrieve_group'; + public const ACTION_ADD_USER = 'add_user'; + public const ACTION_REMOVE_USER = 'delete_user'; + public const ACTION_DISABLE_USER = 'disable_user'; + public const ACTION_ENABLE_USER = 'enable_user'; + public const ACTION_RENAME_GROUP = 'rename'; + public const ACTION_CREATE_GROUP = 'create'; /** * @var Group @@ -35,14 +35,14 @@ class GroupsClient extends Client implements ClientInterface private $group; /** - * @var string Action that client performs. + * @var string action that client performs */ private $action; public function __construct(Group $group, string $action) { if (!$this->isActionValid($action)) { - throw new InvalidArgumentException("Action argument provided to construct method is invalid."); + throw new InvalidArgumentException('Action argument provided to construct method is invalid.'); } $this->group = $group; @@ -50,54 +50,50 @@ public function __construct(Group $group, string $action) } /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl() { if ($this->action == self::ACTION_CREATE_GROUP) { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/groups.json"; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/groups.json'; } if ($this->action == self::ACTION_RETRIEVE_GROUP) { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/groups/".$this->group->getKey().".json?token=".$this->group->getApplication()->getToken(); + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/groups/'.$this->group->getKey().'.json?token='.$this->group->getApplication()->getToken(); } - return Curl::API_BASE_URL."/".Curl::API_VERSION."/groups/".$this->group->getKey()."/".$this->action.".json?token=".$this->group->getApplication()->getToken(); + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/groups/'.$this->group->getKey().'/'.$this->action.'.json?token='.$this->group->getApplication()->getToken(); } - /** - * @param Recipient|null $recipient - * @return array - */ public function buildCurlPostFields(Recipient $recipient = null): array { - $curlPostFields = array( - "token" => $this->group->getApplication()->getToken(), - ); + $curlPostFields = [ + 'token' => $this->group->getApplication()->getToken(), + ]; if ( - $this->action == self::ACTION_ADD_USER || - $this->action == self::ACTION_REMOVE_USER || - $this->action == self::ACTION_DISABLE_USER || - $this->action == self::ACTION_ENABLE_USER + $this->action == self::ACTION_ADD_USER + || $this->action == self::ACTION_REMOVE_USER + || $this->action == self::ACTION_DISABLE_USER + || $this->action == self::ACTION_ENABLE_USER ) { - $curlPostFields["user"] = $recipient->getUserKey(); + $curlPostFields['user'] = $recipient->getUserKey(); } if ($this->action == self::ACTION_ADD_USER) { if (!empty($recipient->getDevice())) { - $curlPostFields["device"] = $recipient->getDevice()[0]; + $curlPostFields['device'] = $recipient->getDevice()[0]; } if (null != $recipient->getMemo()) { - $curlPostFields["memo"] = $recipient->getMemo(); + $curlPostFields['memo'] = $recipient->getMemo(); } } - if ($this->action == self::ACTION_RENAME_GROUP || - $this->action == self::ACTION_CREATE_GROUP + if ($this->action == self::ACTION_RENAME_GROUP + || $this->action == self::ACTION_CREATE_GROUP ) { - $curlPostFields["name"] = $this->group->getName(); + $curlPostFields['name'] = $this->group->getName(); } return $curlPostFields; @@ -105,15 +101,12 @@ public function buildCurlPostFields(Recipient $recipient = null): array /** * Checks if action that was provided into construct is valid. - * - * @param string $action - * @return bool */ private function isActionValid(string $action): bool { $oClass = new \ReflectionClass(__CLASS__); - if (in_array($action, $oClass->getConstants())) { + if (\in_array($action, $oClass->getConstants(), true)) { return true; } diff --git a/src/Client/MessageClient.php b/src/Client/MessageClient.php index d1e559a..780c583 100644 --- a/src/Client/MessageClient.php +++ b/src/Client/MessageClient.php @@ -1,6 +1,6 @@ @@ -33,29 +33,28 @@ public function __construct() } /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl(): string { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/".self::API_PATH; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/'.self::API_PATH; } /** * Builds array for CURLOPT_POSTFIELDS curl argument. * - * @param Notification $notification * @return array[] */ public function buildCurlPostFields(Notification $notification): array { - $curlPostFields = array( - "token" => $notification->getApplication()->getToken(), - "user" => $notification->getRecipient()->getUserKey(), - "message" => $notification->getMessage()->getMessage(), - "timestamp" => $notification->getMessage()->getTimestamp(), - ); - - if (! empty($notification->getRecipient()->getDevice())) { + $curlPostFields = [ + 'token' => $notification->getApplication()->getToken(), + 'user' => $notification->getRecipient()->getUserKey(), + 'message' => $notification->getMessage()->getMessage(), + 'timestamp' => $notification->getMessage()->getTimestamp(), + ]; + + if (!empty($notification->getRecipient()->getDevice())) { $curlPostFields['device'] = $notification->getRecipient()->getDeviceListCommaSeparated(); } @@ -101,7 +100,7 @@ public function buildCurlPostFields(Notification $notification): array } if (null !== $notification->getAttachment()) { - if (! is_readable($notification->getAttachment()->getFilename())) { + if (!is_readable($notification->getAttachment()->getFilename())) { throw new LogicException(sprintf('File "%s" does not exist or is not readable.', $notification->getAttachment()->getFilename())); } @@ -111,7 +110,7 @@ public function buildCurlPostFields(Notification $notification): array $curlPostFields['attachment'] = curl_file_create( $notification->getAttachment()->getFilename(), - $notification->getAttachment()->getMimeType() + $notification->getAttachment()->getMimeType(), ); } diff --git a/src/Client/ReceiptClient.php b/src/Client/ReceiptClient.php index 4235310..fec5af4 100644 --- a/src/Client/ReceiptClient.php +++ b/src/Client/ReceiptClient.php @@ -1,6 +1,6 @@ @@ -20,6 +20,7 @@ class ReceiptClient extends Client implements ClientInterface * @var Application */ private $application; + /** * @var string */ @@ -32,10 +33,10 @@ public function __construct(Application $application, string $receipt) } /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl(): string { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/receipts/".$this->receipt.".json?token=".$this->application->getToken(); + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/receipts/'.$this->receipt.'.json?token='.$this->application->getToken(); } } diff --git a/src/Client/Request/Request.php b/src/Client/Request/Request.php index 90eae32..da0b065 100644 --- a/src/Client/Request/Request.php +++ b/src/Client/Request/Request.php @@ -1,6 +1,6 @@ @@ -23,20 +23,20 @@ class Request implements RequestInterface /** * HTTP GET method. */ - public const GET = "GET"; + public const GET = 'GET'; /** * HTTP POST method. */ - public const POST = "POST"; + public const POST = 'POST'; /** - * @var string Either GET or POST. + * @var string either GET or POST */ private $method; /** - * @var string Full API URL. + * @var string full API URL */ private $apiUrl; @@ -45,15 +45,14 @@ class Request implements RequestInterface * * Array for CURLOPT_POSTFIELDS curl argument. * - * @var array[]|null + * @var null|array[] */ private $curlPostFields; /** * Request constructor. - * @param string $apiUrl - * @param string $method - * @param array[]|null $curlPostFields + * + * @param null|array[] $curlPostFields */ public function __construct(string $apiUrl, string $method, array $curlPostFields = null) { @@ -69,8 +68,6 @@ public function getMethod(): string /** * Returns API URL - * - * @return string */ public function getApiUrl(): string { @@ -78,7 +75,7 @@ public function getApiUrl(): string } /** - * @return array[]|null + * @return null|array[] */ public function getCurlPostFields(): ?array { diff --git a/src/Client/Request/RequestInterface.php b/src/Client/Request/RequestInterface.php index 11ca5ef..5d0d5d2 100644 --- a/src/Client/Request/RequestInterface.php +++ b/src/Client/Request/RequestInterface.php @@ -1,6 +1,6 @@ @@ -18,18 +18,12 @@ */ interface RequestInterface { - /** - * @return string - */ public function getMethod(): string; - /** - * @return string - */ public function getApiUrl(): string; /** - * @return array[]|null + * @return null|array[] */ public function getCurlPostFields(): ?array; } diff --git a/src/Client/Response/AddUserToGroupResponse.php b/src/Client/Response/AddUserToGroupResponse.php index 718634c..5a588cf 100644 --- a/src/Client/Response/AddUserToGroupResponse.php +++ b/src/Client/Response/AddUserToGroupResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/Base/Response.php b/src/Client/Response/Base/Response.php index cd66386..eb26f2a 100644 --- a/src/Client/Response/Base/Response.php +++ b/src/Client/Response/Base/Response.php @@ -1,6 +1,6 @@ @@ -58,7 +58,7 @@ class Response * * @var array[] */ - private $errors = array(); + private $errors = []; /** * Object that contains original request. @@ -67,55 +67,21 @@ class Response */ private $request; - - /** - * @return bool - */ public function isSuccessful(): bool { return $this->isSuccessful; } - /** - * @param bool $isSuccessful - */ - private function setIsSuccessful(bool $isSuccessful): void - { - $this->isSuccessful = $isSuccessful; - } - - /** - * @return int - */ public function getRequestStatus(): int { return $this->requestStatus; } - /** - * @param int $requestStatus - */ - private function setRequestStatus(int $requestStatus): void - { - $this->requestStatus = $requestStatus; - } - - /** - * @return string - */ public function getRequestToken(): string { return $this->requestToken; } - /** - * @param string $requestToken - */ - private function setRequestToken(string $requestToken): void - { - $this->requestToken = $requestToken; - } - /** * @return array[] */ @@ -124,14 +90,6 @@ public function getErrors(): array return $this->errors; } - /** - * @param array[] $errors - */ - private function setErrors(array $errors): void - { - $this->errors = $errors; - } - /** * @return mixed */ @@ -140,25 +98,11 @@ public function getCurlResponse() return $this->curlResponse; } - /** - * @param mixed $curlResponse - */ - private function setCurlResponse($curlResponse): void - { - $this->curlResponse = $curlResponse; - } - - /** - * @return Request - */ public function getRequest(): Request { return $this->request; } - /** - * @param Request $request - */ public function setRequest(Request $request): void { $this->request = $request; @@ -168,6 +112,7 @@ public function setRequest(Request $request): void * Processes initial curl response, common to all response objects. * * @param mixed $curlResponse + * * @return mixed */ protected function processInitialCurlResponse($curlResponse) @@ -191,4 +136,35 @@ protected function processInitialCurlResponse($curlResponse) return $decodedCurlResponse; } + + private function setIsSuccessful(bool $isSuccessful): void + { + $this->isSuccessful = $isSuccessful; + } + + private function setRequestStatus(int $requestStatus): void + { + $this->requestStatus = $requestStatus; + } + + private function setRequestToken(string $requestToken): void + { + $this->requestToken = $requestToken; + } + + /** + * @param array[] $errors + */ + private function setErrors(array $errors): void + { + $this->errors = $errors; + } + + /** + * @param mixed $curlResponse + */ + private function setCurlResponse($curlResponse): void + { + $this->curlResponse = $curlResponse; + } } diff --git a/src/Client/Response/CancelRetryResponse.php b/src/Client/Response/CancelRetryResponse.php index d408ab7..39bad49 100644 --- a/src/Client/Response/CancelRetryResponse.php +++ b/src/Client/Response/CancelRetryResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/CreateGroupResponse.php b/src/Client/Response/CreateGroupResponse.php index b91de8d..9d9d9f2 100644 --- a/src/Client/Response/CreateGroupResponse.php +++ b/src/Client/Response/CreateGroupResponse.php @@ -1,6 +1,6 @@ @@ -32,19 +32,19 @@ public function __construct($curlResponse) } /** - * @param mixed $curlResponse + * @return string Group key obtained */ - private function processCurlResponse($curlResponse): void + public function getGroupKey(): string { - $decodedCurlResponse = $this->processInitialCurlResponse($curlResponse); - $this->groupKey = property_exists($decodedCurlResponse, 'group') ? $decodedCurlResponse->group : null; + return $this->groupKey; } /** - * @return string Group key obtained + * @param mixed $curlResponse */ - public function getGroupKey(): string + private function processCurlResponse($curlResponse): void { - return $this->groupKey; + $decodedCurlResponse = $this->processInitialCurlResponse($curlResponse); + $this->groupKey = property_exists($decodedCurlResponse, 'group') ? $decodedCurlResponse->group : null; } } diff --git a/src/Client/Response/DisableUserInGroupResponse.php b/src/Client/Response/DisableUserInGroupResponse.php index ec2171e..e3692e0 100644 --- a/src/Client/Response/DisableUserInGroupResponse.php +++ b/src/Client/Response/DisableUserInGroupResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/EnableUserInGroupResponse.php b/src/Client/Response/EnableUserInGroupResponse.php index 37de248..9d9907d 100644 --- a/src/Client/Response/EnableUserInGroupResponse.php +++ b/src/Client/Response/EnableUserInGroupResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/GlancesResponse.php b/src/Client/Response/GlancesResponse.php index b42dca3..1c1e134 100644 --- a/src/Client/Response/GlancesResponse.php +++ b/src/Client/Response/GlancesResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/LicenseResponse.php b/src/Client/Response/LicenseResponse.php index 5e68c61..331ff43 100644 --- a/src/Client/Response/LicenseResponse.php +++ b/src/Client/Response/LicenseResponse.php @@ -1,6 +1,6 @@ @@ -19,7 +19,7 @@ class LicenseResponse extends Response { /** - * @var int Number of license credits remaining. + * @var int number of license credits remaining */ private $credits; @@ -31,6 +31,11 @@ public function __construct($curlResponse) $this->processCurlResponse($curlResponse); } + public function getCredits(): int + { + return $this->credits; + } + /** * Processes curl response. * @@ -44,12 +49,4 @@ private function processCurlResponse($curlResponse): void $this->credits = $decodedCurlResponse->credits; } } - - /** - * @return int - */ - public function getCredits(): int - { - return $this->credits; - } } diff --git a/src/Client/Response/MessageResponse.php b/src/Client/Response/MessageResponse.php index 41cb4fa..975ed87 100644 --- a/src/Client/Response/MessageResponse.php +++ b/src/Client/Response/MessageResponse.php @@ -1,6 +1,6 @@ @@ -36,9 +36,6 @@ public function __construct($curlResponse) $this->processCurlResponse($curlResponse); } - /** - * @return string - */ public function getReceipt(): string { return $this->receipt; diff --git a/src/Client/Response/ReceiptResponse.php b/src/Client/Response/ReceiptResponse.php index f9b13b7..9bdbba0 100644 --- a/src/Client/Response/ReceiptResponse.php +++ b/src/Client/Response/ReceiptResponse.php @@ -1,6 +1,6 @@ @@ -20,47 +20,47 @@ class ReceiptResponse extends Response { /** - * @var bool True or False whether the user has acknowledged the notification. + * @var bool true or False whether the user has acknowledged the notification */ private $isAcknowledged = false; /** - * @var \DateTime|null Timestamp of when the user acknowledged, or null. + * @var null|\DateTime timestamp of when the user acknowledged, or null */ private $acknowledgedAt; /** - * @var Recipient User that first acknowledged the notification. + * @var Recipient user that first acknowledged the notification */ private $acknowledgedBy; /** - * @var string The device name of the user that first acknowledged the notification. + * @var string the device name of the user that first acknowledged the notification */ private $acknowledgedByDevice; /** - * @var \DateTime|null Timestamp of when the notification was last retried, or null. + * @var null|\DateTime timestamp of when the notification was last retried, or null */ private $lastDeliveredAt; /** - * @var bool True or False whether the expiration date has passed. + * @var bool true or False whether the expiration date has passed */ private $isExpired; /** - * @var \DateTime Timestamp of when the notification will stop being retried. + * @var \DateTime timestamp of when the notification will stop being retried */ private $expiresAt; /** - * @var bool True or False whether our server has called back to your callback URL if any. + * @var bool true or False whether our server has called back to your callback URL if any */ private $hasCalledBack = false; /** - * @var \DateTime|null Timestamp of when our server called back, or null. + * @var null|\DateTime timestamp of when our server called back, or null */ private $calledBackAt; @@ -72,145 +72,91 @@ public function __construct($curlResponse) $this->processCurlResponse($curlResponse); } - /** - * @return bool - */ public function isAcknowledged(): bool { return $this->isAcknowledged; } - /** - * @param bool $isAcknowledged - */ - private function setIsAcknowledged(bool $isAcknowledged): void + public function getAcknowledgedAt(): ?\DateTime { - $this->isAcknowledged = $isAcknowledged; + return $this->acknowledgedAt; } - /** - * @return \DateTime|null - */ - public function getAcknowledgedAt(): ?\DateTime + public function getAcknowledgedBy(): Recipient { - return $this->acknowledgedAt; + return $this->acknowledgedBy; } - /** - * @param \DateTime $acknowledgedAt - */ - private function setAcknowledgedAt(\DateTime $acknowledgedAt): void + public function getAcknowledgedByDevice(): string { - $this->acknowledgedAt = $acknowledgedAt; + return $this->acknowledgedByDevice; } - /** - * @return Recipient - */ - public function getAcknowledgedBy(): Recipient + public function getLastDeliveredAt(): ?\DateTime { - return $this->acknowledgedBy; + return $this->lastDeliveredAt; } - /** - * @param Recipient $acknowledgedBy - */ - private function setAcknowledgedBy(Recipient $acknowledgedBy): void + public function isExpired(): bool { - $this->acknowledgedBy = $acknowledgedBy; + return $this->isExpired; } - /** - * @return string - */ - public function getAcknowledgedByDevice(): string + public function getExpiresAt(): \DateTime { - return $this->acknowledgedByDevice; + return $this->expiresAt; } - /** - * @param string $acknowledgedByDevice - */ - private function setAcknowledgedByDevice(string $acknowledgedByDevice): void + public function hasCalledBack(): bool { - $this->acknowledgedByDevice = $acknowledgedByDevice; + return $this->hasCalledBack; } - /** - * @return \DateTime|null - */ - public function getLastDeliveredAt(): ?\DateTime + public function getCalledBackAt(): ?\DateTime { - return $this->lastDeliveredAt; + return $this->calledBackAt; } - /** - * @param \DateTime $lastDeliveredAt - */ - private function setLastDeliveredAt(\DateTime $lastDeliveredAt): void + private function setIsAcknowledged(bool $isAcknowledged): void { - $this->lastDeliveredAt = $lastDeliveredAt; + $this->isAcknowledged = $isAcknowledged; } - /** - * @return bool - */ - public function isExpired(): bool + private function setAcknowledgedAt(\DateTime $acknowledgedAt): void { - return $this->isExpired; + $this->acknowledgedAt = $acknowledgedAt; } - /** - * @param bool $isExpired - */ - private function setIsExpired(bool $isExpired): void + private function setAcknowledgedBy(Recipient $acknowledgedBy): void { - $this->isExpired = $isExpired; + $this->acknowledgedBy = $acknowledgedBy; } - /** - * @return \DateTime - */ - public function getExpiresAt(): \DateTime + private function setAcknowledgedByDevice(string $acknowledgedByDevice): void { - return $this->expiresAt; + $this->acknowledgedByDevice = $acknowledgedByDevice; } - /** - * @param \DateTime $expiresAt - */ - private function setExpiresAt(\DateTime $expiresAt): void + private function setLastDeliveredAt(\DateTime $lastDeliveredAt): void { - $this->expiresAt = $expiresAt; + $this->lastDeliveredAt = $lastDeliveredAt; } - /** - * @return bool - */ - public function hasCalledBack(): bool + private function setIsExpired(bool $isExpired): void { - return $this->hasCalledBack; + $this->isExpired = $isExpired; } - /** - * @param bool $hasCalledBack - */ - private function setHasCalledBack(bool $hasCalledBack): void + private function setExpiresAt(\DateTime $expiresAt): void { - $this->hasCalledBack = $hasCalledBack; + $this->expiresAt = $expiresAt; } - /** - * @return \DateTime|null - */ - public function getCalledBackAt(): ?\DateTime + private function setHasCalledBack(bool $hasCalledBack): void { - return $this->calledBackAt; + $this->hasCalledBack = $hasCalledBack; } - /** - * @param \DateTime $calledBackAt - */ private function setCalledBackAt(\DateTime $calledBackAt): void { $this->calledBackAt = $calledBackAt; diff --git a/src/Client/Response/RemoveUserFromGroupResponse.php b/src/Client/Response/RemoveUserFromGroupResponse.php index efee9e8..846f0e0 100644 --- a/src/Client/Response/RemoveUserFromGroupResponse.php +++ b/src/Client/Response/RemoveUserFromGroupResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/RenameGroupResponse.php b/src/Client/Response/RenameGroupResponse.php index d9533a9..3995b8a 100644 --- a/src/Client/Response/RenameGroupResponse.php +++ b/src/Client/Response/RenameGroupResponse.php @@ -1,6 +1,6 @@ diff --git a/src/Client/Response/RetrieveGroupResponse.php b/src/Client/Response/RetrieveGroupResponse.php index 9b01e4e..4796ca5 100644 --- a/src/Client/Response/RetrieveGroupResponse.php +++ b/src/Client/Response/RetrieveGroupResponse.php @@ -1,6 +1,6 @@ @@ -20,12 +20,12 @@ class RetrieveGroupResponse extends Response { /** - * @var string Name of the group. + * @var string name of the group */ private $name; /** - * @var Recipient[] Array of group users of Recipient object. + * @var Recipient[] array of group users of Recipient object */ private $users; @@ -37,9 +37,6 @@ public function __construct($curlResponse) $this->processCurlResponse($curlResponse); } - /** - * @return string - */ public function getName(): string { return $this->name; @@ -69,12 +66,11 @@ private function processCurlResponse($curlResponse): void } /** - * @param array $users * @return Recipient[] */ private function setUsers(array $users): array { - $recipients = array(); + $recipients = []; foreach ($users as $user) { $recipient = new Recipient($user->user); @@ -91,7 +87,7 @@ private function setUsers(array $users): array $recipient->setIsDisabled(true); } - array_push($recipients, $recipient); + $recipients[] = $recipient; } return $recipients; diff --git a/src/Client/Response/SubscriptionResponse.php b/src/Client/Response/SubscriptionResponse.php index 9d7db3d..f1fab60 100644 --- a/src/Client/Response/SubscriptionResponse.php +++ b/src/Client/Response/SubscriptionResponse.php @@ -1,6 +1,6 @@ @@ -19,7 +19,7 @@ class SubscriptionResponse extends Response { /** - * @var string Applications that formerly collected Pushover user keys are encouraged to migrate to subscription keys. + * @var string applications that formerly collected Pushover user keys are encouraged to migrate to subscription keys */ private $subscribed_user_key; @@ -31,9 +31,6 @@ public function __construct($curlResponse) $this->processCurlResponse($curlResponse); } - /** - * @return string - */ public function getSubscribedUserKey(): string { return $this->subscribed_user_key; diff --git a/src/Client/Response/UserGroupValidationResponse.php b/src/Client/Response/UserGroupValidationResponse.php index 75a9c1c..a216930 100644 --- a/src/Client/Response/UserGroupValidationResponse.php +++ b/src/Client/Response/UserGroupValidationResponse.php @@ -1,6 +1,6 @@ @@ -41,44 +41,38 @@ public function __construct($curlResponse) $this->processCurlResponse($curlResponse); } - /** - * @return bool - */ public function isGroup(): bool { return $this->isGroup; } /** - * @param bool $isGroup + * @return array */ - private function setIsGroup(bool $isGroup): void + public function getDevices(): array { - $this->isGroup = $isGroup; + return $this->devices; } /** * @return array */ - public function getDevices(): array + public function getLicenses(): array { - return $this->devices; + return $this->licenses; } - /** - * @param array $devices - */ - private function setDevices(array $devices): void + private function setIsGroup(bool $isGroup): void { - $this->devices = $devices; + $this->isGroup = $isGroup; } /** - * @return array + * @param array $devices */ - public function getLicenses(): array + private function setDevices(array $devices): void { - return $this->licenses; + $this->devices = $devices; } /** diff --git a/src/Client/SubscriptionClient.php b/src/Client/SubscriptionClient.php index 46c3a74..404130b 100644 --- a/src/Client/SubscriptionClient.php +++ b/src/Client/SubscriptionClient.php @@ -1,6 +1,6 @@ @@ -22,35 +22,32 @@ */ class SubscriptionClient extends Client implements ClientInterface { - public const API_PATH = "subscriptions/migrate.json"; + public const API_PATH = 'subscriptions/migrate.json'; /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl() { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/".self::API_PATH; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/'.self::API_PATH; } /** * Builds array for CURLOPT_POSTFIELDS curl argument. * - * @param Subscription $subscription - * @param Recipient $recipient - * @param Sound|null $sound * @return array[] */ public function buildCurlPostFields(Subscription $subscription, Recipient $recipient, Sound $sound = null): array { - $curlPostFields = array( - "token" => $subscription->getApplication()->getToken(), - "subscription" => $subscription->getSubscriptionCode(), - "user" => $recipient->getUserKey(), - ); - - if (! empty($recipient->getDevice())) { - if (count($recipient->getDevice()) > 1) { - throw new LogicException(sprintf('Only one device is supported. "%s" devices provided.', count($recipient->getDevice()))); + $curlPostFields = [ + 'token' => $subscription->getApplication()->getToken(), + 'subscription' => $subscription->getSubscriptionCode(), + 'user' => $recipient->getUserKey(), + ]; + + if (!empty($recipient->getDevice())) { + if (\count($recipient->getDevice()) > 1) { + throw new LogicException(sprintf('Only one device is supported. "%s" devices provided.', \count($recipient->getDevice()))); } $curlPostFields['device_name'] = $recipient->getDeviceListCommaSeparated(); diff --git a/src/Client/UserGroupValidationClient.php b/src/Client/UserGroupValidationClient.php index 3ea484b..ffafe17 100644 --- a/src/Client/UserGroupValidationClient.php +++ b/src/Client/UserGroupValidationClient.php @@ -1,6 +1,6 @@ @@ -18,33 +18,31 @@ class UserGroupValidationClient extends Client implements ClientInterface { - public const API_PATH = "users/validate.json"; + public const API_PATH = 'users/validate.json'; /** - * @inheritDoc + * {@inheritDoc} */ public function buildApiUrl() { - return Curl::API_BASE_URL."/".Curl::API_VERSION."/".self::API_PATH; + return Curl::API_BASE_URL.'/'.Curl::API_VERSION.'/'.self::API_PATH; } /** * Builds array for CURLOPT_POSTFIELDS curl argument. * - * @param Application $application - * @param Recipient $recipient * @return array[] */ public function buildCurlPostFields(Application $application, Recipient $recipient): array { - $curlPostFields = array( - "token" => $application->getToken(), - "user" => $recipient->getUserKey(), - ); - - if (! empty($recipient->getDevice())) { - if (count($recipient->getDevice()) > 1) { - throw new LogicException(sprintf('Api can validate only 1 device at a time. "%s" devices provided.', count($recipient->getDevice()))); + $curlPostFields = [ + 'token' => $application->getToken(), + 'user' => $recipient->getUserKey(), + ]; + + if (!empty($recipient->getDevice())) { + if (\count($recipient->getDevice()) > 1) { + throw new LogicException(sprintf('Api can validate only 1 device at a time. "%s" devices provided.', \count($recipient->getDevice()))); } $curlPostFields['device'] = $recipient->getDeviceListCommaSeparated(); diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index 3407922..3b7d189 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -1,6 +1,6 @@ diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index f29b3aa..bc583d0 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -1,6 +1,6 @@ diff --git a/src/Exception/LogicException.php b/src/Exception/LogicException.php index f5f3b9a..970e11f 100644 --- a/src/Exception/LogicException.php +++ b/src/Exception/LogicException.php @@ -1,6 +1,6 @@ diff --git a/src/Recipient.php b/src/Recipient.php index d8eb8ae..6edbd6a 100644 --- a/src/Recipient.php +++ b/src/Recipient.php @@ -1,6 +1,6 @@ @@ -55,24 +55,21 @@ class Recipient * A free-text memo used to associate data with the user such as their name or e-mail address, * viewable through the API and the groups editor on our website (limited to 200 characters) * - * @var string|null + * @var null|string */ private $memo; public function __construct(string $userKey) { - if (1 != preg_match("/^[a-zA-Z0-9]{30}$/", $userKey)) { - throw new InvalidArgumentException(sprintf('User and group identifiers are 30 characters long, case-sensitive, and may contain the character set [A-Za-z0-9]. "%s" given with "%s" characters.', $userKey, strlen($userKey))); + if (1 != preg_match('/^[a-zA-Z0-9]{30}$/', $userKey)) { + throw new InvalidArgumentException(sprintf('User and group identifiers are 30 characters long, case-sensitive, and may contain the character set [A-Za-z0-9]. "%s" given with "%s" characters.', $userKey, \strlen($userKey))); } $this->userKey = $userKey; - $this->device = array(); + $this->device = []; } - /** - * @return string - */ public function getUserKey(): string { return $this->userKey; @@ -93,56 +90,42 @@ public function getDevice(): array */ public function addDevice($device): void { - if (1 != preg_match("/^[a-zA-Z0-9_-]{1,25}$/", $device)) { - throw new InvalidArgumentException(sprintf('Device names are optional, may be up to 25 characters long, and will contain the character set [A-Za-z0-9_-]. "%s" given with "%s" characters."', $device, strlen($device))); + if (1 != preg_match('/^[a-zA-Z0-9_-]{1,25}$/', $device)) { + throw new InvalidArgumentException(sprintf('Device names are optional, may be up to 25 characters long, and will contain the character set [A-Za-z0-9_-]. "%s" given with "%s" characters."', $device, \strlen($device))); } - if (!in_array($device, $this->device)) { - array_push($this->device, $device); + if (!\in_array($device, $this->device, true)) { + $this->device[] = $device; } } /** * Converts device array to comma separated list and returns it. - * - * @return string */ public function getDeviceListCommaSeparated(): string { return implode(',', $this->device); } - /** - * @return bool - */ public function isDisabled(): bool { return $this->isDisabled; } - /** - * @param bool $isDisabled - */ public function setIsDisabled(bool $isDisabled): void { $this->isDisabled = $isDisabled; } - /** - * @return string|null - */ public function getMemo(): ?string { return $this->memo; } - /** - * @param string|null $memo - */ public function setMemo(?string $memo): void { - if (strlen($memo) > 200) { - throw new InvalidArgumentException('Memo contained ' . strlen($memo) . ' characters. Memos are limited to 200 characters.'); + if (\strlen($memo) > 200) { + throw new InvalidArgumentException('Memo contained '.\strlen($memo).' characters. Memos are limited to 200 characters.'); } $this->memo = $memo; diff --git a/tests/Api/Glances/GlanceDataFieldsTest.php b/tests/Api/Glances/GlanceDataFieldsTest.php index e07628d..0d31b5c 100644 --- a/tests/Api/Glances/GlanceDataFieldsTest.php +++ b/tests/Api/Glances/GlanceDataFieldsTest.php @@ -1,6 +1,6 @@ @@ -31,51 +31,51 @@ public function testSetTitle() { $glanceDataFields = new GlanceDataFields(); - $glanceDataFields->setTitle("This is test title"); - $this->assertEquals("This is test title", $glanceDataFields->getTitle()); + $glanceDataFields->setTitle('This is test title'); + $this->assertEquals('This is test title', $glanceDataFields->getTitle()); $glanceDataFields->setTitle(null); $this->assertNull($glanceDataFields->getTitle()); - $glanceDataFields->setTitle(""); - $this->assertEquals("", $glanceDataFields->getTitle()); + $glanceDataFields->setTitle(''); + $this->assertEquals('', $glanceDataFields->getTitle()); $this->expectException(InvalidArgumentException::class); - $glanceDataFields->setTitle("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); + $glanceDataFields->setTitle('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'); } public function testSetText() { $glanceDataFields = new GlanceDataFields(); - $glanceDataFields->setText("This is test text"); - $this->assertEquals("This is test text", $glanceDataFields->getText()); + $glanceDataFields->setText('This is test text'); + $this->assertEquals('This is test text', $glanceDataFields->getText()); $glanceDataFields->setText(null); $this->assertNull($glanceDataFields->getText()); - $glanceDataFields->setText(""); - $this->assertEquals("", $glanceDataFields->getText()); + $glanceDataFields->setText(''); + $this->assertEquals('', $glanceDataFields->getText()); $this->expectException(InvalidArgumentException::class); - $glanceDataFields->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); + $glanceDataFields->setText('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'); } public function testSetSubtext() { $glanceDataFields = new GlanceDataFields(); - $glanceDataFields->setSubtext("This is test subtext"); - $this->assertEquals("This is test subtext", $glanceDataFields->getSubtext()); + $glanceDataFields->setSubtext('This is test subtext'); + $this->assertEquals('This is test subtext', $glanceDataFields->getSubtext()); $glanceDataFields->setSubtext(null); $this->assertNull($glanceDataFields->getSubtext()); - $glanceDataFields->setSubtext(""); - $this->assertEquals("", $glanceDataFields->getSubtext()); + $glanceDataFields->setSubtext(''); + $this->assertEquals('', $glanceDataFields->getSubtext()); $this->expectException(InvalidArgumentException::class); - $glanceDataFields->setSubtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); + $glanceDataFields->setSubtext('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'); } public function testSetCount() diff --git a/tests/Api/Glances/GlanceTest.php b/tests/Api/Glances/GlanceTest.php index 65763d1..53f3a1e 100644 --- a/tests/Api/Glances/GlanceTest.php +++ b/tests/Api/Glances/GlanceTest.php @@ -1,6 +1,6 @@ @@ -23,13 +23,10 @@ */ class GlanceTest extends TestCase { - /** - * @return Glance - */ public function testCanBeCreated(): Glance { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $glanceDataFields = new GlanceDataFields(); $glance = new Glance($application, $glanceDataFields); @@ -42,7 +39,6 @@ public function testCanBeCreated(): Glance /** * @depends testCanBeCreated - * @param Glance $glance */ public function testGetGlanceDataFields(Glance $glance) { @@ -51,7 +47,6 @@ public function testGetGlanceDataFields(Glance $glance) /** * @depends testCanBeCreated - * @param Glance $glance */ public function testGetApplication(Glance $glance) { @@ -60,7 +55,6 @@ public function testGetApplication(Glance $glance) /** * @depends testCanBeCreated - * @param Glance $glance */ public function testGetRecipient(Glance $glance) { @@ -69,11 +63,10 @@ public function testGetRecipient(Glance $glance) /** * @depends testCanBeCreated - * @param Glance $glance */ public function testSetApplication(Glance $glance) { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $glance->setApplication($application); $this->assertInstanceOf(Application::class, $glance->getApplication()); @@ -81,7 +74,6 @@ public function testSetApplication(Glance $glance) /** * @depends testCanBeCreated - * @param Glance $glance */ public function testSetGlanceDataFields(Glance $glance) { @@ -93,11 +85,10 @@ public function testSetGlanceDataFields(Glance $glance) /** * @depends testCanBeCreated - * @param Glance $glance */ public function testSetRecipient(Glance $glance) { - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $glance->setRecipient($recipient); $this->assertInstanceOf(Recipient::class, $recipient); @@ -105,20 +96,18 @@ public function testSetRecipient(Glance $glance) /** * @depends testCanBeCreated - * @param Glance $glance */ public function testHasAtLeastOneField(Glance $glance) { $this->assertFalse($glance->hasAtLeastOneField()); - $glance->getGlanceDataFields()->setTitle("This is test title"); + $glance->getGlanceDataFields()->setTitle('This is test title'); $this->assertTrue($glance->hasAtLeastOneField()); } /** * @depends testCanBeCreated - * @param Glance $glance */ public function testHasRecipient(Glance $glance) { @@ -130,17 +119,16 @@ public function testHasRecipient(Glance $glance) */ public function testPush() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $glanceDataFields = new GlanceDataFields(); $glanceDataFields - ->setTitle("Title") - ->setText("Text Test") - ->setSubtext("Subtext Test") + ->setTitle('Title') + ->setText('Text Test') + ->setSubtext('Subtext Test') ->setCount(199) - ->setPercent(99) - ; + ->setPercent(99); $glance = new Glance($application, $glanceDataFields); $glance->setRecipient($recipient); diff --git a/tests/Api/Groups/GroupTest.php b/tests/Api/Groups/GroupTest.php index 31bf084..8be2346 100644 --- a/tests/Api/Groups/GroupTest.php +++ b/tests/Api/Groups/GroupTest.php @@ -1,6 +1,6 @@ @@ -22,13 +22,10 @@ */ class GroupTest extends TestCase { - /** - * @return Group - */ public function testCanBeCreated(): Group { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application); // using dummy group key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $group = new Group('eeee5555EEEE5555ffff6666FFFF66', $application); // using dummy group key $this->assertInstanceOf(Group::class, $group); @@ -37,21 +34,19 @@ public function testCanBeCreated(): Group /** * @depends testCanBeCreated - * @param Group $group */ public function testGetApplication(Group $group) { $this->assertInstanceOf(Application::class, $group->getApplication()); - $this->assertEquals("cccc3333CCCC3333dddd4444DDDD44", $group->getApplication()->getToken()); + $this->assertEquals('cccc3333CCCC3333dddd4444DDDD44', $group->getApplication()->getToken()); } /** * @depends testCanBeCreated - * @param Group $group */ public function testGetKey(Group $group) { - $this->assertEquals("eeee5555EEEE5555ffff6666FFFF66", $group->getKey()); + $this->assertEquals('eeee5555EEEE5555ffff6666FFFF66', $group->getKey()); } /** @@ -59,24 +54,24 @@ public function testGetKey(Group $group) */ public function testRetrieveGroupInformation() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application); + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $group = new Group('eeee5555EEEE5555ffff6666FFFF66', $application); $response = $group->retrieveGroupInformation(); $this->assertInstanceOf(RetrieveGroupResponse::class, $response); } - + /** * @group Integration */ public function testCreate() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application); + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $group = new Group('eeee5555EEEE5555ffff6666FFFF66', $application); - $response = $group->create('unit test '. date('Y-m-d H:i:s')); + $response = $group->create('unit test '.date('Y-m-d H:i:s')); $this->assertInstanceOf(CreateGroupResponse::class, $response); - } + } } diff --git a/tests/Api/Licensing/LicenseTest.php b/tests/Api/Licensing/LicenseTest.php index cad49e9..e76d3f6 100644 --- a/tests/Api/Licensing/LicenseTest.php +++ b/tests/Api/Licensing/LicenseTest.php @@ -1,6 +1,6 @@ @@ -20,12 +20,9 @@ class LicenseTest extends TestCase { - /** - * @return License - */ public function testCanBeCreated(): License { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $license = new License($application); $this->assertInstanceOf(License::class, $license); @@ -35,7 +32,6 @@ public function testCanBeCreated(): License /** * @depends testCanBeCreated - * @param License $license */ public function testGetApplication(License $license) { @@ -44,11 +40,10 @@ public function testGetApplication(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testSetApplication(License $license) { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $license->setApplication($application); $this->assertInstanceOf(Application::class, $license->getApplication()); @@ -56,7 +51,6 @@ public function testSetApplication(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testGetRecipient(License $license) { @@ -65,11 +59,10 @@ public function testGetRecipient(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testSetRecipient(License $license) { - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $license->setRecipient($recipient); $this->assertInstanceOf(Recipient::class, $license->getRecipient()); @@ -80,7 +73,6 @@ public function testSetRecipient(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testGetEmail(License $license) { @@ -89,7 +81,6 @@ public function testGetEmail(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testSetEmail(License $license) { @@ -104,7 +95,6 @@ public function testSetEmail(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testGetOs(License $license) { @@ -113,7 +103,6 @@ public function testGetOs(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testSetOs(License $license) { @@ -129,11 +118,10 @@ public function testSetOs(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testCanBeAssigned(License $license) { - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $email = 'dummy@email.com'; $this->assertFalse($license->canBeAssigned()); @@ -153,16 +141,15 @@ public function testCanBeAssigned(License $license) /** * @depends testCanBeCreated - * @param License $license */ public function testGetAvailableOsTypes(License $license) { - $licenseTypes = array( - 'OS_ANDROID' => "Android", - 'OS_IOS' => "iOS", - 'OS_DESKTOP' => "Desktop", + $licenseTypes = [ + 'OS_ANDROID' => 'Android', + 'OS_IOS' => 'iOS', + 'OS_DESKTOP' => 'Desktop', 'OS_ANY' => null, - ); + ]; $this->assertEquals($licenseTypes, $license->getAvailableOsTypes()); } @@ -172,7 +159,7 @@ public function testGetAvailableOsTypes(License $license) */ public function testCheckCredits() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $license = new License($application); $response = $license->checkCredits(); diff --git a/tests/Api/Message/AttachmentTest.php b/tests/Api/Message/AttachmentTest.php index c23eeb3..d5e02e6 100644 --- a/tests/Api/Message/AttachmentTest.php +++ b/tests/Api/Message/AttachmentTest.php @@ -1,6 +1,6 @@ @@ -44,7 +44,6 @@ public function testCannotBeCreatedWithInvalidExtension() /** * @depends testCanBeCreated - * @param Attachment $attachment */ public function testGetMimeType(Attachment $attachment) { @@ -53,7 +52,6 @@ public function testGetMimeType(Attachment $attachment) /** * @depends testCanBeCreated - * @param Attachment $attachment */ public function testGetFilename(Attachment $attachment) { @@ -62,7 +60,6 @@ public function testGetFilename(Attachment $attachment) /** * @depends testCanBeCreated - * @param Attachment $attachment */ public function testSetMimeType(Attachment $attachment) { @@ -75,7 +72,6 @@ public function testSetMimeType(Attachment $attachment) /** * @depends testCanBeCreated - * @param Attachment $attachment */ public function testSetFilename(Attachment $attachment) { @@ -88,7 +84,6 @@ public function testSetFilename(Attachment $attachment) /** * @depends testCanBeCreated - * @param Attachment $attachment */ public function testGetSupportedAttachmentTypes(Attachment $attachment) { @@ -99,13 +94,12 @@ public function testGetSupportedAttachmentTypes(Attachment $attachment) /** * @depends testCanBeCreated - * @param Attachment $attachment */ public function testGetSupportedAttachmentExtensions(Attachment $attachment) { - $supportedAttachmentExtensions = array( - 'bmp', 'gif', 'ico', 'jpeg', 'jpg', 'png', 'svg', 'tif', 'tiff', 'webp' - ); + $supportedAttachmentExtensions = [ + 'bmp', 'gif', 'ico', 'jpeg', 'jpg', 'png', 'svg', 'tif', 'tiff', 'webp', + ]; $this->assertEquals($supportedAttachmentExtensions, $attachment->getSupportedAttachmentExtensions()); } diff --git a/tests/Api/Message/CustomSoundTest.php b/tests/Api/Message/CustomSoundTest.php index 5c8ae02..3ded3b9 100644 --- a/tests/Api/Message/CustomSoundTest.php +++ b/tests/Api/Message/CustomSoundTest.php @@ -1,6 +1,6 @@ @@ -22,14 +22,13 @@ class CustomSoundTest extends TestCase { public function testCanBeCreated() { - $this->assertInstanceOf(CustomSound::class, $customSound = new CustomSound("door_open")); + $this->assertInstanceOf(CustomSound::class, $customSound = new CustomSound('door_open')); return $customSound; } /** * @depends testCanBeCreated - * @param CustomSound $customSound */ public function testGetCustomSound(CustomSound $customSound) { @@ -38,53 +37,49 @@ public function testGetCustomSound(CustomSound $customSound) /** * @depends testCanBeCreated - * @param CustomSound $customSound */ public function testSetCustomSound(CustomSound $customSound) { - $customSound->setCustomSound("warning"); + $customSound->setCustomSound('warning'); $this->assertEquals('warning', $customSound->getCustomSound()); - $customSound->setCustomSound("door_open"); + $customSound->setCustomSound('door_open'); $this->assertEquals('door_open', $customSound->getCustomSound()); - $customSound->setCustomSound("bell-sound"); + $customSound->setCustomSound('bell-sound'); $this->assertEquals('bell-sound', $customSound->getCustomSound()); } /** * @depends testCanBeCreated - * @param CustomSound $customSound */ public function testSetExistingCustomSound(CustomSound $customSound) { $this->expectException(InvalidArgumentException::class); - $customSound->setCustomSound("echo"); + $customSound->setCustomSound('echo'); } /** * @depends testCanBeCreated - * @param CustomSound $customSound */ public function testSetInvalidCustomSound(CustomSound $customSound) { $this->expectException(InvalidArgumentException::class); - $customSound->setCustomSound("warning+door_open"); + $customSound->setCustomSound('warning+door_open'); } /** * @depends testCanBeCreated - * @param CustomSound $customSound */ public function testSetLongCustomSound(CustomSound $customSound) { $this->expectException(InvalidArgumentException::class); - $customSound->setCustomSound("warning_door_open_warning_door_open"); + $customSound->setCustomSound('warning_door_open_warning_door_open'); } } diff --git a/tests/Api/Message/MessageTest.php b/tests/Api/Message/MessageTest.php index f99e96f..a6d3d93 100644 --- a/tests/Api/Message/MessageTest.php +++ b/tests/Api/Message/MessageTest.php @@ -1,5 +1,6 @@ @@ -19,99 +20,105 @@ class MessageTest extends TestCase { public function testCanBeCreated() { - $message = new Message("This is a test message", "This is a title of the message"); + $message = new Message('This is a test message', 'This is a title of the message'); $this->assertInstanceOf(Message::class, $message); } public function testSetMessage() { - $message = new Message("This is a test message"); - $message->setMessage("This is a test message"); + $message = new Message('This is a test message'); + $message->setMessage('This is a test message'); $this->expectException(InvalidArgumentException::class); $message->setMessage( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + <<<'EOD' +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." +EOD ); } public function testGetMessage() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); - $this->assertEquals("This is a test message", $message->getMessage()); + $this->assertEquals('This is a test message', $message->getMessage()); } public function testSetTitle() { - $message = new Message("This is a test message"); - $message->setTitle("This is a title of the message"); + $message = new Message('This is a test message'); + $message->setTitle('This is a title of the message'); $this->expectException(InvalidArgumentException::class); $message->setTitle( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." + <<<'EOD' +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +EOD ); } public function testGetTitle() { - $message = new Message("This is a test message", "This is a title of the message"); + $message = new Message('This is a test message', 'This is a title of the message'); - $this->assertEquals("This is a title of the message", $message->getTitle()); + $this->assertEquals('This is a title of the message', $message->getTitle()); } public function testSetUrl() { - $message = new Message("This is a test message"); - $message->setUrl("https://www.example.com"); + $message = new Message('This is a test message'); + $message->setUrl('https://www.example.com'); $this->expectException(InvalidArgumentException::class); $message->setUrl( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + <<<'EOD' +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." +EOD ); } public function testGetUrl() { - $message = new Message("This is a test message"); - $message->setUrl("https://www.example.com"); + $message = new Message('This is a test message'); + $message->setUrl('https://www.example.com'); - $this->assertEquals("https://www.example.com", $message->getUrl()); + $this->assertEquals('https://www.example.com', $message->getUrl()); } public function testSetUrlTitle() { - $message = new Message("This is a test message"); - $message->setUrlTitle("Example URL"); + $message = new Message('This is a test message'); + $message->setUrlTitle('Example URL'); $this->expectException(InvalidArgumentException::class); $message->setUrlTitle( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', ); } public function testGetUrlTitle() { - $message = new Message("This is a test message"); - $message->setUrlTitle("Example URL"); + $message = new Message('This is a test message'); + $message->setUrlTitle('Example URL'); - $this->assertEquals("Example URL", $message->getUrlTitle()); + $this->assertEquals('Example URL', $message->getUrlTitle()); } public function testSetPriority() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $message->setPriority(null); $this->assertNull($message->getPriority()); @@ -119,7 +126,7 @@ public function testSetPriority() public function testGetPriority() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $message->setPriority(new Priority(Priority::NORMAL)); $this->assertInstanceOf(Priority::class, $message->getPriority()); @@ -127,7 +134,7 @@ public function testGetPriority() public function testSetIsHtml() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $message->setIsHtml(null); $this->assertNull($message->getIsHtml()); @@ -135,7 +142,7 @@ public function testSetIsHtml() public function testGetIsHtml() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $message->setIsHtml(true); $this->assertTrue($message->getIsHtml()); @@ -143,7 +150,7 @@ public function testGetIsHtml() public function testGetTimestamp() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $datetime = new \DateTime(); $message->setTimestamp($datetime); @@ -153,7 +160,7 @@ public function testGetTimestamp() public function testSetAndGetTtl() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $this->assertNull($message->getTtl()); @@ -168,7 +175,7 @@ public function testSetAndGetTtl() public function testSetNegativeTtl() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $this->expectException(InvalidArgumentException::class); @@ -177,7 +184,7 @@ public function testSetNegativeTtl() public function testSetZeroTtl() { - $message = new Message("This is a test message"); + $message = new Message('This is a test message'); $this->expectException(InvalidArgumentException::class); diff --git a/tests/Api/Message/NotificationTest.php b/tests/Api/Message/NotificationTest.php index 5876422..9b09bc6 100644 --- a/tests/Api/Message/NotificationTest.php +++ b/tests/Api/Message/NotificationTest.php @@ -1,6 +1,6 @@ @@ -28,10 +28,10 @@ class NotificationTest extends TestCase { public function testCanBeCreated() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key - $message = new Message("This is a test message", "This is a title of the message"); + $message = new Message('This is a test message', 'This is a title of the message'); $notification = new Notification($application, $recipient, $message); @@ -42,7 +42,6 @@ public function testCanBeCreated() /** * @depends testCanBeCreated - * @param Notification $notification */ public function testSetSound(Notification $notification) { @@ -53,7 +52,6 @@ public function testSetSound(Notification $notification) /** * @depends testCanBeCreated - * @param Notification $notification */ public function testSetSoundNull(Notification $notification) { @@ -64,18 +62,16 @@ public function testSetSoundNull(Notification $notification) /** * @depends testCanBeCreated - * @param Notification $notification */ public function testSetCustomSound(Notification $notification) { - $notification->setCustomSound(new CustomSound("door_open")); + $notification->setCustomSound(new CustomSound('door_open')); $this->assertEquals('door_open', $notification->getCustomSound()->getCustomSound()); } /** * @depends testCanBeCreated - * @param Notification $notification */ public function testSetCustomSoundNull(Notification $notification) { @@ -86,11 +82,10 @@ public function testSetCustomSoundNull(Notification $notification) /** * @depends testCanBeCreated - * @param Notification $notification */ public function testSetAttachment(Notification $notification) { - $notification->setAttachment(new Attachment("/path/to/file.jpg", Attachment::MIME_TYPE_JPEG)); + $notification->setAttachment(new Attachment('/path/to/file.jpg', Attachment::MIME_TYPE_JPEG)); $this->assertEquals('/path/to/file.jpg', $notification->getAttachment()->getFilename()); $this->assertEquals('image/jpeg', $notification->getAttachment()->getMimeType()); @@ -98,7 +93,6 @@ public function testSetAttachment(Notification $notification) /** * @depends testCanBeCreated - * @param Notification $notification */ public function testSetAttachmentNull(Notification $notification) { @@ -112,9 +106,9 @@ public function testSetAttachmentNull(Notification $notification) */ public function testPush() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key - $message = new Message("This is a test message", "This is a title of the message"); + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key + $message = new Message('This is a test message', 'This is a title of the message'); $notification = new Notification($application, $recipient, $message); $response = $notification->push(); diff --git a/tests/Api/Message/PriorityTest.php b/tests/Api/Message/PriorityTest.php index cc989f5..c976b4f 100644 --- a/tests/Api/Message/PriorityTest.php +++ b/tests/Api/Message/PriorityTest.php @@ -1,6 +1,6 @@ @@ -62,12 +62,12 @@ public function testEmergencyPriorityRequiresExtraParams() /** * @depends testCanBeCreatedWithEmergencyPriority - * @param Priority $priority + * * @return Priority */ public function testSetCallback(Priority $priority) { - $priority->setCallback("https://callback.example.com"); + $priority->setCallback('https://callback.example.com'); $this->assertInstanceOf(Priority::class, $priority); @@ -76,16 +76,14 @@ public function testSetCallback(Priority $priority) /** * @depends testSetCallback - * @param Priority $priority */ public function testGetCallback(Priority $priority) { - $this->assertEquals("https://callback.example.com", $priority->getCallback()); + $this->assertEquals('https://callback.example.com', $priority->getCallback()); } /** * @depends testCanBeCreated - * @param Priority $priority */ public function testAvailablePriorities(Priority $priority) { diff --git a/tests/Api/Message/SoundTest.php b/tests/Api/Message/SoundTest.php index c05cde9..e0aebb8 100644 --- a/tests/Api/Message/SoundTest.php +++ b/tests/Api/Message/SoundTest.php @@ -1,6 +1,6 @@ @@ -29,7 +29,6 @@ public function testCanBeCreated() /** * @depends testCanBeCreated - * @param Sound $sound */ public function testGetSound(Sound $sound) { @@ -38,7 +37,6 @@ public function testGetSound(Sound $sound) /** * @depends testCanBeCreated - * @param Sound $sound */ public function testAvailableSounds(Sound $sound) { @@ -49,7 +47,6 @@ public function testAvailableSounds(Sound $sound) /** * @depends testCanBeCreated - * @param Sound $sound */ public function testSetSound(Sound $sound) { @@ -59,6 +56,6 @@ public function testSetSound(Sound $sound) $this->expectException(InvalidArgumentException::class); - $sound->setSound("invalid_sound"); + $sound->setSound('invalid_sound'); } } diff --git a/tests/Api/Receipts/ReceiptTest.php b/tests/Api/Receipts/ReceiptTest.php index 532d7e7..e2f6920 100644 --- a/tests/Api/Receipts/ReceiptTest.php +++ b/tests/Api/Receipts/ReceiptTest.php @@ -1,6 +1,6 @@ @@ -24,7 +24,7 @@ class ReceiptTest extends TestCase { public function testCanBeCreated() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $receipt = new Receipt($application); @@ -35,14 +35,13 @@ public function testCanBeCreated() /** * @depends testCanBeCreated - * @param Receipt $receipt */ public function testGetApplication(Receipt $receipt) { $application = $receipt->getApplication(); $this->assertInstanceOf(Application::class, $application); - $this->assertEquals("cccc3333CCCC3333dddd4444DDDD44", $application->getToken()); + $this->assertEquals('cccc3333CCCC3333dddd4444DDDD44', $application->getToken()); } /** @@ -50,10 +49,10 @@ public function testGetApplication(Receipt $receipt) */ public function testQuery() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $receipt = new Receipt($application); - $response = $receipt->query("gggg7777GGGG7777hhhh8888HHHH88"); // using dummy receipt + $response = $receipt->query('gggg7777GGGG7777hhhh8888HHHH88'); // using dummy receipt $this->assertInstanceOf(ReceiptResponse::class, $response); } @@ -63,10 +62,10 @@ public function testQuery() */ public function testCancelRetry() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $receipt = new Receipt($application); - $response = $receipt->cancelRetry("gggg7777GGGG7777hhhh8888HHHH88"); // using dummy receipt + $response = $receipt->cancelRetry('gggg7777GGGG7777hhhh8888HHHH88'); // using dummy receipt $this->assertInstanceOf(CancelRetryResponse::class, $response); } diff --git a/tests/Api/Subscription/SubscriptionTest.php b/tests/Api/Subscription/SubscriptionTest.php index f9a6515..843a0f4 100644 --- a/tests/Api/Subscription/SubscriptionTest.php +++ b/tests/Api/Subscription/SubscriptionTest.php @@ -1,6 +1,6 @@ @@ -22,13 +22,10 @@ */ class SubscriptionTest extends TestCase { - /** - * @return Subscription - */ public function testCanBeCreated(): Subscription { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $subscription = new Subscription($application, "dummy-subscription-aaa111bbb222ccc"); // using dummy subscription code + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $subscription = new Subscription($application, 'dummy-subscription-aaa111bbb222ccc'); // using dummy subscription code $this->assertInstanceOf(Subscription::class, $subscription); @@ -37,16 +34,14 @@ public function testCanBeCreated(): Subscription /** * @depends testCanBeCreated - * @param Subscription $subscription */ public function testGetSubscriptionCode(Subscription $subscription) { - $this->assertEquals("dummy-subscription-aaa111bbb222ccc", $subscription->getSubscriptionCode()); + $this->assertEquals('dummy-subscription-aaa111bbb222ccc', $subscription->getSubscriptionCode()); } /** * @depends testCanBeCreated - * @param Subscription $subscription */ public function testGetApplication(Subscription $subscription) { @@ -58,9 +53,9 @@ public function testGetApplication(Subscription $subscription) */ public function testMigrate() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $subscription = new Subscription($application, "dummy-subscription-aaa111bbb222ccc"); - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $subscription = new Subscription($application, 'dummy-subscription-aaa111bbb222ccc'); + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $recipient->addDevice('test-device-1'); diff --git a/tests/Api/UserGroupValidation/ValidationTest.php b/tests/Api/UserGroupValidation/ValidationTest.php index 5d6031d..07f49e4 100644 --- a/tests/Api/UserGroupValidation/ValidationTest.php +++ b/tests/Api/UserGroupValidation/ValidationTest.php @@ -1,6 +1,6 @@ @@ -22,12 +22,9 @@ */ class ValidationTest extends TestCase { - /** - * @return Validation - */ public function testCanBeCreated(): Validation { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $validation = new Validation($application); $this->assertInstanceOf(Validation::class, $validation); @@ -37,12 +34,11 @@ public function testCanBeCreated(): Validation /** * @depends testCanBeCreated - * @param Validation $validation */ public function testGetApplication(Validation $validation) { $this->assertInstanceOf(Application::class, $validation->getApplication()); - $this->assertEquals("cccc3333CCCC3333dddd4444DDDD44", $validation->getApplication()->getToken()); + $this->assertEquals('cccc3333CCCC3333dddd4444DDDD44', $validation->getApplication()->getToken()); } /** @@ -50,9 +46,9 @@ public function testGetApplication(Validation $validation) */ public function testValidate() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $validation = new Validation($application); - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $response = $validation->validate($recipient); diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 44ea385..f2c5c95 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -1,6 +1,6 @@ @@ -15,12 +15,9 @@ class ApplicationTest extends TestCase { - /** - * @return Application - */ public function testCanBeCreated(): Application { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); $this->assertInstanceOf(Application::class, $application); @@ -30,27 +27,26 @@ public function testCanBeCreated(): Application public function testCannotBeCreated() { $this->expectException(InvalidArgumentException::class); - new Application("Lorem ipsum dolor sit amet"); + new Application('Lorem ipsum dolor sit amet'); } public function testCannotBeCreatedFromInvalidApiToken(): void { $this->expectException(InvalidArgumentException::class); - new Application("this-is-invalid-token"); + new Application('this-is-invalid-token'); } public function testCannotBeCreatedFromShortApiToken(): void { $this->expectException(InvalidArgumentException::class); - new Application("token"); + new Application('token'); } /** * @depends testCanBeCreated - * @param Application $application */ public function testGetToken(Application $application) { - $this->assertEquals("cccc3333CCCC3333dddd4444DDDD44", $application->getToken()); + $this->assertEquals('cccc3333CCCC3333dddd4444DDDD44', $application->getToken()); } } diff --git a/tests/Client/AssignLicenseClientTest.php b/tests/Client/AssignLicenseClientTest.php index d4a7d1e..dc83997 100644 --- a/tests/Client/AssignLicenseClientTest.php +++ b/tests/Client/AssignLicenseClientTest.php @@ -1,6 +1,6 @@ @@ -24,13 +24,13 @@ public function testBuildApiUrl() { $client = new AssignLicenseClient(); $this->assertInstanceOf(AssignLicenseClient::class, $client); - $this->assertEquals("https://api.pushover.net/1/licenses/assign.json", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/licenses/assign.json', $client->buildApiUrl()); } public function testBuildCurlPostFields() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $license = new License($application); $email = 'dummy@email.com'; @@ -40,12 +40,12 @@ public function testBuildCurlPostFields() $client = new AssignLicenseClient(); - $curlPostFields = array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - "user" => "aaaa1111AAAA1111bbbb2222BBBB22", - "email" => "dummy@email.com", - "os" => "Android", - ); + $curlPostFields = [ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', + 'email' => 'dummy@email.com', + 'os' => 'Android', + ]; $this->assertEquals($curlPostFields, $client->buildCurlPostFields($license)); diff --git a/tests/Client/CancelRetryClientTest.php b/tests/Client/CancelRetryClientTest.php index a6e05a5..3b686e6 100644 --- a/tests/Client/CancelRetryClientTest.php +++ b/tests/Client/CancelRetryClientTest.php @@ -1,6 +1,6 @@ @@ -21,12 +21,9 @@ */ class CancelRetryClientTest extends TestCase { - /** - * @return CancelRetryClient - */ public function testCabBeCreated(): CancelRetryClient { - $client = new CancelRetryClient("gggg7777GGGG7777hhhh8888HHHH88"); // using dummy receipt + $client = new CancelRetryClient('gggg7777GGGG7777hhhh8888HHHH88'); // using dummy receipt $this->assertInstanceOf(CancelRetryClient::class, $client); @@ -35,29 +32,27 @@ public function testCabBeCreated(): CancelRetryClient /** * @depends testCabBeCreated - * @param CancelRetryClient $client */ public function testBuildCurlPostFields(CancelRetryClient $client) { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $receipt = new Receipt($application); $curlPostFields = $client->buildCurlPostFields($receipt); // using dummy receipt - $this->assertEquals(array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - ), $curlPostFields); + $this->assertEquals([ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + ], $curlPostFields); } /** * @depends testCabBeCreated - * @param CancelRetryClient $client */ public function testBuildApiUrl(CancelRetryClient $client) { $this->assertEquals( - "https://api.pushover.net/1/receipts/gggg7777GGGG7777hhhh8888HHHH88/cancel.json", - $client->buildApiUrl() + 'https://api.pushover.net/1/receipts/gggg7777GGGG7777hhhh8888HHHH88/cancel.json', + $client->buildApiUrl(), ); } } diff --git a/tests/Client/CheckLicenseClientTest.php b/tests/Client/CheckLicenseClientTest.php index e82eb76..64511e8 100644 --- a/tests/Client/CheckLicenseClientTest.php +++ b/tests/Client/CheckLicenseClientTest.php @@ -1,6 +1,6 @@ @@ -20,13 +20,13 @@ class CheckLicenseClientTest extends TestCase { public function testBuildApiUrl() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token $license = new License($application); $client = new CheckLicenseClient($license); $this->assertInstanceOf(CheckLicenseClient::class, $client); - $this->assertEquals("https://api.pushover.net/1/licenses.json?token=cccc3333CCCC3333dddd4444DDDD44", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/licenses.json?token=cccc3333CCCC3333dddd4444DDDD44', $client->buildApiUrl()); } } diff --git a/tests/Client/GlancesClientTest.php b/tests/Client/GlancesClientTest.php index 48f79d0..ca888a3 100644 --- a/tests/Client/GlancesClientTest.php +++ b/tests/Client/GlancesClientTest.php @@ -1,6 +1,6 @@ @@ -31,26 +31,26 @@ public function testBuildApiUrl() { $client = new GlancesClient(); - $this->assertEquals("https://api.pushover.net/1/glances.json", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/glances.json', $client->buildApiUrl()); } public function testBuildCurlPostFields() { $client = new GlancesClient(); - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $glanceDataFields = new GlanceDataFields(); $glance = new Glance($application, $glanceDataFields); $glance->setRecipient($recipient); - $glance->getGlanceDataFields()->setTitle("This is test title"); + $glance->getGlanceDataFields()->setTitle('This is test title'); - $curlPostFields = array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - "user" => "aaaa1111AAAA1111bbbb2222BBBB22", - "title" => "This is test title", - ); + $curlPostFields = [ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', + 'title' => 'This is test title', + ]; $this->assertEquals($curlPostFields, $client->buildCurlPostFields($glance)); } diff --git a/tests/Client/GroupsClientTest.php b/tests/Client/GroupsClientTest.php index 0b7b364..415eed3 100644 --- a/tests/Client/GroupsClientTest.php +++ b/tests/Client/GroupsClientTest.php @@ -1,6 +1,6 @@ @@ -24,8 +24,8 @@ class GroupsClientTest extends TestCase { public function testCanBeCreated() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application); // using dummy group key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $group = new Group('eeee5555EEEE5555ffff6666FFFF66', $application); // using dummy group key $client = new GroupsClient($group, GroupsClient::ACTION_RETRIEVE_GROUP); @@ -34,64 +34,64 @@ public function testCanBeCreated() public function testBuildApiUrl() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application); // using dummy group key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $group = new Group('eeee5555EEEE5555ffff6666FFFF66', $application); // using dummy group key // testing various "actions" below $client = new GroupsClient($group, GroupsClient::ACTION_RETRIEVE_GROUP); - $this->assertEquals("https://api.pushover.net/1/groups/eeee5555EEEE5555ffff6666FFFF66.json?token=cccc3333CCCC3333dddd4444DDDD44", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/groups/eeee5555EEEE5555ffff6666FFFF66.json?token=cccc3333CCCC3333dddd4444DDDD44', $client->buildApiUrl()); $client = new GroupsClient($group, GroupsClient::ACTION_ADD_USER); - $this->assertEquals("https://api.pushover.net/1/groups/eeee5555EEEE5555ffff6666FFFF66/add_user.json?token=cccc3333CCCC3333dddd4444DDDD44", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/groups/eeee5555EEEE5555ffff6666FFFF66/add_user.json?token=cccc3333CCCC3333dddd4444DDDD44', $client->buildApiUrl()); } public function testBuildCurlPostFields() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $group = new Group("eeee5555EEEE5555ffff6666FFFF66", $application); // using dummy group key - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $group = new Group('eeee5555EEEE5555ffff6666FFFF66', $application); // using dummy group key + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key // testing various "actions" below $client = new GroupsClient($group, GroupsClient::ACTION_ADD_USER); $this->assertEquals( - array( + [ 'token' => 'cccc3333CCCC3333dddd4444DDDD44', 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', - ), - $client->buildCurlPostFields($recipient) + ], + $client->buildCurlPostFields($recipient), ); $client = new GroupsClient($group, GroupsClient::ACTION_REMOVE_USER); $this->assertEquals( - array( + [ 'token' => 'cccc3333CCCC3333dddd4444DDDD44', 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', - ), - $client->buildCurlPostFields($recipient) + ], + $client->buildCurlPostFields($recipient), ); $client = new GroupsClient($group, GroupsClient::ACTION_ENABLE_USER); $this->assertEquals( - array( + [ 'token' => 'cccc3333CCCC3333dddd4444DDDD44', 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', - ), - $client->buildCurlPostFields($recipient) + ], + $client->buildCurlPostFields($recipient), ); $client = new GroupsClient($group, GroupsClient::ACTION_DISABLE_USER); $this->assertEquals( - array( + [ 'token' => 'cccc3333CCCC3333dddd4444DDDD44', 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', - ), - $client->buildCurlPostFields($recipient) + ], + $client->buildCurlPostFields($recipient), ); } } diff --git a/tests/Client/MessageClientTest.php b/tests/Client/MessageClientTest.php index 353f67f..0097bc6 100644 --- a/tests/Client/MessageClientTest.php +++ b/tests/Client/MessageClientTest.php @@ -1,6 +1,6 @@ @@ -29,23 +29,23 @@ public function testBuildApiUrl() { $client = new MessageClient(); - $this->assertEquals("https://api.pushover.net/1/messages.json", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/messages.json', $client->buildApiUrl()); } public function testBuildCurlPostFields() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key - $message = new Message("This is a test message", "This is a title of the message"); - $message->setUrl("https://www.example.com"); - $message->setUrlTitle("Example.com"); + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key + $message = new Message('This is a test message', 'This is a title of the message'); + $message->setUrl('https://www.example.com'); + $message->setUrlTitle('Example.com'); $message->setPriority(new Priority(Priority::EMERGENCY, 30, 300)); - $message->getPriority()->setCallback("https://callback.example.com"); + $message->getPriority()->setCallback('https://callback.example.com'); $message->setIsHtml(true); $message->setTtl(60 * 60 * 24); - $recipient->addDevice("ios"); - $recipient->addDevice("android"); + $recipient->addDevice('ios'); + $recipient->addDevice('android'); $notification = new Notification($application, $recipient, $message); $notification->setSound(new Sound(Sound::PUSHOVER)); @@ -54,19 +54,19 @@ public function testBuildCurlPostFields() $curlPostFields = $client->buildCurlPostFields($notification); $this->assertIsArray($curlPostFields); - $this->assertEquals("cccc3333CCCC3333dddd4444DDDD44", $curlPostFields['token']); - $this->assertEquals("aaaa1111AAAA1111bbbb2222BBBB22", $curlPostFields['user']); - $this->assertEquals("This is a test message", $curlPostFields['message']); - $this->assertEquals("ios,android", $curlPostFields['device']); - $this->assertEquals("This is a title of the message", $curlPostFields['title']); - $this->assertEquals("https://www.example.com", $curlPostFields['url']); - $this->assertEquals("Example.com", $curlPostFields['url_title']); - $this->assertEquals("2", $curlPostFields['priority']); - $this->assertEquals("30", $curlPostFields['retry']); - $this->assertEquals("300", $curlPostFields['expire']); - $this->assertEquals("https://callback.example.com", $curlPostFields['callback']); - $this->assertEquals("1", $curlPostFields['html']); - $this->assertEquals("86400", $curlPostFields['ttl']); - $this->assertEquals("pushover", $curlPostFields['sound']); + $this->assertEquals('cccc3333CCCC3333dddd4444DDDD44', $curlPostFields['token']); + $this->assertEquals('aaaa1111AAAA1111bbbb2222BBBB22', $curlPostFields['user']); + $this->assertEquals('This is a test message', $curlPostFields['message']); + $this->assertEquals('ios,android', $curlPostFields['device']); + $this->assertEquals('This is a title of the message', $curlPostFields['title']); + $this->assertEquals('https://www.example.com', $curlPostFields['url']); + $this->assertEquals('Example.com', $curlPostFields['url_title']); + $this->assertEquals('2', $curlPostFields['priority']); + $this->assertEquals('30', $curlPostFields['retry']); + $this->assertEquals('300', $curlPostFields['expire']); + $this->assertEquals('https://callback.example.com', $curlPostFields['callback']); + $this->assertEquals('1', $curlPostFields['html']); + $this->assertEquals('86400', $curlPostFields['ttl']); + $this->assertEquals('pushover', $curlPostFields['sound']); } } diff --git a/tests/Client/ReceiptClientTest.php b/tests/Client/ReceiptClientTest.php index 97acf8c..7d40e46 100644 --- a/tests/Client/ReceiptClientTest.php +++ b/tests/Client/ReceiptClientTest.php @@ -1,6 +1,6 @@ @@ -20,13 +20,10 @@ */ class ReceiptClientTest extends TestCase { - /** - * @return ReceiptClient - */ public function testCanBeCreated(): ReceiptClient { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $client = new ReceiptClient($application, "gggg7777GGGG7777hhhh8888HHHH88"); // using dummy receipt + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $client = new ReceiptClient($application, 'gggg7777GGGG7777hhhh8888HHHH88'); // using dummy receipt $this->assertInstanceOf(ReceiptClient::class, $client); @@ -35,13 +32,12 @@ public function testCanBeCreated(): ReceiptClient /** * @depends testCanBeCreated - * @param ReceiptClient $client */ public function testBuildApiUrl(ReceiptClient $client) { $this->assertEquals( - "https://api.pushover.net/1/receipts/gggg7777GGGG7777hhhh8888HHHH88.json?token=cccc3333CCCC3333dddd4444DDDD44", - $client->buildApiUrl() + 'https://api.pushover.net/1/receipts/gggg7777GGGG7777hhhh8888HHHH88.json?token=cccc3333CCCC3333dddd4444DDDD44', + $client->buildApiUrl(), ); } } diff --git a/tests/Client/Request/RequestTest.php b/tests/Client/Request/RequestTest.php index 7f37078..4754a42 100644 --- a/tests/Client/Request/RequestTest.php +++ b/tests/Client/Request/RequestTest.php @@ -1,6 +1,6 @@ @@ -24,7 +24,7 @@ class RequestTest extends TestCase */ public function testCanBeCrated() { - $request = new Request("https://test.com/api", Request::POST, array()); + $request = new Request('https://test.com/api', Request::POST, []); $this->assertInstanceOf(Request::class, $request); @@ -33,7 +33,6 @@ public function testCanBeCrated() /** * @depends testCanBeCrated - * @param Request $request */ public function testGetMethod(Request $request) { @@ -42,16 +41,14 @@ public function testGetMethod(Request $request) /** * @depends testCanBeCrated - * @param Request $request */ public function testGetApiUrl(Request $request) { - $this->assertEquals("https://test.com/api", $request->getApiUrl()); + $this->assertEquals('https://test.com/api', $request->getApiUrl()); } /** * @depends testCanBeCrated - * @param Request $request */ public function testGetCurlPostFields(Request $request) { diff --git a/tests/Client/Response/AddUserToGroupResponseTest.php b/tests/Client/Response/AddUserToGroupResponseTest.php index 234355f..3afa596 100644 --- a/tests/Client/Response/AddUserToGroupResponseTest.php +++ b/tests/Client/Response/AddUserToGroupResponseTest.php @@ -1,6 +1,6 @@ @@ -26,14 +26,14 @@ public function testCenBeCreated() $this->assertInstanceOf(AddUserToGroupResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"user":"invalid","errors":["user is already a member of this group"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new AddUserToGroupResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(AddUserToGroupResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "user is already a member of this group"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'user is already a member of this group'], $response->getErrors()); } } diff --git a/tests/Client/Response/CancelRetryResponseTest.php b/tests/Client/Response/CancelRetryResponseTest.php index fff8e12..42b325e 100644 --- a/tests/Client/Response/CancelRetryResponseTest.php +++ b/tests/Client/Response/CancelRetryResponseTest.php @@ -1,6 +1,6 @@ @@ -26,14 +26,14 @@ public function testCenBeCreated() $this->assertInstanceOf(CancelRetryResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"receipt":"not found","errors":["receipt not found; may be invalid or expired"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new CancelRetryResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(CancelRetryResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "receipt not found; may be invalid or expired"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'receipt not found; may be invalid or expired'], $response->getErrors()); } } diff --git a/tests/Client/Response/DisableUserInGroupResponseTest.php b/tests/Client/Response/DisableUserInGroupResponseTest.php index be64078..c5fb498 100644 --- a/tests/Client/Response/DisableUserInGroupResponseTest.php +++ b/tests/Client/Response/DisableUserInGroupResponseTest.php @@ -1,6 +1,6 @@ @@ -26,14 +26,14 @@ public function testCenBeCreated() $this->assertInstanceOf(DisableUserInGroupResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"user":"invalid","errors":["user is not a member of this group"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new DisableUserInGroupResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(DisableUserInGroupResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "user is not a member of this group"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'user is not a member of this group'], $response->getErrors()); } } diff --git a/tests/Client/Response/EnableUserInGroupResponseTest.php b/tests/Client/Response/EnableUserInGroupResponseTest.php index f35ce1e..ace0059 100644 --- a/tests/Client/Response/EnableUserInGroupResponseTest.php +++ b/tests/Client/Response/EnableUserInGroupResponseTest.php @@ -1,6 +1,6 @@ @@ -26,14 +26,14 @@ public function testCenBeCreated() $this->assertInstanceOf(EnableUserInGroupResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"user":"invalid","errors":["user is not a member of this group"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new EnableUserInGroupResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(EnableUserInGroupResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "user is not a member of this group"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'user is not a member of this group'], $response->getErrors()); } } diff --git a/tests/Client/Response/GlancesResponseTest.php b/tests/Client/Response/GlancesResponseTest.php index 0dd92be..0100032 100644 --- a/tests/Client/Response/GlancesResponseTest.php +++ b/tests/Client/Response/GlancesResponseTest.php @@ -1,6 +1,6 @@ @@ -23,14 +23,14 @@ public function testCanBeCreated() $this->assertInstanceOf(GlancesResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"token":"invalid","errors":["application token is invalid"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new GlancesResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(GlancesResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "application token is invalid"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'application token is invalid'], $response->getErrors()); } } diff --git a/tests/Client/Response/LicenseResponseTest.php b/tests/Client/Response/LicenseResponseTest.php index e193249..f5b50e1 100644 --- a/tests/Client/Response/LicenseResponseTest.php +++ b/tests/Client/Response/LicenseResponseTest.php @@ -1,6 +1,6 @@ @@ -26,7 +26,7 @@ public function testCanBeCreated() $this->assertInstanceOf(LicenseResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $this->assertEquals(5, $response->getCredits()); $unSuccessfulCurlResponse = '{"token":"is out of available license credits","errors":["application is out of available license credits"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; @@ -34,8 +34,8 @@ public function testCanBeCreated() $this->assertInstanceOf(LicenseResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "application is out of available license credits"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'application is out of available license credits'], $response->getErrors()); } public function testGetCredits() diff --git a/tests/Client/Response/MessageResponseTest.php b/tests/Client/Response/MessageResponseTest.php index cf168f2..99d16fd 100644 --- a/tests/Client/Response/MessageResponseTest.php +++ b/tests/Client/Response/MessageResponseTest.php @@ -1,6 +1,6 @@ @@ -26,16 +26,16 @@ public function testCanBeCrated() $this->assertInstanceOf(MessageResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals("gggg7777GGGG7777hhhh8888HHHH88", $response->getReceipt()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals('gggg7777GGGG7777hhhh8888HHHH88', $response->getReceipt()); $unSuccessfulCurlResponse = '{"user":"invalid","errors":["user identifier is not a valid user, group, or subscribed user key"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new MessageResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(MessageResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "user identifier is not a valid user, group, or subscribed user key"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'user identifier is not a valid user, group, or subscribed user key'], $response->getErrors()); } public function testGetReceipt() @@ -43,6 +43,6 @@ public function testGetReceipt() $successfulCurlResponse = '{"receipt":"gggg7777GGGG7777hhhh8888HHHH88","status":1,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new MessageResponse($successfulCurlResponse); - $this->assertEquals("gggg7777GGGG7777hhhh8888HHHH88", $response->getReceipt()); + $this->assertEquals('gggg7777GGGG7777hhhh8888HHHH88', $response->getReceipt()); } } diff --git a/tests/Client/Response/ReceiptResponseTest.php b/tests/Client/Response/ReceiptResponseTest.php index 9f0c188..264e2d4 100644 --- a/tests/Client/Response/ReceiptResponseTest.php +++ b/tests/Client/Response/ReceiptResponseTest.php @@ -1,6 +1,6 @@ @@ -20,9 +20,6 @@ */ class ReceiptResponseTest extends TestCase { - /** - * @return ReceiptResponse - */ public function testCanBeCreated(): ReceiptResponse { $unSuccessfulCurlResponse = '{"receipt":"not found","errors":["receipt not found; may be invalid or expired"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; @@ -30,41 +27,38 @@ public function testCanBeCreated(): ReceiptResponse $this->assertInstanceOf(ReceiptResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "receipt not found; may be invalid or expired"), $response->getErrors()); - + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'receipt not found; may be invalid or expired'], $response->getErrors()); + $successfulCurlResponse = '{"status":1,"acknowledged":1,"acknowledged_at":1593975206,"acknowledged_by":"aaaa1111AAAA1111bbbb2222BBBB22","acknowledged_by_device":"test-device-1","last_delivered_at":1593975186,"expired":1,"expires_at":1593975485,"called_back":1,"called_back_at":1593975206,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new ReceiptResponse($successfulCurlResponse); $this->assertInstanceOf(ReceiptResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); return $response; } /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testGetAcknowledgedBy(ReceiptResponse $response) { $this->assertInstanceOf(Recipient::class, $response->getAcknowledgedBy()); - $this->assertEquals("aaaa1111AAAA1111bbbb2222BBBB22", $response->getAcknowledgedBy()->getUserKey()); + $this->assertEquals('aaaa1111AAAA1111bbbb2222BBBB22', $response->getAcknowledgedBy()->getUserKey()); } /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testGetAcknowledgedByDevice(ReceiptResponse $response) { - $this->assertEquals("test-device-1", $response->getAcknowledgedByDevice()); + $this->assertEquals('test-device-1', $response->getAcknowledgedByDevice()); } /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testGetExpiresAt(ReceiptResponse $response) { @@ -73,7 +67,6 @@ public function testGetExpiresAt(ReceiptResponse $response) /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testGetLastDeliveredAt(ReceiptResponse $response) { @@ -82,7 +75,6 @@ public function testGetLastDeliveredAt(ReceiptResponse $response) /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testIsAcknowledged(ReceiptResponse $response) { @@ -91,7 +83,6 @@ public function testIsAcknowledged(ReceiptResponse $response) /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testGetCalledBackAt(ReceiptResponse $response) { @@ -100,7 +91,6 @@ public function testGetCalledBackAt(ReceiptResponse $response) /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testGetAcknowledgedAt(ReceiptResponse $response) { @@ -109,7 +99,6 @@ public function testGetAcknowledgedAt(ReceiptResponse $response) /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testHasCalledBack(ReceiptResponse $response) { @@ -118,7 +107,6 @@ public function testHasCalledBack(ReceiptResponse $response) /** * @depends testCanBeCreated - * @param ReceiptResponse $response */ public function testIsExpired(ReceiptResponse $response) { diff --git a/tests/Client/Response/RemoveUserFromGroupResponseTest.php b/tests/Client/Response/RemoveUserFromGroupResponseTest.php index 5b3db81..fb61fdc 100644 --- a/tests/Client/Response/RemoveUserFromGroupResponseTest.php +++ b/tests/Client/Response/RemoveUserFromGroupResponseTest.php @@ -1,6 +1,6 @@ @@ -26,14 +26,14 @@ public function testCenBeCreated() $this->assertInstanceOf(RemoveUserFromGroupResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"user":"invalid","errors":["user is not a member of this group"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new RemoveUserFromGroupResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(RemoveUserFromGroupResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "user is not a member of this group"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'user is not a member of this group'], $response->getErrors()); } } diff --git a/tests/Client/Response/RenameGroupResponseTest.php b/tests/Client/Response/RenameGroupResponseTest.php index 199e3a3..c874b90 100644 --- a/tests/Client/Response/RenameGroupResponseTest.php +++ b/tests/Client/Response/RenameGroupResponseTest.php @@ -1,6 +1,6 @@ @@ -26,14 +26,14 @@ public function testCenBeCreated() $this->assertInstanceOf(RenameGroupResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"group":"not found","errors":["group not found or you are not authorized to edit it"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new RenameGroupResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(RenameGroupResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "group not found or you are not authorized to edit it"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'group not found or you are not authorized to edit it'], $response->getErrors()); } } diff --git a/tests/Client/Response/RetrieveGroupResponseTest.php b/tests/Client/Response/RetrieveGroupResponseTest.php index d915936..34613de 100644 --- a/tests/Client/Response/RetrieveGroupResponseTest.php +++ b/tests/Client/Response/RetrieveGroupResponseTest.php @@ -1,6 +1,6 @@ @@ -17,9 +17,6 @@ class RetrieveGroupResponseTest extends TestCase { - /** - * @return RetrieveGroupResponse - */ public function testCanBeCreated(): RetrieveGroupResponse { $unSuccessfulCurlResponse = '{"group":"not found","errors":["group not found or you are not authorized to edit it"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; @@ -27,40 +24,38 @@ public function testCanBeCreated(): RetrieveGroupResponse $this->assertInstanceOf(RetrieveGroupResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "group not found or you are not authorized to edit it"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'group not found or you are not authorized to edit it'], $response->getErrors()); $successfulCurlResponse = '{"name":"Test Group","users":[{"user":"aaaa1111AAAA1111bbbb2222BBBB22","device":"test-device-1","memo":"This is a test memo","disabled":false}],"status":1,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new RetrieveGroupResponse($successfulCurlResponse); $this->assertInstanceOf(RetrieveGroupResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); return $response; } /** * @depends testCanBeCreated - * @param RetrieveGroupResponse $response */ public function testGetName(RetrieveGroupResponse $response) { - $this->assertEquals("Test Group", $response->getName()); + $this->assertEquals('Test Group', $response->getName()); } /** * @depends testCanBeCreated - * @param RetrieveGroupResponse $response */ public function testGetUsers(RetrieveGroupResponse $response) { $recipient = $response->getUsers()[0]; $this->assertInstanceOf(Recipient::class, $recipient); - $this->assertEquals("aaaa1111AAAA1111bbbb2222BBBB22", $recipient->getUserKey()); + $this->assertEquals('aaaa1111AAAA1111bbbb2222BBBB22', $recipient->getUserKey()); $this->assertFalse($recipient->isDisabled()); - $this->assertEquals("This is a test memo", $recipient->getMemo()); - $this->assertEquals(array("test-device-1"), $recipient->getDevice()); + $this->assertEquals('This is a test memo', $recipient->getMemo()); + $this->assertEquals(['test-device-1'], $recipient->getDevice()); } } diff --git a/tests/Client/Response/SubscriptionResponseTest.php b/tests/Client/Response/SubscriptionResponseTest.php index a72135f..123d211 100644 --- a/tests/Client/Response/SubscriptionResponseTest.php +++ b/tests/Client/Response/SubscriptionResponseTest.php @@ -1,6 +1,6 @@ @@ -26,15 +26,15 @@ public function testCanBeCreated() $this->assertInstanceOf(SubscriptionResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); $unSuccessfulCurlResponse = '{"subscription":"invalid","errors":["subscription code is invalid"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new SubscriptionResponse($unSuccessfulCurlResponse); $this->assertInstanceOf(SubscriptionResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "subscription code is invalid"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'subscription code is invalid'], $response->getErrors()); } public function testGetSubscribedUserKey() @@ -43,6 +43,6 @@ public function testGetSubscribedUserKey() $response = new SubscriptionResponse($curlResponse); - $this->assertEquals("aaaa1111AAAA1111bbbb2222BBBB22", $response->getSubscribedUserKey()); + $this->assertEquals('aaaa1111AAAA1111bbbb2222BBBB22', $response->getSubscribedUserKey()); } } diff --git a/tests/Client/Response/UserGroupValidationResponseTest.php b/tests/Client/Response/UserGroupValidationResponseTest.php index 40bf4fd..fa1cdb5 100644 --- a/tests/Client/Response/UserGroupValidationResponseTest.php +++ b/tests/Client/Response/UserGroupValidationResponseTest.php @@ -1,6 +1,6 @@ @@ -19,9 +19,6 @@ */ class UserGroupValidationResponseTest extends TestCase { - /** - * @return UserGroupValidationResponse - */ public function testCanBeCreated(): UserGroupValidationResponse { $unSuccessfulCurlResponse = '{"user":"invalid","errors":["user key is invalid"],"status":0,"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; @@ -29,40 +26,37 @@ public function testCanBeCreated(): UserGroupValidationResponse $this->assertInstanceOf(UserGroupValidationResponse::class, $response); $this->assertFalse($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); - $this->assertEquals(array(0 => "user key is invalid"), $response->getErrors()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); + $this->assertEquals([0 => 'user key is invalid'], $response->getErrors()); $successfulCurlResponse = '{"status":1,"group":0,"devices":["test-device-1", "test-device-2"],"licenses":["Android","iOS"],"request":"aaaaaaaa-1111-bbbb-2222-cccccccccccc"}'; $response = new UserGroupValidationResponse($successfulCurlResponse); $this->assertInstanceOf(UserGroupValidationResponse::class, $response); $this->assertTrue($response->isSuccessful()); - $this->assertEquals("aaaaaaaa-1111-bbbb-2222-cccccccccccc", $response->getRequestToken()); + $this->assertEquals('aaaaaaaa-1111-bbbb-2222-cccccccccccc', $response->getRequestToken()); return $response; } /** * @depends testCanBeCreated - * @param UserGroupValidationResponse $response */ public function testGetLicenses(UserGroupValidationResponse $response) { - $this->assertEquals(array("Android","iOS"), $response->getLicenses()); + $this->assertEquals(['Android', 'iOS'], $response->getLicenses()); } /** * @depends testCanBeCreated - * @param UserGroupValidationResponse $response */ public function testGetDevices(UserGroupValidationResponse $response) { - $this->assertEquals(array("test-device-1", "test-device-2"), $response->getDevices()); + $this->assertEquals(['test-device-1', 'test-device-2'], $response->getDevices()); } /** * @depends testCanBeCreated - * @param UserGroupValidationResponse $response */ public function testGetIsGroup(UserGroupValidationResponse $response) { diff --git a/tests/Client/SubscriptionClientTest.php b/tests/Client/SubscriptionClientTest.php index 4af2b45..1e5b48c 100644 --- a/tests/Client/SubscriptionClientTest.php +++ b/tests/Client/SubscriptionClientTest.php @@ -1,6 +1,6 @@ @@ -32,41 +32,41 @@ public function testCanBeCreated() public function testBuildCurlPostFields() { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key - $subscription = new Subscription($application, "dummy-subscription-aaa111bbb222ccc"); // using dummy subscription code + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key + $subscription = new Subscription($application, 'dummy-subscription-aaa111bbb222ccc'); // using dummy subscription code $client = new SubscriptionClient(); // only required parameters - $curlPostFields = array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - "subscription" => "dummy-subscription-aaa111bbb222ccc", - "user" => "aaaa1111AAAA1111bbbb2222BBBB22", - ); + $curlPostFields = [ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + 'subscription' => 'dummy-subscription-aaa111bbb222ccc', + 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', + ]; $this->assertEquals($curlPostFields, $client->buildCurlPostFields($subscription, $recipient)); // add recipient device - $recipient->addDevice("test-device-1"); + $recipient->addDevice('test-device-1'); - $curlPostFields = array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - "subscription" => "dummy-subscription-aaa111bbb222ccc", - "user" => "aaaa1111AAAA1111bbbb2222BBBB22", - "device_name" => "test-device-1", - ); + $curlPostFields = [ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + 'subscription' => 'dummy-subscription-aaa111bbb222ccc', + 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', + 'device_name' => 'test-device-1', + ]; $this->assertEquals($curlPostFields, $client->buildCurlPostFields($subscription, $recipient)); // add sound - $curlPostFields = array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - "subscription" => "dummy-subscription-aaa111bbb222ccc", - "user" => "aaaa1111AAAA1111bbbb2222BBBB22", - "device_name" => "test-device-1", - "sound" => "pushover", - ); + $curlPostFields = [ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + 'subscription' => 'dummy-subscription-aaa111bbb222ccc', + 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', + 'device_name' => 'test-device-1', + 'sound' => 'pushover', + ]; $this->assertEquals($curlPostFields, $client->buildCurlPostFields($subscription, $recipient, new Sound(Sound::PUSHOVER))); } @@ -75,6 +75,6 @@ public function testBuildApiUrl() { $client = new SubscriptionClient(); - $this->assertEquals("https://api.pushover.net/1/subscriptions/migrate.json", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/subscriptions/migrate.json', $client->buildApiUrl()); } } diff --git a/tests/Client/UserGroupValidationClientTest.php b/tests/Client/UserGroupValidationClientTest.php index f57b913..7506172 100644 --- a/tests/Client/UserGroupValidationClientTest.php +++ b/tests/Client/UserGroupValidationClientTest.php @@ -1,6 +1,6 @@ @@ -32,26 +32,24 @@ public function testCanBeCreated() /** * @depends testCanBeCreated - * @param UserGroupValidationClient $client */ public function testBuildCurlPostFields(UserGroupValidationClient $client) { - $application = new Application("cccc3333CCCC3333dddd4444DDDD44"); // using dummy token - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); // using dummy user key + $application = new Application('cccc3333CCCC3333dddd4444DDDD44'); // using dummy token + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); // using dummy user key $curlPostFields = $client->buildCurlPostFields($application, $recipient); - $this->assertEquals(array( - "token" => "cccc3333CCCC3333dddd4444DDDD44", - "user" => "aaaa1111AAAA1111bbbb2222BBBB22", - ), $curlPostFields); + $this->assertEquals([ + 'token' => 'cccc3333CCCC3333dddd4444DDDD44', + 'user' => 'aaaa1111AAAA1111bbbb2222BBBB22', + ], $curlPostFields); } /** * @depends testCanBeCreated - * @param UserGroupValidationClient $client */ public function testBuildApiUrl(UserGroupValidationClient $client) { - $this->assertEquals("https://api.pushover.net/1/users/validate.json", $client->buildApiUrl()); + $this->assertEquals('https://api.pushover.net/1/users/validate.json', $client->buildApiUrl()); } } diff --git a/tests/RecipientTest.php b/tests/RecipientTest.php index 8c01cb7..762bf71 100644 --- a/tests/RecipientTest.php +++ b/tests/RecipientTest.php @@ -1,6 +1,6 @@ @@ -18,16 +18,13 @@ */ class RecipientTest extends TestCase { - /** - * @return Recipient - */ public function testCanBeCreated(): Recipient { - $recipient = new Recipient("aaaa1111AAAA1111bbbb2222BBBB22"); + $recipient = new Recipient('aaaa1111AAAA1111bbbb2222BBBB22'); $recipient->setIsDisabled(false); - $recipient->addDevice("test-device-1"); - $recipient->addDevice("test-device-2"); - $recipient->setMemo("This is test memo"); + $recipient->addDevice('test-device-1'); + $recipient->addDevice('test-device-2'); + $recipient->setMemo('This is test memo'); $this->assertInstanceOf(Recipient::class, $recipient); @@ -37,45 +34,41 @@ public function testCanBeCreated(): Recipient public function testCannotBeCreated() { $this->expectException(InvalidArgumentException::class); - new Recipient("Lorem ipsum dolor sit amet"); + new Recipient('Lorem ipsum dolor sit amet'); } /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testGetUserKey(Recipient $recipient) { - $this->assertEquals("aaaa1111AAAA1111bbbb2222BBBB22", $recipient->getUserKey()); + $this->assertEquals('aaaa1111AAAA1111bbbb2222BBBB22', $recipient->getUserKey()); } /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testGetDevice(Recipient $recipient) { $this->assertEquals( - array( - "test-device-1", - "test-device-2", - ), - $recipient->getDevice() + [ + 'test-device-1', + 'test-device-2', + ], + $recipient->getDevice(), ); } /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testGetDeviceListCommaSeparated(Recipient $recipient) { - $this->assertEquals("test-device-1,test-device-2", $recipient->getDeviceListCommaSeparated()); + $this->assertEquals('test-device-1,test-device-2', $recipient->getDeviceListCommaSeparated()); } /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testIsDisabled(Recipient $recipient) { @@ -84,16 +77,14 @@ public function testIsDisabled(Recipient $recipient) /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testGetMemo(Recipient $recipient) { - $this->assertEquals("This is test memo", $recipient->getMemo()); + $this->assertEquals('This is test memo', $recipient->getMemo()); } /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testSetIsDisabled(Recipient $recipient) { @@ -103,21 +94,19 @@ public function testSetIsDisabled(Recipient $recipient) /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testSetMemo(Recipient $recipient) { $this->expectException(InvalidArgumentException::class); - $recipient->setMemo("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."); + $recipient->setMemo('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'); } /** * @depends testCanBeCreated - * @param Recipient $recipient */ public function testAddDevice(Recipient $recipient) { $this->expectException(InvalidArgumentException::class); - $recipient->addDevice("Lorem-ipsum-dolor-sit-amet"); + $recipient->addDevice('Lorem-ipsum-dolor-sit-amet'); } }