Skip to content

Commit c7767a3

Browse files
authored
Merge pull request msyk#100 from msyk/mod20240911
Modified types and so on, with PHPStan
2 parents b95b0b5 + df02200 commit c7767a3

9 files changed

Lines changed: 476 additions & 470 deletions

composer.lock

Lines changed: 80 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/FMDataAPI_Sample.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
// Instantiate the class FMDataAPI with database name, user name, password and host.
2020
// Although the port number and protocol can be set in parameters of constructor,
2121
// these parameters can be omitted with default values.
22-
$fmdb = new FMDataAPI("TestDB", "web", "password", "localhost");
22+
$fmdb = new FMDataAPI("TestDB", "web", null, "localhost");
2323

2424
//==============================
25-
//$fmdb = new FMDataAPI("TestDB", "web", "password", "localserver");
25+
//$fmdb = new FMDataAPI("TestDB", "web", null, "localserver");
2626
// "localserver" is added on Ver.2 and it's a magic term for FMDataAPI. It happens direct connect to
2727
// FileMaker Server in the same host. I've refered Atsushi Matsuo's script below and I got his way
2828
// to be able to connect port number 3000.

src/FMDataAPI.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FMDataAPI
3030
* @var FileMakerLayout[] Keeping the FileMakerLayout object for each layout.
3131
* @ignore
3232
*/
33-
private $layoutTable = [];
33+
private array $layoutTable = [];
3434

3535
/**
3636
* @var null|CommunicationProvider Keeping the CommunicationProvider object.
@@ -45,22 +45,29 @@ class FMDataAPI
4545
* Every database must have the accessing privilege 'fmrest' including external data sources.
4646
* @param string $user The fmrest privilege accessible user to the database.
4747
* If you’re going to call useOAuth method, you have to specify the data for X-FM-Data-OAuth-Request-Id.
48-
* @param string $password The password of the above user.
48+
* @param string|null $password The password of the above user.
4949
* If you’re going to call useOAuth method, you have to specify the data for X-FM-Data-OAuth-Identifier.
50-
* @param ?string $host FileMaker Server's host name or IP address. If omitted, 'localhost' is chosen.
50+
* @param string|null $host FileMaker Server's host name or IP address. If omitted, 'localhost' is chosen.
5151
* The value "localserver" tries to connect directory 127.0.0.1, and you don't have to set $port and $protocol.
52-
* @param int $port FileMaker Server's port number. If omitted, 443 is chosen.
53-
* @param string $protocol FileMaker Server's protocol name. If omitted, 'https' is chosen.
54-
* @param array $fmDataSource Authentication information for external data sources.
55-
* Ex. [{"database"=>"<databaseName>", "username"=>"<username>", "password"=>"<password>"].
52+
* @param int|null $port FileMaker Server's port number. If omitted, 443 is chosen.
53+
* @param string|null $protocol FileMaker Server's protocol name. If omitted, 'https' is chosen.
54+
* @param array|null $fmDataSource Authentication information for external data sources.
55+
* Ex. [{"database"=>"<databaseName>", "username"=>"<username>", "password"=>"<password>"}].
5656
* If you use OAuth, "oAuthRequestId" and "oAuthIdentifier" keys have to be spedified.
5757
* @param boolean $isUnitTest If it's set to true, the communication provider just works locally.
5858
*/
59-
public function __construct(
60-
string $solution, string $user, string $password,
61-
?string $host = null, ?int $port = null, ?string $protocol = null,
62-
?array $fmDataSource = null, bool $isUnitTest = false)
59+
public function __construct(string $solution,
60+
string $user,
61+
string|null $password,
62+
string|null $host = null,
63+
int|null $port = null,
64+
string|null $protocol = null,
65+
array|null $fmDataSource = null,
66+
bool $isUnitTest = false)
6367
{
68+
if (is_null($password)) {
69+
$password = "password"; // For testing purpose.
70+
}
6471
if (!$isUnitTest) {
6572
$this->provider = new Supporting\CommunicationProvider($solution, $user, $password, $host, $port, $protocol, $fmDataSource);
6673
} else {
@@ -75,7 +82,8 @@ public function __construct(
7582
* @throws Exception
7683
* @ignore
7784
*/
78-
public function __set(string $key, mixed $value): void
85+
public function __set(string $key,
86+
mixed $value): void
7987
{
8088
throw new Exception("The $key property is read-only, and can't set any value.");
8189
}
@@ -158,7 +166,7 @@ public function setCertValidating(bool $value): void
158166
* If this property is set to true,
159167
* FileMakerRelation class's field method (including describing field name directly) returns the value processed
160168
* with the htmlspecialchars.
161-
* This means kind of compatible mode of FileMaker API for PHP.
169+
* This means kind of compatible mode to FileMaker API for PHP.
162170
* This feature works whole the FMDataAPI library.
163171
* @param bool $value Turn on to verify the certificate if the value is true.
164172
*/
@@ -205,7 +213,7 @@ public function curlErrorCode(): int
205213

206214
/**
207215
* The error message of curl, text representation of code.
208-
* @return string The error message of curl.
216+
* @return string|null The error message of curl.
209217
*/
210218
public function curlErrorMessage(): null|string
211219
{
@@ -214,9 +222,9 @@ public function curlErrorMessage(): null|string
214222

215223
/**
216224
* The HTTP status code of the latest response from the REST API.
217-
* @return int The HTTP status code.
225+
* @return int|null The HTTP status code.
218226
*/
219-
public function httpStatus(): null|int
227+
public function httpStatus(): int|null
220228
{
221229
return $this->provider->httpStatus;
222230
}
@@ -235,9 +243,9 @@ public function errorCode(): int
235243
/**
236244
* The error message of the latest response from the REST API.
237245
* This error message is associated with FileMaker's error code.
238-
* @return string The error message.
246+
* @return string|null The error message.
239247
*/
240-
public function errorMessage(): null|string
248+
public function errorMessage(): string|null
241249
{
242250
return $this->provider->errorMessage;
243251
}
@@ -294,7 +302,7 @@ public function setGlobalField(array $fields): void
294302
$headers = ["Content-Type" => "application/json"];
295303
$params = ["globals" => null];
296304
$request = ["globalFields" => $fields];
297-
$this->provider->callRestAPI($params, true, "PATCH", $request, $headers);
305+
$this->provider->callRestAPI($params, true, "PATCH", $request, $headers); // Throw Exception
298306
$this->provider->storeToProperties();
299307
$this->provider->logout();
300308
}

0 commit comments

Comments
 (0)