Skip to content

Commit e6fbf6f

Browse files
committed
chore(cs): use php-cs-fixer with PER2.0 standard
1 parent 729e04d commit e6fbf6f

File tree

6 files changed

+52
-44
lines changed

6 files changed

+52
-44
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"codeception/module-asserts": ">= 3.0",
3131
"codeception/module-filesystem": "> 3.0",
3232
"phpstan/phpstan": "^2",
33-
"rector/rector": "^2"
33+
"rector/rector": "^2",
34+
"friendsofphp/php-cs-fixer": "^3.70"
3435
},
3536
"autoload":{
3637
"classmap": ["src/"]

src/Codeception/Lib/Connector/Yii2.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,40 @@
3232
use yii\web\Response as YiiResponse;
3333
use yii\web\User;
3434

35-
3635
/**
3736
* @extends Client<BrowserkitRequest, Response>
3837
*/
3938
class Yii2 extends Client
4039
{
4140
use Shared\PhpSuperGlobalsConverter;
4241

43-
const CLEAN_METHODS = [
42+
public const CLEAN_METHODS = [
4443
self::CLEAN_RECREATE,
4544
self::CLEAN_CLEAR,
4645
self::CLEAN_FORCE_RECREATE,
47-
self::CLEAN_MANUAL
46+
self::CLEAN_MANUAL,
4847
];
4948
/**
5049
* Clean the response object by recreating it.
5150
* This might lose behaviors / event handlers / other changes that are done in the application bootstrap phase.
5251
*/
53-
const CLEAN_RECREATE = 'recreate';
52+
public const CLEAN_RECREATE = 'recreate';
5453
/**
5554
* Same as recreate but will not warn when behaviors / event handlers are lost.
5655
*/
57-
const CLEAN_FORCE_RECREATE = 'force_recreate';
56+
public const CLEAN_FORCE_RECREATE = 'force_recreate';
5857
/**
5958
* Clean the response object by resetting specific properties via its' `clear()` method.
6059
* This will keep behaviors / event handlers, but could inadvertently leave some changes intact.
6160
* @see \yii\web\Response::clear()
6261
*/
63-
const CLEAN_CLEAR = 'clear';
62+
public const CLEAN_CLEAR = 'clear';
6463

6564
/**
6665
* Do not clean the response, instead the test writer will be responsible for manually resetting the response in
6766
* between requests during one test
6867
*/
69-
const CLEAN_MANUAL = 'manual';
68+
public const CLEAN_MANUAL = 'manual';
7069

7170

7271
/**
@@ -257,7 +256,7 @@ function ($matches) use (&$parameters): string {
257256
$parameters[$key] = $matches[1] ?? '\w+';
258257
return $key;
259258
},
260-
$template
259+
$template,
261260
);
262261
}
263262
if ($template === null) {
@@ -327,7 +326,7 @@ public function doRequest(object $request): Response
327326
$queryString = parse_url($uri, PHP_URL_QUERY);
328327
$_SERVER['REQUEST_URI'] = $queryString === null ? $pathString : $pathString . '?' . $queryString;
329328
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
330-
$_SERVER['QUERY_STRING'] = (string)$queryString;
329+
$_SERVER['QUERY_STRING'] = (string) $queryString;
331330

332331
parse_str($queryString ?: '', $params);
333332
foreach ($params as $k => $v) {
@@ -403,7 +402,7 @@ public function doRequest(object $request): Response
403402
protected function encodeCookies(
404403
YiiResponse $response,
405404
YiiRequest $request,
406-
Security $security
405+
Security $security,
407406
): void {
408407
if ($request->enableCookieValidation) {
409408
$validationKey = $request->cookieValidationKey;
@@ -419,15 +418,15 @@ protected function encodeCookies(
419418
: $cookie->value;
420419
$value = $security->hashData(serialize($data), $validationKey);
421420
}
422-
$expires = is_int($cookie->expire) ? (string)$cookie->expire : null;
421+
$expires = is_int($cookie->expire) ? (string) $cookie->expire : null;
423422
$c = new Cookie(
424423
$cookie->name,
425424
$value,
426425
$expires,
427426
$cookie->path,
428427
$cookie->domain,
429428
$cookie->secure,
430-
$cookie->httpOnly
429+
$cookie->httpOnly,
431430
);
432431
$this->getCookieJar()->set($c);
433432
}
@@ -457,13 +456,15 @@ protected function mockMailer(array $config): array
457456
'class' => TestMailer::class,
458457
'callback' => function (BaseMessage $message): void {
459458
$this->emails[] = $message;
460-
}
459+
},
461460
];
462461

463462
if (isset($config['components'])) {
464463
if (!is_array($config['components'])) {
465-
throw new ModuleConfigException($this,
466-
"Yii2 config does not contain components key is not of type array");
464+
throw new ModuleConfigException(
465+
$this,
466+
"Yii2 config does not contain components key is not of type array",
467+
);
467468
}
468469
} else {
469470
$config['components'] = [];
@@ -538,12 +539,13 @@ protected function resetResponse(Application $app): void
538539
|| count($app->response->getBehaviors()) > 0)
539540
&& $method === self::CLEAN_RECREATE
540541
) {
541-
Debug::debug(<<<TEXT
542+
Debug::debug(
543+
<<<TEXT
542544
[WARNING] You are attaching event handlers or behaviors to the response object. But the Yii2 module is configured to recreate
543545
the response object, this means any behaviors or events that are not attached in the component config will be lost.
544546
We will fall back to clearing the response. If you are certain you want to recreate it, please configure
545547
responseCleanMethod = 'force_recreate' in the module.
546-
TEXT
548+
TEXT,
547549
);
548550
$method = self::CLEAN_CLEAR;
549551
}
@@ -563,12 +565,13 @@ protected function resetRequest(Application $app): void
563565

564566
// First check the current request object.
565567
if (count($request->getBehaviors()) > 0 && $method === self::CLEAN_RECREATE) {
566-
Debug::debug(<<<TEXT
568+
Debug::debug(
569+
<<<TEXT
567570
[WARNING] You are attaching event handlers or behaviors to the request object. But the Yii2 module is configured to recreate
568571
the request object, this means any behaviors or events that are not attached in the component config will be lost.
569572
We will fall back to clearing the request. If you are certain you want to recreate it, please configure
570573
requestCleanMethod = 'force_recreate' in the module.
571-
TEXT
574+
TEXT,
572575
);
573576
$method = self::CLEAN_CLEAR;
574577
}

src/Codeception/Lib/Connector/Yii2/FixturesStore.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class FixturesStore
1616
*
1717
* FixturesStore constructor.
1818
*/
19-
public function __construct(protected mixed $data)
20-
{
21-
}
19+
public function __construct(protected mixed $data) {}
2220

2321
public function fixtures(): mixed
2422
{

src/Codeception/Lib/Connector/Yii2/Logger.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ public function init(): void
3838
*/
3939
public function log($message, $level, $category = 'application'): void
4040
{
41-
if (!in_array($level, [
42-
self::LEVEL_INFO,
43-
self::LEVEL_WARNING,
44-
self::LEVEL_ERROR,
45-
], true)) {
41+
if (
42+
!in_array($level, [
43+
self::LEVEL_INFO,
44+
self::LEVEL_WARNING,
45+
self::LEVEL_ERROR,
46+
], true)
47+
) {
4648
return;
4749
}
4850
if (str_starts_with($category, 'yii\db\Command')) {

src/Codeception/Lib/Connector/Yii2/TransactionForcer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,21 @@ protected function connectionOpened(Connection $connection): void
5555
*/
5656
if (isset($this->pdoCache[$key])) {
5757
$connection->pdo = $this->pdoCache[$key];
58-
} elseif(isset($connection->pdo)) {
58+
} elseif (isset($connection->pdo)) {
5959
$this->pdoCache[$key] = $connection->pdo;
6060
}
61-
if (isset($this->dsnCache[$connection->dsn])
61+
if (
62+
isset($this->dsnCache[$connection->dsn])
6263
&& $this->dsnCache[$connection->dsn] !== $key
6364
&& !$this->ignoreCollidingDSN
6465
) {
65-
$this->debug(<<<TEXT
66+
$this->debug(
67+
<<<TEXT
6668
You use multiple connections to the same DSN ({$connection->dsn}) with different configuration.
6769
These connections will not see the same database state since we cannot share a transaction between different PDO
6870
instances.
6971
You can remove this message by adding 'ignoreCollidingDSN = true' in the module configuration.
70-
TEXT
72+
TEXT,
7173
);
7274
Debug::pause();
7375
}

src/Codeception/Module/Yii2.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ private function initServerGlobal(): void
316316
'SCRIPT_NAME' => $entryScript,
317317
'SERVER_NAME' => $parsedUrl['host'] ?? '',
318318
'SERVER_PORT' => $parsedUrl['port'] ?? '80',
319-
'HTTPS' => isset($parsedUrl['scheme']) && $parsedUrl['scheme'] === 'https'
319+
'HTTPS' => isset($parsedUrl['scheme']) && $parsedUrl['scheme'] === 'https',
320320
]);
321321
}
322322

@@ -329,27 +329,27 @@ protected function validateConfig(): void
329329
if (!isset($this->config['configFile'])) {
330330
throw new ModuleConfigException(
331331
self::class,
332-
"The application config file was not configured"
332+
"The application config file was not configured",
333333
);
334334
}
335335
$pathToConfig = codecept_absolute_path($this->config['configFile']);
336336
if (!is_file($pathToConfig)) {
337337
throw new ModuleConfigException(
338338
self::class,
339-
"The application config file does not exist: " . $pathToConfig
339+
"The application config file does not exist: " . $pathToConfig,
340340
);
341341
}
342342
$validMethods = implode(", ", Yii2Connector::CLEAN_METHODS);
343343
if (!in_array($this->config['responseCleanMethod'], Yii2Connector::CLEAN_METHODS, true)) {
344344
throw new ModuleConfigException(
345345
self::class,
346-
"The response clean method must be one of: " . $validMethods
346+
"The response clean method must be one of: " . $validMethods,
347347
);
348348
}
349349
if (!in_array($this->config['requestCleanMethod'], Yii2Connector::CLEAN_METHODS, true)) {
350350
throw new ModuleConfigException(
351351
self::class,
352-
"The request clean method must be one of: " . $validMethods
352+
"The request clean method must be one of: " . $validMethods,
353353
);
354354
}
355355
}
@@ -384,7 +384,7 @@ protected function recreateClient(): void
384384
'SCRIPT_NAME' => $entryScript,
385385
'SERVER_NAME' => $parsedUrl['host'] ?? '',
386386
'SERVER_PORT' => $parsedUrl['port'] ?? '80',
387-
'HTTPS' => isset($parsedUrl['scheme']) && $parsedUrl['scheme'] === 'https'
387+
'HTTPS' => isset($parsedUrl['scheme']) && $parsedUrl['scheme'] === 'https',
388388
]);
389389
$this->validateConfig();
390390
$this->configureClient($this->config);
@@ -417,7 +417,8 @@ public function _before(TestInterface $test): void
417417
private function loadFixtures(object $test): void
418418
{
419419
$this->debugSection('Fixtures', 'Loading fixtures');
420-
if ($this->loadedFixtures === []
420+
if (
421+
$this->loadedFixtures === []
421422
&& method_exists($test, $this->config['fixturesMethod'])
422423
) {
423424
$connectionWatcher = new ConnectionWatcher();
@@ -517,7 +518,7 @@ public function amLoggedInAs(int|string|IdentityInterface $user): void
517518
{
518519
try {
519520
$this->getClient()->findAndLoginUser($user);
520-
} catch (ConfigurationException|RuntimeException $e) {
521+
} catch (ConfigurationException | RuntimeException $e) {
521522
throw new ModuleException($this, $e->getMessage());
522523
}
523524
}
@@ -579,8 +580,8 @@ public function haveFixtures(array $fixtures): void
579580
public function grabFixtures(): array
580581
{
581582
$result = [];
582-
foreach($this->loadedFixtures as $store) {
583-
foreach($store->getFixtures() as $name => $fixture) {
583+
foreach ($this->loadedFixtures as $store) {
584+
foreach ($store->getFixtures() as $name => $fixture) {
584585
$result[$name] = $fixture;
585586
}
586587
}
@@ -616,7 +617,7 @@ public function grabFixture(string $name, null|string $index = null): Fixture|\y
616617
return match (true) {
617618
$index === null => $fixture,
618619
$fixture instanceof \yii\test\BaseActiveFixture => $fixture->getModel($index),
619-
default => throw new ModuleException($this, "Fixture $name is not an instance of ActiveFixture and can't be loaded with second parameter")
620+
default => throw new ModuleException($this, "Fixture $name is not an instance of ActiveFixture and can't be loaded with second parameter"),
620621
};
621622
}
622623

@@ -713,7 +714,8 @@ protected function findRecord(string $model, array $attributes = []): ActiveReco
713714
throw new RuntimeException("Class $model does not exist");
714715
}
715716
$rc = new ReflectionClass($model);
716-
if ($rc->hasMethod('find')
717+
if (
718+
$rc->hasMethod('find')
717719
/** @phpstan-ignore-next-line */
718720
&& ($findMethod = $rc->getMethod('find'))
719721
&& $findMethod->isStatic()

0 commit comments

Comments
 (0)