Skip to content

Commit 9bb73d2

Browse files
committed
Improve code style
1 parent 9baf902 commit 9bb73d2

File tree

17 files changed

+346
-174
lines changed

17 files changed

+346
-174
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ name: CI
33
on: [push, pull_request]
44

55
jobs:
6+
phpcs:
7+
name: Code style
8+
runs-on: 'ubuntu-latest'
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
13+
- name: Install PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: '8.1'
17+
ini-values: memory_limit=-1, date.timezone='UTC'
18+
tools: phpcs
19+
20+
- name: Check production code style
21+
run: phpcs src/
22+
23+
- name: Check test code style
24+
run: phpcs tests/ --standard=tests/phpcs.xml
625
tests:
726
runs-on: ubuntu-latest
827

@@ -11,7 +30,7 @@ jobs:
1130

1231
strategy:
1332
matrix:
14-
php: [8.0, 8.1]
33+
php: [8.0, 8.1, 8.2]
1534

1635
steps:
1736
- name: Checkout code

phpcs.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Codeception">
3+
<description>Codeception code standard</description>
4+
<rule ref="PSR12">
5+
<exclude name="Generic.Files.LineLength.TooLong"/>
6+
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
7+
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
8+
</rule>
9+
</ruleset>

src/Codeception/Constraint/JsonType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class JsonType extends Constraint
1515
{
1616
public function __construct(
1717
protected array $jsonType,
18-
private bool $match = true)
19-
{
18+
private bool $match = true
19+
) {
2020
}
2121

2222
/**

src/Codeception/Module/REST.php

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
* ## Conflicts
9393
*
9494
* Conflicts with SOAP module
95-
*
9695
*/
9796
class REST extends Module implements DependsOnModule, PartedModule, API, ConflictsWithModule
9897
{
@@ -232,8 +231,8 @@ public function haveHttpHeader(string $name, string $value): void
232231
* ```
233232
*
234233
* @param string $name the name of the header to delete.
235-
* @part json
236-
* @part xml
234+
* @part json
235+
* @part xml
237236
*/
238237
public function deleteHeader(string $name): void
239238
{
@@ -302,10 +301,10 @@ public function seeHttpHeaderOnce(string $name): void
302301
/**
303302
* Returns the value of the specified header name
304303
*
305-
* @param bool $first Whether to return the first value or all header values
304+
* @param bool $first Whether to return the first value or all header values
306305
* @return string|array|null The first header value if $first is true, an array of values otherwise
307-
* @part json
308-
* @part xml
306+
* @part json
307+
* @part xml
309308
*/
310309
public function grabHttpHeader(string $name, bool $first = true): string|array|null
311310
{
@@ -366,8 +365,8 @@ public function amBearerAuthenticated(string $accessToken): void
366365
* ```
367366
*
368367
* @throws ModuleException
369-
* @part json
370-
* @part xml
368+
* @part json
369+
* @part xml
371370
*/
372371
public function amNTLMAuthenticated(string $username, string $password): void
373372
{
@@ -402,6 +401,7 @@ public function amNTLMAuthenticated(string $username, string $password): void
402401
* <?php
403402
* $I->amAWSAuthenticated();
404403
* ```
404+
*
405405
* @throws ConfigurationException
406406
*/
407407
public function amAWSAuthenticated(array $additionalAWSConfig = []): void
@@ -461,16 +461,16 @@ public function amAWSAuthenticated(array $additionalAWSConfig = []): void
461461
* keys: name, type, error, size, tmp_name (pointing to the real file path). Each key works
462462
* as the "name" attribute of a file input field.
463463
*
464-
* @see https://php.net/manual/en/features.file-upload.post-method.php
465-
* @see codecept_data_dir()
464+
* @see https://php.net/manual/en/features.file-upload.post-method.php
465+
* @see codecept_data_dir()
466466
* @part json
467467
* @part xml
468468
*/
469469
public function sendPost(
470470
string $url,
471471
array|string|ArrayAccess|JsonSerializable $params = [],
472-
array $files = []): ?string
473-
{
472+
array $files = []
473+
): ?string {
474474
return $this->execute('POST', $url, $params, $files);
475475
}
476476

@@ -530,8 +530,7 @@ public function sendPut(
530530
string $url,
531531
array|string|ArrayAccess|JsonSerializable $params = [],
532532
array $files = []
533-
): ?string
534-
{
533+
): ?string {
535534
return $this->execute('PUT', $url, $params, $files);
536535
}
537536

@@ -550,8 +549,7 @@ public function sendPatch(
550549
string $url,
551550
array|string|ArrayAccess|JsonSerializable $params = [],
552551
array $files = []
553-
): ?string
554-
{
552+
): ?string {
555553
return $this->execute('PATCH', $url, $params, $files);
556554
}
557555

@@ -570,8 +568,7 @@ public function sendDelete(
570568
string $url,
571569
array|string|ArrayAccess|JsonSerializable $params = [],
572570
array $files = []
573-
): ?string
574-
{
571+
): ?string {
575572
return $this->execute('DELETE', $url, $params, $files);
576573
}
577574

@@ -585,8 +582,8 @@ public function send(
585582
string $method,
586583
string $url,
587584
array|string|ArrayAccess|JsonSerializable $params = [],
588-
array $files = []): ?string
589-
{
585+
array $files = []
586+
): ?string {
590587
return $this->execute(strtoupper($method), $url, $params, $files);
591588
}
592589

@@ -627,8 +624,8 @@ private function setHeaderLink(array $linkEntries): void
627624
* @link https://tools.ietf.org/html/rfc2068#section-19.6.2.4
628625
*
629626
630-
* @part json
631-
* @part xml
627+
* @part json
628+
* @part xml
632629
*/
633630
public function sendLink(string $url, array $linkEntries): void
634631
{
@@ -639,11 +636,11 @@ public function sendLink(string $url, array $linkEntries): void
639636
/**
640637
* Sends UNLINK request to given uri.
641638
*
642-
* @param array $linkEntries (entry is array with keys "uri" and "link-param")
643-
* @link https://tools.ietf.org/html/rfc2068#section-19.6.2.4
639+
* @param array $linkEntries (entry is array with keys "uri" and "link-param")
640+
* @link https://tools.ietf.org/html/rfc2068#section-19.6.2.4
644641
645-
* @part json
646-
* @part xml
642+
* @part json
643+
* @part xml
647644
*/
648645
public function sendUnlink(string $url, array $linkEntries): void
649646
{
@@ -658,8 +655,8 @@ protected function execute(
658655
string $method,
659656
string $url,
660657
array|string|ArrayAccess|JsonSerializable $parameters = [],
661-
array $files = []): ?string
662-
{
658+
array $files = []
659+
): ?string {
663660
// allow full url to be requested
664661
if (!$url) {
665662
$url = $this->config['url'];
@@ -696,7 +693,8 @@ protected function execute(
696693
$this->debugSection("Request", sprintf('%s %s', $method, $url));
697694
$files = [];
698695
} else {
699-
$this->debugSection("Request",
696+
$this->debugSection(
697+
"Request",
700698
sprintf('%s %s ', $method, $url) . json_encode($parameters, JSON_PRESERVE_ZERO_FRACTION | JSON_THROW_ON_ERROR)
701699
);
702700
$files = $this->formatFilesArray($files);
@@ -746,7 +744,7 @@ protected function isBinaryData(string $data): bool
746744
/**
747745
* Format a binary string for debug printing
748746
*
749-
* @param string $data the binary data string
747+
* @param string $data the binary data string
750748
* @return string the debug string
751749
*/
752750
protected function binaryToDebugString(string $data): string
@@ -757,13 +755,11 @@ protected function binaryToDebugString(string $data): string
757755
protected function encodeApplicationJson(
758756
string $method,
759757
array|string|ArrayAccess|JsonSerializable $parameters,
760-
): array|string
761-
{
758+
): array|string {
762759
if (
763760
array_key_exists('Content-Type', $this->connectionModule->headers)
764761
&& ($this->connectionModule->headers['Content-Type'] === 'application/json'
765-
|| preg_match('#^application/.+\+json$#', $this->connectionModule->headers['Content-Type'])
766-
)
762+
|| preg_match('#^application/.+\+json$#', $this->connectionModule->headers['Content-Type']))
767763
) {
768764
if ($parameters instanceof JsonSerializable) {
769765
return json_encode($parameters, JSON_PRESERVE_ZERO_FRACTION | JSON_THROW_ON_ERROR);
@@ -825,6 +821,7 @@ private function formatFilesArray(array $files): array
825821
} elseif (is_object($value)) {
826822
/**
827823
* do nothing, probably the user knows what he is doing
824+
*
828825
* @issue https://github.com/Codeception/Codeception/issues/3298
829826
*/
830827
} else {
@@ -861,7 +858,6 @@ private function checkFileBeforeUpload(string $file): void
861858

862859
/**
863860
* Extends the function Module::validateConfig for shorten messages
864-
*
865861
*/
866862
protected function validateConfig(): void
867863
{
@@ -995,7 +991,7 @@ public function seeResponseIsValidOnJsonSchemaString(string $schema): void
995991
* Supply schema as relative file path in your project directory or an absolute path
996992
*
997993
* @part json
998-
* @see codecept_absolute_path()
994+
* @see codecept_absolute_path()
999995
*/
1000996
public function seeResponseIsValidOnJsonSchema(string $schemaFilename): void
1001997
{
@@ -1010,7 +1006,7 @@ public function seeResponseIsValidOnJsonSchema(string $schemaFilename): void
10101006
/**
10111007
* Converts string to json and asserts that no error occurred while decoding.
10121008
*
1013-
* @param string $jsonString the json encoded string
1009+
* @param string $jsonString the json encoded string
10141010
* @param string $errorFormat optional string for custom sprintf format
10151011
*/
10161012
protected function decodeAndValidateJson(string $jsonString, string $errorFormat = "Invalid json: %s. System message: %s.")
@@ -1063,7 +1059,7 @@ public function grabResponse(): string
10631059
*
10641060
* @return array Array of matching items
10651061
* @throws Exception
1066-
* @part json
1062+
* @part json
10671063
*/
10681064
public function grabDataFromResponseByJsonPath(string $jsonPath): array
10691065
{
@@ -1106,6 +1102,7 @@ public function grabDataFromResponseByJsonPath(string $jsonPath): array
11061102
* // at least one item in store has price
11071103
* $I->seeResponseJsonMatchesXpath('/store//price');
11081104
* ```
1105+
*
11091106
* @part json
11101107
*/
11111108
public function seeResponseJsonMatchesXpath(string $xPath): void
@@ -1152,6 +1149,7 @@ public function seeResponseJsonMatchesXpath(string $xPath): void
11521149
* // count the number of books written by given author is 5
11531150
* $I->seeResponseJsonMatchesXpath("//author[text() = 'Nigel Rees']", 1.0);
11541151
* ```
1152+
*
11551153
* @part json
11561154
*/
11571155
public function seeResponseJsonXpathEvaluatesTo(string $xPath, $expected): void
@@ -1163,7 +1161,7 @@ public function seeResponseJsonXpathEvaluatesTo(string $xPath, $expected): void
11631161
"Received JSON did not evualated XPath `{$xPath}` as expected.\nJson Response: \n" . $response
11641162
);
11651163
}
1166-
1164+
11671165
/**
11681166
* Opposite to seeResponseJsonXpathEvaluatesTo
11691167
*
@@ -1347,7 +1345,7 @@ public function dontSeeResponseContainsJson(array $json = []): void
13471345
* See [JsonType reference](https://codeception.com/docs/reference/JsonType).
13481346
*
13491347
* @part json
1350-
* @see JsonType
1348+
* @see JsonType
13511349
*/
13521350
public function seeResponseMatchesJsonType(array $jsonType, string $jsonPath = null): void
13531351
{
@@ -1362,9 +1360,9 @@ public function seeResponseMatchesJsonType(array $jsonType, string $jsonPath = n
13621360
/**
13631361
* Opposite to `seeResponseMatchesJsonType`.
13641362
*
1365-
* @part json
1363+
* @part json
13661364
* @param array $jsonType JsonType structure
1367-
* @see seeResponseMatchesJsonType
1365+
* @see seeResponseMatchesJsonType
13681366
*/
13691367
public function dontSeeResponseMatchesJsonType(array $jsonType, string $jsonPath = null): void
13701368
{
@@ -1504,6 +1502,7 @@ public function seeResponseIsXml(): void
15041502
* <?php
15051503
* $I->seeXmlResponseMatchesXpath('//root/user[@id=1]');
15061504
* ```
1505+
*
15071506
* @part xml
15081507
*/
15091508
public function seeXmlResponseMatchesXpath(string $xPath): void
@@ -1519,6 +1518,7 @@ public function seeXmlResponseMatchesXpath(string $xPath): void
15191518
* <?php
15201519
* $I->dontSeeXmlResponseMatchesXpath('//root/user[@id=1]');
15211520
* ```
1521+
*
15221522
* @part xml
15231523
*/
15241524
public function dontSeeXmlResponseMatchesXpath(string $xPath): void
@@ -1572,7 +1572,7 @@ public function seeXmlResponseEquals(DOMDocument|string $xml): void
15721572
* Comparison is done by canonicalizing both xml`s.
15731573
*
15741574
* @param mixed $xml
1575-
* @part xml
1575+
* @part xml
15761576
*/
15771577
public function dontSeeXmlResponseEquals(DOMDocument|string $xml): void
15781578
{
@@ -1650,8 +1650,8 @@ public function dontSeeXmlResponseIncludes(DOMNode|XmlBuilder|array|string $xml)
16501650
*
16511651
* @param string $hash the hashed data response expected
16521652
* @param string $algo the hash algorithm to use. Default sha1.
1653-
* @part json
1654-
* @part xml
1653+
* @part json
1654+
* @part xml
16551655
*/
16561656
public function seeBinaryResponseEquals(string $hash, string $algo = 'sha1'): void
16571657
{
@@ -1670,8 +1670,8 @@ public function seeBinaryResponseEquals(string $hash, string $algo = 'sha1'): vo
16701670
*
16711671
* @param string $hash the hashed data response expected
16721672
* @param string $algo the hash algorithm to use. Default md5.
1673-
* @part json
1674-
* @part xml
1673+
* @part json
1674+
* @part xml
16751675
*/
16761676
public function dontSeeBinaryResponseEquals(string $hash, string $algo = 'sha1'): void
16771677
{

src/Codeception/Step/AsJson.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public static function getTemplate(Template $template): ?Template
2525
$action = $template->getVar('action');
2626

2727
// should only be applied to send* methods
28-
if (!str_starts_with($action, 'send')) return null;
28+
if (!str_starts_with($action, 'send')) {
29+
return null;
30+
}
2931

3032
$conditionalDoc = "* JSON response will be automatically decoded \n " . $template->getVar('doc');
3133

src/Codeception/Util/ArrayContainsComparator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function containsArray(array $needle): bool
3434
/**
3535
3636
37-
* @link https://www.php.net/manual/en/function.array-intersect-assoc.php#39822
37+
* @link https://www.php.net/manual/en/function.array-intersect-assoc.php#39822
3838
*/
3939
private function arrayIntersectRecursive(mixed $arr1, mixed $arr2): bool|array|null
4040
{

0 commit comments

Comments
 (0)