Skip to content

Commit

Permalink
Use strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Oct 5, 2024
1 parent 3d325fd commit a475754
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion castor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
use Castor\Attribute\{AsContext, AsTask};
use Castor\Context;
use function Castor\{exit_code, finder, fs, run, variable};
Expand Down
2 changes: 1 addition & 1 deletion example/send_message.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
use freemobile\Client;

// Sends an SMS notification.
Expand Down
7 changes: 4 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace freemobile;
<?php declare(strict_types=1);
namespace freemobile;

use Nyholm\Psr7\{Response, Uri};
use Psr\Http\Message\UriInterface;
Expand Down Expand Up @@ -32,7 +33,7 @@
function __construct(string $account, string $apiKey, string|UriInterface $baseUrl = "https://smsapi.free-mobile.fr") {
$this->account = $account;
$this->apiKey = $apiKey;
$this->baseUrl = new Uri(rtrim($baseUrl, "/"));
$this->baseUrl = new Uri(rtrim((string) $baseUrl, "/"));
}

/**
Expand All @@ -42,7 +43,7 @@ function __construct(string $account, string $apiKey, string|UriInterface $baseU
*/
function sendMessage(string $text): void {
$query = ["msg" => mb_substr(trim($text), 0, 160), "pass" => $this->apiKey, "user" => $this->account];
$handle = curl_init($this->baseUrl
$handle = curl_init((string) $this->baseUrl
->withPath("{$this->baseUrl->getPath()}/sendmsg")
->withQuery(http_build_query($query, arg_separator: "&", encoding_type: PHP_QUERY_RFC3986)));

Expand Down
17 changes: 12 additions & 5 deletions test/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php namespace freemobile;
<?php declare(strict_types=1);
namespace freemobile;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\{Assert, TestCase};
use PHPUnit\Framework\Attributes\{Test, TestDox};
use function PHPUnit\Framework\{assertThat, isNull};
use function PHPUnit\Framework\{assertThat, isTrue};

/**
* Tests the features of the {@see Client} class.
Expand All @@ -26,7 +27,13 @@ function invalidCredentials(): void {

#[Test, TestDox("sendMessage(): should send SMS messages if the credentials are valid.")]
function validCredentials(): void {
$client = new Client(getenv("FREEMOBILE_ACCOUNT") ?: "", getenv("FREEMOBILE_API_KEY") ?: "");
assertThat($client->sendMessage("Hello Cédric, from PHP!"), isNull()); // @phpstan-ignore method.void
try {
$client = new Client(getenv("FREEMOBILE_ACCOUNT") ?: "", getenv("FREEMOBILE_API_KEY") ?: "");
$client->sendMessage("Hello Cédric, from PHP!");
assertThat(true, isTrue());
}
catch (\RuntimeException $e) {
Assert::fail($e->getMessage());
}
}
}

0 comments on commit a475754

Please sign in to comment.