Skip to content

Commit 9baf902

Browse files
committed
Add missing types to method signatures
1 parent 57b35f9 commit 9baf902

File tree

7 files changed

+81
-92
lines changed

7 files changed

+81
-92
lines changed

src/Codeception/Constraint/JsonContains.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616

1717
class JsonContains extends Constraint
1818
{
19-
/**
20-
* @var array
21-
*/
22-
protected $expected;
23-
24-
public function __construct(array $expected)
19+
public function __construct(protected array $expected)
2520
{
26-
$this->expected = $expected;
2721
}
2822

2923
/**

src/Codeception/Constraint/JsonType.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,17 @@
1313

1414
class JsonType extends Constraint
1515
{
16-
/**
17-
* @var array
18-
*/
19-
protected $jsonType;
20-
/**
21-
* @var bool
22-
*/
23-
private $match;
24-
25-
public function __construct(array $jsonType, bool $match = true)
16+
public function __construct(
17+
protected array $jsonType,
18+
private bool $match = true)
2619
{
27-
$this->jsonType = $jsonType;
28-
$this->match = $match;
2920
}
3021

3122
/**
3223
* Evaluates the constraint for parameter $other. Returns true if the
3324
* constraint is met, false otherwise.
3425
*
35-
* @param mixed $jsonArray Value or object to evaluate.
26+
* @param array|JsonArray $jsonArray Value or object to evaluate.
3627
*/
3728
protected function matches($jsonArray): bool
3829
{

src/Codeception/Module/REST.php

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
use Codeception\Util\JsonArray;
2323
use Codeception\Util\JsonType;
2424
use Codeception\Util\Soap as XmlUtils;
25+
use Codeception\Util\XmlBuilder;
2526
use Codeception\Util\XmlStructure;
27+
use DOMDocument;
28+
use DOMNode;
2629
use Exception;
2730
use JsonException;
2831
use JsonSchema\Constraints\Constraint as JsonConstraint;
@@ -121,17 +124,13 @@ class REST extends Module implements DependsOnModule, PartedModule, API, Conflic
121124

122125
protected int $DEFAULT_SHORTEN_VALUE = 150;
123126

124-
/**
125-
* @var HttpKernelBrowser|AbstractBrowser
126-
*/
127-
public $client;
127+
public HttpKernelBrowser|AbstractBrowser|null $client;
128128

129129
public bool $isFunctional = false;
130130

131131
protected ?InnerBrowser $connectionModule = null;
132132

133-
/** @var array */
134-
public $params = [];
133+
public array|string|ArrayAccess|JsonSerializable $params = [];
135134

136135
public ?string $response = null;
137136

@@ -150,7 +149,7 @@ protected function resetVariables(): void
150149

151150
public function _conflicts(): string
152151
{
153-
return \Codeception\Lib\Interfaces\API::class;
152+
return API::class;
154153
}
155154

156155
public function _depends(): array
@@ -202,7 +201,7 @@ protected function getRunningClient(): AbstractBrowser
202201
}
203202

204203
/**
205-
* Sets a HTTP header to be used for all subsequent requests. Use [`deleteHeader`](#deleteHeader) to unset it.
204+
* Sets na HTTP header to be used for all subsequent requests. Use [`deleteHeader`](#deleteHeader) to unset it.
206205
*
207206
* ```php
208207
* <?php
@@ -219,7 +218,7 @@ public function haveHttpHeader(string $name, string $value): void
219218
}
220219

221220
/**
222-
* Deletes a HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)),
221+
* Deletes an HTTP header (that was originally added by [haveHttpHeader()](#haveHttpHeader)),
223222
* so that subsequent requests will not send it anymore.
224223
*
225224
* Example:
@@ -245,7 +244,6 @@ public function deleteHeader(string $name): void
245244
* Checks over the given HTTP header and (optionally)
246245
* its value, asserting that are there
247246
*
248-
* @param $value
249247
* @part json
250248
* @part xml
251249
*/
@@ -266,7 +264,6 @@ public function seeHttpHeader(string $name, $value = null): void
266264
* Checks over the given HTTP header and (optionally)
267265
* its value, asserting that are not there
268266
*
269-
* @param $value
270267
* @part json
271268
* @part xml
272269
*/
@@ -286,7 +283,7 @@ public function dontSeeHttpHeader(string $name, $value = null): void
286283
/**
287284
* Checks that http response header is received only once.
288285
* HTTP RFC2616 allows multiple response headers with the same name.
289-
* You can check that you didn't accidentally sent the same header twice.
286+
* You can check that you didn't accidentally send the same header twice.
290287
*
291288
* ``` php
292289
* <?php
@@ -306,7 +303,7 @@ public function seeHttpHeaderOnce(string $name): void
306303
* Returns the value of the specified header name
307304
*
308305
* @param bool $first Whether to return the first value or all header values
309-
* @return string|array The first header value if $first is true, an array of values otherwise
306+
* @return string|array|null The first header value if $first is true, an array of values otherwise
310307
* @part json
311308
* @part xml
312309
*/
@@ -386,7 +383,7 @@ public function amNTLMAuthenticated(string $username, string $password): void
386383
}
387384

