diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..734db04c --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,20 @@ +name: "CodeQL" + +on: [pull_request] +jobs: + lint: + name: CodeQL + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Run CodeQL + run: | + docker run --rm -v $PWD:/app composer sh -c \ + "composer install --profile --ignore-platform-reqs && composer check" \ No newline at end of file diff --git a/composer.json b/composer.json index 0e9de463..4d3b8475 100644 --- a/composer.json +++ b/composer.json @@ -6,9 +6,10 @@ "license": "MIT", "minimum-stability": "stable", "scripts": { - "test": "vendor/bin/phpunit", + "test": "./vendor/bin/phpunit", "lint": "./vendor/bin/pint --test", - "format": "./vendor/bin/pint" + "format": "./vendor/bin/pint", + "check": "./vendor/bin/phpstan analyse --level 8 src tests" }, "autoload": { "psr-4": { @@ -28,7 +29,8 @@ "require-dev": { "phpunit/phpunit": "9.5.*", "phpmailer/phpmailer": "6.6.*", - "laravel/pint": "^1.2" + "laravel/pint": "^1.2", + "phpstan/phpstan": "^1.9" }, "config": { "platform": { diff --git a/composer.lock b/composer.lock index c2118454..4902d1fb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,35 +4,35 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1ca9da311c804e40032e90c09ad04d76", + "content-hash": "05988be0318fcccd8354a439b6103139", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -59,7 +59,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -75,20 +75,20 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "laravel/pint", - "version": "v1.2.0", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86" + "reference": "e0a8cef58b74662f27355be9cdea0e726bbac362" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/1d276e4c803397a26cc337df908f55c2a4e90d86", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86", + "url": "https://api.github.com/repos/laravel/pint/zipball/e0a8cef58b74662f27355be9cdea0e726bbac362", + "reference": "e0a8cef58b74662f27355be9cdea0e726bbac362", "shasum": "" }, "require": { @@ -99,13 +99,13 @@ "php": "^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11.0", - "illuminate/view": "^9.27", - "laravel-zero/framework": "^9.1.3", - "mockery/mockery": "^1.5.0", - "nunomaduro/larastan": "^2.2", - "nunomaduro/termwind": "^1.14.0", - "pestphp/pest": "^1.22.1" + "friendsofphp/php-cs-fixer": "^3.14.4", + "illuminate/view": "^9.51.0", + "laravel-zero/framework": "^9.2.0", + "mockery/mockery": "^1.5.1", + "nunomaduro/larastan": "^2.4.0", + "nunomaduro/termwind": "^1.15.1", + "pestphp/pest": "^1.22.4" }, "bin": [ "builds/pint" @@ -141,7 +141,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2022-09-13T15:07:15+00:00" + "time": "2023-02-14T16:31:02+00:00" }, { "name": "myclabs/deep-copy", @@ -204,16 +204,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.1", + "version": "v4.15.3", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900" + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039", + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039", "shasum": "" }, "require": { @@ -254,9 +254,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3" }, - "time": "2022-09-04T07:30:47+00:00" + "time": "2023-01-16T22:05:37+00:00" }, { "name": "phar-io/manifest", @@ -371,16 +371,16 @@ }, { "name": "phpmailer/phpmailer", - "version": "v6.6.4", + "version": "v6.6.5", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "a94fdebaea6bd17f51be0c2373ab80d3d681269b" + "reference": "8b6386d7417526d1ea4da9edb70b8352f7543627" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/a94fdebaea6bd17f51be0c2373ab80d3d681269b", - "reference": "a94fdebaea6bd17f51be0c2373ab80d3d681269b", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/8b6386d7417526d1ea4da9edb70b8352f7543627", + "reference": "8b6386d7417526d1ea4da9edb70b8352f7543627", "shasum": "" }, "require": { @@ -404,8 +404,8 @@ "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", "league/oauth2-google": "Needed for Google XOAUTH2 authentication", "psr/log": "For optional PSR-3 debug logging", - "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", - "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" + "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)", + "thenetworg/oauth2-azure": "Needed for Microsoft XOAUTH2 authentication" }, "type": "library", "autoload": { @@ -437,7 +437,7 @@ "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "support": { "issues": "https://github.com/PHPMailer/PHPMailer/issues", - "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.6.4" + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.6.5" }, "funding": [ { @@ -445,20 +445,79 @@ "type": "github" } ], - "time": "2022-08-22T09:22:00+00:00" + "time": "2022-10-07T12:23:10+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.9.18", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "f2d5cf71be91172a57c649770b73c20ebcffb0bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f2d5cf71be91172a57c649770b73c20ebcffb0bf", + "reference": "f2d5cf71be91172a57c649770b73c20ebcffb0bf", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.9.18" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-02-17T15:01:27+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.17", + "version": "9.2.24", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" + "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2cf940ebc6355a9d430462811b5aaa308b174bed", + "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed", "shasum": "" }, "require": { @@ -514,7 +573,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.24" }, "funding": [ { @@ -522,7 +581,7 @@ "type": "github" } ], - "time": "2022-08-30T12:24:04+00:00" + "time": "2023-01-26T08:26:55+00:00" }, { "name": "phpunit/php-file-iterator", @@ -767,20 +826,20 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.25", + "version": "9.5.28", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d" + "reference": "954ca3113a03bf780d22f07bf055d883ee04b65e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d", - "reference": "3e6f90ca7e3d02025b1d147bd8d4a89fd4ca8a1d", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/954ca3113a03bf780d22f07bf055d883ee04b65e", + "reference": "954ca3113a03bf780d22f07bf055d883ee04b65e", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1", + "doctrine/instantiator": "^1.3.1 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", @@ -849,7 +908,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.25" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.28" }, "funding": [ { @@ -865,7 +924,7 @@ "type": "tidelift" } ], - "time": "2022-09-25T03:44:45+00:00" + "time": "2023-01-14T12:32:24+00:00" }, { "name": "sebastian/cli-parser", @@ -1233,16 +1292,16 @@ }, { "name": "sebastian/environment", - "version": "5.1.4", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", "shasum": "" }, "require": { @@ -1284,7 +1343,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -1292,7 +1351,7 @@ "type": "github" } ], - "time": "2022-04-03T09:37:03+00:00" + "time": "2023-02-03T06:03:51+00:00" }, { "name": "sebastian/exporter", @@ -1606,16 +1665,16 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172" + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { @@ -1654,10 +1713,10 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, "funding": [ { @@ -1665,7 +1724,7 @@ "type": "github" } ], - "time": "2020-10-26T13:17:30+00:00" + "time": "2023-02-03T06:07:39+00:00" }, { "name": "sebastian/resource-operations", @@ -1724,16 +1783,16 @@ }, { "name": "sebastian/type", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { @@ -1768,7 +1827,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -1776,7 +1835,7 @@ "type": "github" } ], - "time": "2022-09-12T14:47:03+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { "name": "sebastian/version", diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index 60a909ef..9e1d5195 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -6,29 +6,21 @@ abstract class Adapter { /** * Get the name of the adapter. - * - * @return string */ abstract public function getName(): string; /** * Get the type of the adapter. - * - * @return string */ abstract public function getType(): string; /** * Get the type of the message the adapter can send. - * - * @return string */ abstract public function getMessageType(): string; /** * Get the maximum number of messages that can be sent in a single request. - * - * @return int */ abstract public function getMaxMessagesPerRequest(): int; @@ -45,8 +37,8 @@ abstract public function send(Message $message): string; * * @param string $method The HTTP method to use. * @param string $url The URL to send the request to. - * @param array $headers An array of headers to send with the request. - * @param string|null $body The body of the request. + * @param array $headers An array of headers to send with the request. + * @param ?string $body The body of the request * @return string The response body. * * @throws \Exception If the request fails. @@ -70,11 +62,12 @@ protected function request( \curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); \curl_setopt($ch, CURLOPT_USERAGENT, "Appwrite {$this->getName()} Message Sender"); - $response = \curl_exec($ch); + $response = strval(\curl_exec($ch)); if (\curl_errno($ch)) { throw new \Exception('Error: '.\curl_error($ch)); } + if (\curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 400) { throw new \Exception($response); } diff --git a/src/Utopia/Messaging/Adapters/Email.php b/src/Utopia/Messaging/Adapters/Email.php index 55318e46..04f42a25 100644 --- a/src/Utopia/Messaging/Adapters/Email.php +++ b/src/Utopia/Messaging/Adapters/Email.php @@ -21,6 +21,8 @@ public function getMessageType(): string /** * {@inheritdoc} * + * @param Message $message Message to send. + * * @throws \Exception */ public function send(Message $message): string diff --git a/src/Utopia/Messaging/Adapters/Email/Mock.php b/src/Utopia/Messaging/Adapters/Email/Mock.php index 0f326106..35f65a14 100644 --- a/src/Utopia/Messaging/Adapters/Email/Mock.php +++ b/src/Utopia/Messaging/Adapters/Email/Mock.php @@ -23,6 +23,7 @@ public function getMaxMessagesPerRequest(): int /** * {@inheritdoc} * + * * @throws Exception * @throws \Exception */ diff --git a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php b/src/Utopia/Messaging/Adapters/Email/Sendgrid.php index 17745c48..61c853de 100644 --- a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapters/Email/Sendgrid.php @@ -50,7 +50,7 @@ protected function process(Email $message): string 'value' => $message->getContent(), ], ], - ]), + ]) ?: null, ); } } diff --git a/src/Utopia/Messaging/Adapters/Push.php b/src/Utopia/Messaging/Adapters/Push.php index 6d96d9c4..3b37513f 100644 --- a/src/Utopia/Messaging/Adapters/Push.php +++ b/src/Utopia/Messaging/Adapters/Push.php @@ -21,6 +21,8 @@ public function getMessageType(): string /** * {@inheritdoc} * + * @param Message $message Message to send. + * * @throws \Exception */ public function send(Message $message): string diff --git a/src/Utopia/Messaging/Adapters/Push/FCM.php b/src/Utopia/Messaging/Adapters/Push/FCM.php index 3734b16d..021af043 100644 --- a/src/Utopia/Messaging/Adapters/Push/FCM.php +++ b/src/Utopia/Messaging/Adapters/Push/FCM.php @@ -52,7 +52,7 @@ protected function process(Push $message): string 'tag' => $message->getTag(), ], 'data' => $message->getData(), - ]) + ]) ?: null ); } } diff --git a/src/Utopia/Messaging/Adapters/SMS.php b/src/Utopia/Messaging/Adapters/SMS.php index 5a2b6c4e..6843d635 100644 --- a/src/Utopia/Messaging/Adapters/SMS.php +++ b/src/Utopia/Messaging/Adapters/SMS.php @@ -21,6 +21,8 @@ public function getMessageType(): string /** * {@inheritdoc} * + * @param Message $message Message to send. + * * @throws \Exception */ public function send(Message $message): string diff --git a/src/Utopia/Messaging/Adapters/SMS/Mock.php b/src/Utopia/Messaging/Adapters/SMS/Mock.php index a9cd0eb8..115cb62c 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Mock.php +++ b/src/Utopia/Messaging/Adapters/SMS/Mock.php @@ -46,7 +46,7 @@ protected function process(SMS $message): string 'message' => $message->getContent(), 'from' => $message->getFrom(), 'to' => \implode(',', $message->getTo()), - ]), + ]) ?: null, ); } } diff --git a/src/Utopia/Messaging/Adapters/SMS/Msg91.php b/src/Utopia/Messaging/Adapters/SMS/Msg91.php index 82b2527d..0154c623 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Msg91.php +++ b/src/Utopia/Messaging/Adapters/SMS/Msg91.php @@ -55,7 +55,7 @@ protected function process(SMS $message): string 'otp' => $message->getContent(), 'flow_id' => $message->getFrom(), 'recipients' => [$to], - ]), + ]) ?: null, ); } } diff --git a/src/Utopia/Messaging/Adapters/SMS/Telnyx.php b/src/Utopia/Messaging/Adapters/SMS/Telnyx.php index 431736b5..3d72b5c3 100644 --- a/src/Utopia/Messaging/Adapters/SMS/Telnyx.php +++ b/src/Utopia/Messaging/Adapters/SMS/Telnyx.php @@ -43,7 +43,7 @@ protected function process(SMS $message): string 'text' => $message->getContent(), 'from' => $message->getFrom(), 'to' => $message->getTo()[0], - ]), + ]) ?: null, ); } } diff --git a/src/Utopia/Messaging/Adapters/SMS/TextMagic.php b/src/Utopia/Messaging/Adapters/SMS/TextMagic.php index 68fb4e37..d68d7b3b 100644 --- a/src/Utopia/Messaging/Adapters/SMS/TextMagic.php +++ b/src/Utopia/Messaging/Adapters/SMS/TextMagic.php @@ -51,7 +51,7 @@ protected function process(SMS $message): string ], body: \http_build_query([ 'text' => $message->getContent(), - 'from' => \ltrim($message->getFrom(), '+'), + 'from' => \ltrim($message->getFrom() ?? '', '+'), 'phones' => \implode(',', $to), ]), ); diff --git a/src/Utopia/Messaging/Message.php b/src/Utopia/Messaging/Message.php index 3b5e21ae..ba76eee5 100644 --- a/src/Utopia/Messaging/Message.php +++ b/src/Utopia/Messaging/Message.php @@ -7,4 +7,8 @@ */ interface Message { + /** + * @return array + */ + public function getTo(): array; } diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 21fedeea..8533eb39 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -7,11 +7,11 @@ class Email implements Message { /** - * @param array $to The recipients of the email. + * @param array $to The recipients of the email. * @param string $subject The subject of the email. * @param string $content The content of the email. * @param string|null $from The sender of the email. - * @param array|null $attachments The attachments of the email. + * @param array|null $attachments The attachments of the email. * @param bool $html Whether the message is HTML or not. */ public function __construct( @@ -25,48 +25,36 @@ public function __construct( } /** - * @return array + * @return array */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getSubject(): string { return $this->subject; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } /** - * @return array|null + * @return array|null */ public function getAttachments(): ?array { return $this->attachments; } - /** - * @return bool - */ public function isHtml(): bool { return $this->html; diff --git a/src/Utopia/Messaging/Messages/Push.php b/src/Utopia/Messaging/Messages/Push.php index d4a4333b..91ebdbd7 100644 --- a/src/Utopia/Messaging/Messages/Push.php +++ b/src/Utopia/Messaging/Messages/Push.php @@ -7,10 +7,10 @@ class Push implements Message { /** - * @param array $to The recipients of the push notification. + * @param array $to The recipients of the push notification. * @param string $title The title of the push notification. * @param string $body The body of the push notification. - * @param array|null $data This parameter specifies the custom key-value pairs of the message's payload. For example, with data:{"score":"3x1"}:

On Apple platforms, if the message is sent via APNs, it represents the custom data fields. If it is sent via FCM, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification:.

On Android, this would result in an intent extra named score with the string value 3x1.

The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse_key).

Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string. + * @param array|null $data This parameter specifies the custom key-value pairs of the message's payload. For example, with data:{"score":"3x1"}:

On Apple platforms, if the message is sent via APNs, it represents the custom data fields. If it is sent via FCM, it would be represented as key value dictionary in AppDelegate application:didReceiveRemoteNotification:.

On Android, this would result in an intent extra named score with the string value 3x1.

The key should not be a reserved word ("from", "message_type", or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse_key).

Values in string types are recommended. You have to convert values in objects or other non-string data types (e.g., integers or booleans) to string. * @param string|null $sound The sound to play when the device receives the notification.

On Android, sound files must reside in /res/raw/.

On iOS, sounds files must reside in the main bundle of the client app or in the Library/Sounds folder of the app's data container. * @param string|null $action The action associated with a user click on the notification.

On Android, this is the activity to launch.

On iOS, this is the category to launch. * @param string|null $icon Android only. The icon of the push notification. Sets the notification icon to myicon for drawable resource myicon. If you don't send this key in the request, FCM displays the launcher icon specified in your app manifest. @@ -33,80 +33,56 @@ public function __construct( } /** - * @return array + * @return array */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getTitle(): string { return $this->title; } - /** - * @return string - */ public function getBody(): string { return $this->body; } /** - * @return array|null + * @return array|null */ public function getData(): ?array { return $this->data; } - /** - * @return string|null - */ public function getAction(): ?string { return $this->action; } - /** - * @return string|null - */ public function getSound(): ?string { return $this->sound; } - /** - * @return string|null - */ public function getIcon(): ?string { return $this->icon; } - /** - * @return string|null - */ public function getColor(): ?string { return $this->color; } - /** - * @return string|null - */ public function getTag(): ?string { return $this->tag; } - /** - * @return string|null - */ public function getBadge(): ?string { return $this->badge; diff --git a/src/Utopia/Messaging/Messages/SMS.php b/src/Utopia/Messaging/Messages/SMS.php index bcb913c0..5e2f1023 100644 --- a/src/Utopia/Messaging/Messages/SMS.php +++ b/src/Utopia/Messaging/Messages/SMS.php @@ -6,6 +6,10 @@ class SMS implements Message { + /** + * @param array $to The recipients of the push notification. + * @param array $attachments The recipients of the push notification. + */ public function __construct( private array $to, private string $content, @@ -15,31 +19,25 @@ public function __construct( } /** - * @return array + * @return array */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } /** - * @return array|null + * @return array|null */ public function getAttachments(): ?array { diff --git a/tests/e2e/Base.php b/tests/e2e/Base.php index 14970e51..fb29fb05 100644 --- a/tests/e2e/Base.php +++ b/tests/e2e/Base.php @@ -6,21 +6,22 @@ class Base extends TestCase { - protected function getLastRequest(): array + /** + * @throws \Exception If the request fails. + */ + protected function getLastRequest(): mixed { \sleep(2); - - $request = \json_decode(\file_get_contents('http://request-catcher:5000/__last_request__'), true); + $request = \json_decode(\file_get_contents('http://request-catcher:5000/__last_request__') ?: '', true); $request['data'] = \json_decode($request['data'], true); return $request; } - protected function getLastEmail(): array + protected function getLastEmail(): mixed { sleep(3); - - $emails = \json_decode(\file_get_contents('http://maildev:1080/email'), true); + $emails = \json_decode(\file_get_contents('http://maildev:1080/email') ?: '', true); if ($emails && \is_array($emails)) { return \end($emails); diff --git a/tests/e2e/Email/EmailTest.php b/tests/e2e/Email/EmailTest.php index 40606255..186afa64 100644 --- a/tests/e2e/Email/EmailTest.php +++ b/tests/e2e/Email/EmailTest.php @@ -1,7 +1,8 @@