Skip to content

Commit 524d742

Browse files
authored
Merge pull request #180 from armanist/179-Integrate-Rector-into-Quantum-Starter-Projec
Integrated Rector into Quantum Starter Project
2 parents 44c41b7 + cbc3e05 commit 524d742

29 files changed

Lines changed: 121 additions & 53 deletions

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"require-dev": {
1616
"phpunit/phpunit": "^9.0",
1717
"mockery/mockery": "^1.2",
18-
"friendsofphp/php-cs-fixer": "^3.94"
18+
"friendsofphp/php-cs-fixer": "^3.94",
19+
"rector/rector": "^2.3"
1920
},
2021
"autoload": {
2122
"psr-4": {
@@ -39,6 +40,8 @@
3940
],
4041
"cs:check": "vendor/bin/php-cs-fixer check",
4142
"cs:fix": "vendor/bin/php-cs-fixer fix",
43+
"rector:check": "vendor/bin/rector process --dry-run",
44+
"rector:fix": "vendor/bin/rector process",
4245
"test": "vendor/bin/phpunit --stderr --coverage-clover coverage.xml"
4346
},
4447
"config": {

helpers/functions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @author Arman Ag. <arman.ag@softberg.org>
1010
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
1111
* @link http://quantum.softberg.org/
12-
* @since 2.9.9
12+
* @since 3.0.0
1313
*/
1414

1515
use Quantum\HttpClient\Exceptions\HttpClientException;
@@ -99,7 +99,7 @@ function save_remote_image(string $imageUrl, string $userDirectory, string $imag
9999
* @throws BaseException
100100
* @throws ConfigException
101101
*/
102-
function create_user_directory(string $uuid)
102+
function create_user_directory(string $uuid): void
103103
{
104104
$userDirectory = uploads_dir() . DS . $uuid;
105105

@@ -111,16 +111,16 @@ function create_user_directory(string $uuid)
111111
/**
112112
* Cleans up text for titles/descriptions.
113113
* @param string $text
114-
* @return array|string|string[]
114+
* @return string
115115
*/
116-
function textCleanUp(string $text)
116+
function textCleanUp(string $text): string
117117
{
118118
return str_replace(['"', '\'', '-'], '', $text);
119119
}
120120

121121
/**
122122
* Encodes current query string to URL-safe base64.
123-
* @param string $query
123+
* @param string|null $query
124124
* @return string
125125
*/
126126
function nav_ref_encode(?string $query): string

migrations/create_table_comments_1698145440.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Create_table_comments_1698145440 extends QtMigration
77
{
8-
public function up(?TableFactory $tableFactory)
8+
public function up(?TableFactory $tableFactory): void
99
{
1010
$table = $tableFactory->create('comments');
1111
$table->addColumn('id', 'integer')->primary()->autoIncrement();
@@ -16,7 +16,7 @@ public function up(?TableFactory $tableFactory)
1616
$table->addColumn('created_at', 'timestamp');
1717
}
1818

19-
public function down(?TableFactory $tableFactory)
19+
public function down(?TableFactory $tableFactory): void
2020
{
2121
$tableFactory->drop('comments');
2222
}

migrations/create_table_posts_1669639752.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Create_table_posts_1669639752 extends QtMigration
77
{
8-
public function up(?TableFactory $tableFactory)
8+
public function up(?TableFactory $tableFactory): void
99
{
1010
$table = $tableFactory->create('posts');
1111
$table->addColumn('id', 'integer')->primary()->autoIncrement();
@@ -17,7 +17,7 @@ public function up(?TableFactory $tableFactory)
1717
$table->addColumn('updated_at', 'timestamp');
1818
}
1919

20-
public function down(?TableFactory $tableFactory)
20+
public function down(?TableFactory $tableFactory): void
2121
{
2222
$tableFactory->drop('posts');
2323
}

migrations/create_table_users_1669639740.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Create_table_users_1669639740 extends QtMigration
77
{
8-
public function up(?TableFactory $tableFactory)
8+
public function up(?TableFactory $tableFactory): void
99
{
1010
$table = $tableFactory->create('users');
1111
$table->addColumn('id', 'integer')->primary()->autoIncrement();
@@ -25,7 +25,7 @@ public function up(?TableFactory $tableFactory)
2525
$table->addColumn('otp_expires', 'timestamp')->nullable();
2626
}
2727

28-
public function down(?TableFactory $tableFactory)
28+
public function down(?TableFactory $tableFactory): void
2929
{
3030
$tableFactory->drop('users');
3131
}

rector.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
use Rector\Set\ValueObject\SetList;
8+
use Rector\Config\RectorConfig;
9+
10+
return RectorConfig::configure()
11+
->withPaths([
12+
__DIR__ . '/helpers',
13+
__DIR__ . '/hooks',
14+
__DIR__ . '/libraries',
15+
__DIR__ . '/migrations',
16+
__DIR__ . '/public/index.php',
17+
__DIR__ . '/shared',
18+
])
19+
->withSkip([
20+
__DIR__ . '/modules',
21+
])
22+
->withSets([
23+
LevelSetList::UP_TO_PHP_80,
24+
SetList::TYPE_DECLARATION,
25+
])
26+
->withRules([
27+
DeclareStrictTypesRector::class,
28+
]);

shared/Commands/CommandValidationTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* Quantum PHP Framework
57
*

shared/Commands/CommentCreateCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* Quantum PHP Framework
57
*

shared/Commands/CommentDeleteCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* Quantum PHP Framework
57
*
@@ -97,7 +99,7 @@ public function exec(): void
9799
* @throws ServiceException
98100
* @throws BaseException
99101
*/
100-
private function deleteSingleComment(string $uuid)
102+
private function deleteSingleComment(string $uuid): void
101103
{
102104
$commentService = service(CommentService::class);
103105

@@ -120,7 +122,7 @@ private function deleteSingleComment(string $uuid)
120122
* @throws ServiceException
121123
* @throws BaseException
122124
*/
123-
private function deleteAllComments()
125+
private function deleteAllComments(): void
124126
{
125127
service(CommentService::class)->deleteAllComments();
126128

shared/Commands/DemoCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* Quantum PHP Framework
57
*
@@ -161,37 +163,37 @@ private function getSteps(): array
161163
return [
162164
[
163165
'message' => 'Creating API module',
164-
'action' => function () {
166+
'action' => function (): void {
165167
$this->createModule('Api', 'DemoApi', false);
166168
},
167169
],
168170
[
169171
'message' => 'Creating Web module',
170-
'action' => function () {
172+
'action' => function (): void {
171173
$this->createModule('Web', 'DemoWeb', true);
172174
},
173175
],
174176
[
175177
'message' => 'Cleaning up uploads & rebuilding database',
176-
'action' => function () {
178+
'action' => function (): void {
177179
$this->resetDatabase();
178180
},
179181
],
180182
[
181183
'message' => 'Generating users',
182-
'action' => function () {
184+
'action' => function (): void {
183185
$this->generatedUsers = $this->generateUsers();
184186
},
185187
],
186188
[
187189
'message' => 'Generating posts',
188-
'action' => function () {
190+
'action' => function (): void {
189191
$this->generatedPosts = $this->generatePosts($this->generatedUsers);
190192
},
191193
],
192194
[
193195
'message' => 'Generating comments',
194-
'action' => function () {
196+
'action' => function (): void {
195197
$this->generateComments($this->generatedUsers, $this->generatedPosts);
196198
},
197199
],
@@ -295,7 +297,7 @@ private function generateComments(array $users, array $posts): void
295297
$this->runCommandInternally(self::COMMANDS['comment_create'], [
296298
'post_uuid' => $post['uuid'],
297299
'user_uuid' => $commentUser['uuid'],
298-
'content' => textCleanUp($this->faker->realText(rand(20, 100))),
300+
'content' => textCleanUp($this->faker->realText(random_int(20, 100))),
299301
]);
300302
}
301303
}
@@ -374,9 +376,7 @@ private function generatePostData(array $user): array
374376
*/
375377
private function getRandomUserExcept(array $users, string $excludeUuid): array
376378
{
377-
$candidates = array_filter($users, function ($u) use ($excludeUuid) {
378-
return $u['uuid'] !== $excludeUuid;
379-
});
379+
$candidates = array_filter($users, fn (array $u): bool => $u['uuid'] !== $excludeUuid);
380380

381381
$candidates = array_values($candidates);
382382
return $candidates[array_rand($candidates)];
@@ -454,7 +454,7 @@ private function resetDatabase(): void
454454
* @param array $arguments
455455
* @throws ExceptionInterface
456456
*/
457-
private function runCommandInternally(string $commandName, array $arguments = [])
457+
private function runCommandInternally(string $commandName, array $arguments = []): void
458458
{
459459
$command = $this->getApplication()->find($commandName);
460460
$command->run(new ArrayInput($arguments), new NullOutput());
@@ -464,7 +464,7 @@ private function runCommandInternally(string $commandName, array $arguments = []
464464
* @param string $commandName
465465
* @param array $arguments
466466
*/
467-
private function runCommandExternally(string $commandName, array $arguments = [])
467+
private function runCommandExternally(string $commandName, array $arguments = []): void
468468
{
469469
$command = $this->buildCommand($commandName, $arguments);
470470
$this->runExternalProcess($command);

0 commit comments

Comments
 (0)