388385
/**
389-
* Allows to send REST request using AWS Authorization
386+
* Allows sending REST request using AWS Authorization
390387
*
391388
* Only works with PhpBrowser
392389
* Example Config:
@@ -460,7 +457,6 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
460457
* ]]);
461458
* ```
462459
*
463-
* @param array|string|JsonSerializable $params
464460
* @param array $files A list of filenames or "mocks" of $_FILES (each entry being an array with the following
465461
* keys: name, type, error, size, tmp_name (pointing to the real file path). Each key works
466462
* as the "name" attribute of a file input field.
@@ -470,7 +466,10 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
470466
* @part json
471467
* @part xml
472468
*/
473-
public function sendPost(string $url, $params = [], array $files = [])
469+
public function sendPost(
470+
string $url,
471+
array|string|ArrayAccess|JsonSerializable $params = [],
472+
array $files = []): ?string
474473
{
475474
return $this->execute('POST', $url, $params, $files);
476475
}
@@ -481,7 +480,7 @@ public function sendPost(string $url, $params = [], array $files = [])
481480
* @part json
482481
* @part xml
483482
*/
484-
public function sendHead(string $url, array $params = [])
483+
public function sendHead(string $url, array $params = []): ?string
485484
{
486485
return $this->execute('HEAD', $url, $params);
487486
}
@@ -511,7 +510,7 @@ public function sendOptions(string $url, array $params = []): void
511510
* @part json
512511
* @part xml
513512
*/
514-
public function sendGet(string $url, array $params = [])
513+
public function sendGet(string $url, array $params = []): ?string
515514
{
516515
return $this->execute('GET', $url, $params);
517516
}
@@ -524,11 +523,14 @@ public function sendGet(string $url, array $params = [])
524523
* $response = $I->sendPut('/message/1', ['subject' => 'Read this!']);
525524
* ```
526525
*
527-
* @param array|string|JsonSerializable $params
528526
* @part json
529527
* @part xml
530528
*/
531-
public function sendPut(string $url, $params = [], array $files = [])
529+
public function sendPut(
530+
string $url,
531+
array|string|ArrayAccess|JsonSerializable $params = [],
532+
array $files = []
533+
): ?string
532534
{
533535
return $this->execute('PUT', $url, $params, $files);
534536
}
@@ -541,11 +543,14 @@ public function sendPut(string $url, $params = [], array $files = [])
541543
* $response = $I->sendPatch('/message/1', ['subject' => 'Read this!']);
542544
* ```
543545
*
544-
* @param array|string|JsonSerializable $params
545546
* @part json
546547
* @part xml
547548
*/
548-
public function sendPatch(string $url, $params = [], array $files = [])
549+
public function sendPatch(
550+
string $url,
551+
array|string|ArrayAccess|JsonSerializable $params = [],
552+
array $files = []
553+
): ?string
549554
{
550555
return $this->execute('PATCH', $url, $params, $files);
551556
}
@@ -561,19 +566,26 @@ public function sendPatch(string $url, $params = [], array $files = [])
561566
* @part json
562567
* @part xml
563568
*/
564-
public function sendDelete(string $url, array $params = [], array $files = [])
569+
public function sendDelete(
570+
string $url,
571+
array|string|ArrayAccess|JsonSerializable $params = [],
572+
array $files = []
573+
): ?string
565574
{
566575
return $this->execute('DELETE', $url, $params, $files);
567576
}
568577

569578
/**
570579
* Sends a HTTP request.
571580
*
572-
* @param array|string|JsonSerializable $params
573581
* @part json
574582
* @part xml
575583
*/
576-
public function send(string $method, string $url, $params = [], array $files = [])
584+
public function send(
585+
string $method,
586+
string $url,
587+
array|string|ArrayAccess|JsonSerializable $params = [],
588+
array $files = []): ?string
577589
{
578590
return $this->execute(strtoupper($method), $url, $params, $files);
579591
}
@@ -640,13 +652,13 @@ public function sendUnlink(string $url, array $linkEntries): void
640652
}
641653

642654
/**
643-
* @param $method
644-
* @param $url
645-
* @param array|string|object $parameters
646-
* @param array $files
647655
* @throws ModuleException|ExternalUrlException|JsonException
648656
*/
649-
protected function execute($method, $url, $parameters = [], $files = [])
657+
protected function execute(
658+
string $method,
659+
string $url,
660+
array|string|ArrayAccess|JsonSerializable $parameters = [],
661+
array $files = []): ?string
650662
{
651663
// allow full url to be requested
652664
if (!$url) {
@@ -692,6 +704,9 @@ protected function execute($method, $url, $parameters = [], $files = [])
692704

693705
$this->response = $this->connectionModule->_request($method, $url, $parameters, $files);
694706
} else {
707+
/**
708+
* @var string $parameters
709+
*/
695710
$requestData = $parameters;
696711
if ($this->isBinaryData($requestData)) {
697712
$requestData = $this->binaryToDebugString($requestData);
@@ -739,7 +754,10 @@ protected function binaryToDebugString(string $data): string
739754
return '[binary-data length:' . strlen($data) . ' md5:' . md5($data) . ']';
740755
}
741756

742-
protected function encodeApplicationJson(string $method, $parameters)
757+
protected function encodeApplicationJson(
758+
string $method,
759+
array|string|ArrayAccess|JsonSerializable $parameters,
760+
): array|string
743761
{
744762
if (
745763
array_key_exists('Content-Type', $this->connectionModule->headers)
@@ -901,15 +919,15 @@ public function dontSeeResponseContains(string $text): void
901919
*
902920
* ``` php
903921
* <?php
904-
* // response: {name: john, email: [email protected]}
905-
* $I->seeResponseContainsJson(array('name' => 'john'));
922+
* // response: {"name": "john", "email": "[email protected]"}
923+
* $I->seeResponseContainsJson(['name' => 'john']);
906924
*
907-
* // response {user: john, profile: { email: [email protected] }}
908-
* $I->seeResponseContainsJson(array('email' => '[email protected]'));
925+
* // response {"user": "john", "profile": {"email": "[email protected]"}}
926+
* $I->seeResponseContainsJson(['email' => '[email protected]']);
909927
*
910928
* ```
911929
*
912-
* This method recursively checks if one array can be found inside of another.
930+
* This method recursively checks if one array can be found inside another.
913931
*
914932
* @part json
915933
*/
@@ -1313,13 +1331,13 @@ public function dontSeeResponseContainsJson(array $json = []): void
13131331
*
13141332
* ```php
13151333
* <?php
1316-
* // {'user_id': 1, 'email' => '[email protected]'}
1334+
* // {"user_id": 1, "email" => "[email protected]"}
13171335
* $I->seeResponseMatchesJsonType([
13181336
* 'user_id' => 'string:>0:<1000', // multiple filters can be used
13191337
* 'email' => 'string:regex(~\@~)' // we just check that @ char is included
13201338
* ]);
13211339
*
1322-
* // {'user_id': '1'}
1340+
* // {"user_id"'": "1"}
13231341
* $I->seeResponseMatchesJsonType([
13241342
* 'user_id' => 'string:>0', // works with strings as well
13251343
* ]);
@@ -1513,10 +1531,9 @@ public function dontSeeXmlResponseMatchesXpath(string $xPath): void
15131531
* Finds and returns text contents of element.
15141532
* Element is matched by either CSS or XPath
15151533
*
1516-
* @param mixed $cssOrXPath
15171534
* @part xml
15181535
*/
1519-
public function grabTextContentFromXmlElement($cssOrXPath): string
1536+
public function grabTextContentFromXmlElement(string $cssOrXPath): string
15201537
{
15211538
$el = (new XmlStructure($this->connectionModule->_getResponseContent()))->matchElement($cssOrXPath);
15221539
return $el->textContent;
@@ -1542,12 +1559,9 @@ public function grabAttributeFromXmlElement(string $cssOrXPath, string $attribut
15421559
* Checks XML response equals provided XML.
15431560
* Comparison is done by canonicalizing both xml`s.
15441561
*
1545-
* Parameters can be passed either as DOMDocument, DOMNode, XML string, or array (if no attributes).
1546-
*
1547-
* @param mixed $xml
15481562
* @part xml
15491563
*/
1550-
public function seeXmlResponseEquals($xml): void
1564+
public function seeXmlResponseEquals(DOMDocument|string $xml): void
15511565
{
15521566
Assert::assertXmlStringEqualsXmlString($this->connectionModule->_getResponseContent(), $xml);
15531567
}
@@ -1557,12 +1571,10 @@ public function seeXmlResponseEquals($xml): void
15571571
* Checks XML response does not equal to provided XML.
15581572
* Comparison is done by canonicalizing both xml`s.
15591573
*
1560-
* Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
1561-
*
15621574
* @param mixed $xml
15631575
* @part xml
15641576
*/
1565-
public function dontSeeXmlResponseEquals($xml): void
1577+
public function dontSeeXmlResponseEquals(DOMDocument|string $xml): void
15661578
{
15671579
Assert::assertXmlStringNotEqualsXmlString(
15681580
$this->connectionModule->_getResponseContent(),
@@ -1582,10 +1594,9 @@ public function dontSeeXmlResponseEquals($xml): void
15821594
* $I->seeXmlResponseIncludes("<result>1</result>");
15831595
* ```
15841596
*
1585-
* @param mixed $xml
15861597
* @part xml
15871598
*/
1588-
public function seeXmlResponseIncludes($xml): void
1599+
public function seeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): void
15891600
{
15901601
$this->assertStringContainsString(
15911602
XmlUtils::toXml($xml)->C14N(),
@@ -1599,10 +1610,9 @@ public function seeXmlResponseIncludes($xml): void
15991610
* Comparison is done by canonicalizing both xml`s.
16001611
* Parameter can be passed either as XmlBuilder, DOMDocument, DOMNode, XML string, or array (if no attributes).
16011612
*
1602-
* @param mixed $xml
16031613
* @part xml
16041614
*/
1605-
public function dontSeeXmlResponseIncludes($xml): void
1615+
public function dontSeeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml): void
16061616
{
16071617
$this->assertStringNotContainsString(
16081618
XmlUtils::toXml($xml)->C14N(),

0 commit comments

Comments
 (0)