Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"require-dev": {
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.2",
"friendsofphp/php-cs-fixer": "^3.94"
"friendsofphp/php-cs-fixer": "^3.94",
"rector/rector": "^2.3"
},
"autoload": {
"psr-4": {
Expand All @@ -39,6 +40,8 @@
],
"cs:check": "vendor/bin/php-cs-fixer check",
"cs:fix": "vendor/bin/php-cs-fixer fix",
"rector:check": "vendor/bin/rector process --dry-run",
"rector:fix": "vendor/bin/rector process",
"test": "vendor/bin/phpunit --stderr --coverage-clover coverage.xml"
},
"config": {
Expand Down
10 changes: 5 additions & 5 deletions helpers/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.9
* @since 3.0.0
*/

use Quantum\HttpClient\Exceptions\HttpClientException;
Expand Down Expand Up @@ -99,7 +99,7 @@ function save_remote_image(string $imageUrl, string $userDirectory, string $imag
* @throws BaseException
* @throws ConfigException
*/
function create_user_directory(string $uuid)
function create_user_directory(string $uuid): void
{
$userDirectory = uploads_dir() . DS . $uuid;

Expand All @@ -111,16 +111,16 @@ function create_user_directory(string $uuid)
/**
* Cleans up text for titles/descriptions.
* @param string $text
* @return array|string|string[]
* @return string
*/
function textCleanUp(string $text)
function textCleanUp(string $text): string
{
return str_replace(['"', '\'', '-'], '', $text);
}

/**
* Encodes current query string to URL-safe base64.
* @param string $query
* @param string|null $query
* @return string
*/
function nav_ref_encode(?string $query): string
Expand Down
4 changes: 2 additions & 2 deletions migrations/create_table_comments_1698145440.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Create_table_comments_1698145440 extends QtMigration
{
public function up(?TableFactory $tableFactory)
public function up(?TableFactory $tableFactory): void
{
$table = $tableFactory->create('comments');
$table->addColumn('id', 'integer')->primary()->autoIncrement();
Expand All @@ -16,7 +16,7 @@ public function up(?TableFactory $tableFactory)
$table->addColumn('created_at', 'timestamp');
}

public function down(?TableFactory $tableFactory)
public function down(?TableFactory $tableFactory): void
{
$tableFactory->drop('comments');
}
Expand Down
4 changes: 2 additions & 2 deletions migrations/create_table_posts_1669639752.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Create_table_posts_1669639752 extends QtMigration
{
public function up(?TableFactory $tableFactory)
public function up(?TableFactory $tableFactory): void
{
$table = $tableFactory->create('posts');
$table->addColumn('id', 'integer')->primary()->autoIncrement();
Expand All @@ -17,7 +17,7 @@ public function up(?TableFactory $tableFactory)
$table->addColumn('updated_at', 'timestamp');
}

public function down(?TableFactory $tableFactory)
public function down(?TableFactory $tableFactory): void
{
$tableFactory->drop('posts');
}
Expand Down
4 changes: 2 additions & 2 deletions migrations/create_table_users_1669639740.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Create_table_users_1669639740 extends QtMigration
{
public function up(?TableFactory $tableFactory)
public function up(?TableFactory $tableFactory): void
{
$table = $tableFactory->create('users');
$table->addColumn('id', 'integer')->primary()->autoIncrement();
Expand All @@ -25,7 +25,7 @@ public function up(?TableFactory $tableFactory)
$table->addColumn('otp_expires', 'timestamp')->nullable();
}

public function down(?TableFactory $tableFactory)
public function down(?TableFactory $tableFactory): void
{
$tableFactory->drop('users');
}
Expand Down
28 changes: 28 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/helpers',
__DIR__ . '/hooks',
__DIR__ . '/libraries',
__DIR__ . '/migrations',
__DIR__ . '/public/index.php',
__DIR__ . '/shared',
])
->withSkip([
__DIR__ . '/modules',
])
->withSets([
LevelSetList::UP_TO_PHP_80,
SetList::TYPE_DECLARATION,
])
->withRules([
DeclareStrictTypesRector::class,
]);
2 changes: 2 additions & 0 deletions shared/Commands/CommandValidationTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down
2 changes: 2 additions & 0 deletions shared/Commands/CommentCreateCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down
6 changes: 4 additions & 2 deletions shared/Commands/CommentDeleteCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down Expand Up @@ -97,7 +99,7 @@ public function exec(): void
* @throws ServiceException
* @throws BaseException
*/
private function deleteSingleComment(string $uuid)
private function deleteSingleComment(string $uuid): void
{
$commentService = service(CommentService::class);

Expand All @@ -120,7 +122,7 @@ private function deleteSingleComment(string $uuid)
* @throws ServiceException
* @throws BaseException
*/
private function deleteAllComments()
private function deleteAllComments(): void
{
service(CommentService::class)->deleteAllComments();

Expand Down
24 changes: 12 additions & 12 deletions shared/Commands/DemoCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down Expand Up @@ -161,37 +163,37 @@ private function getSteps(): array
return [
[
'message' => 'Creating API module',
'action' => function () {
'action' => function (): void {
$this->createModule('Api', 'DemoApi', false);
},
],
[
'message' => 'Creating Web module',
'action' => function () {
'action' => function (): void {
$this->createModule('Web', 'DemoWeb', true);
},
],
[
'message' => 'Cleaning up uploads & rebuilding database',
'action' => function () {
'action' => function (): void {
$this->resetDatabase();
},
],
[
'message' => 'Generating users',
'action' => function () {
'action' => function (): void {
$this->generatedUsers = $this->generateUsers();
},
],
[
'message' => 'Generating posts',
'action' => function () {
'action' => function (): void {
$this->generatedPosts = $this->generatePosts($this->generatedUsers);
},
],
[
'message' => 'Generating comments',
'action' => function () {
'action' => function (): void {
$this->generateComments($this->generatedUsers, $this->generatedPosts);
},
],
Expand Down Expand Up @@ -295,7 +297,7 @@ private function generateComments(array $users, array $posts): void
$this->runCommandInternally(self::COMMANDS['comment_create'], [
'post_uuid' => $post['uuid'],
'user_uuid' => $commentUser['uuid'],
'content' => textCleanUp($this->faker->realText(rand(20, 100))),
'content' => textCleanUp($this->faker->realText(random_int(20, 100))),
]);
}
}
Expand Down Expand Up @@ -374,9 +376,7 @@ private function generatePostData(array $user): array
*/
private function getRandomUserExcept(array $users, string $excludeUuid): array
{
$candidates = array_filter($users, function ($u) use ($excludeUuid) {
return $u['uuid'] !== $excludeUuid;
});
$candidates = array_filter($users, fn (array $u): bool => $u['uuid'] !== $excludeUuid);

$candidates = array_values($candidates);
return $candidates[array_rand($candidates)];
Expand Down Expand Up @@ -454,7 +454,7 @@ private function resetDatabase(): void
* @param array $arguments
* @throws ExceptionInterface
*/
private function runCommandInternally(string $commandName, array $arguments = [])
private function runCommandInternally(string $commandName, array $arguments = []): void
{
$command = $this->getApplication()->find($commandName);
$command->run(new ArrayInput($arguments), new NullOutput());
Expand All @@ -464,7 +464,7 @@ private function runCommandInternally(string $commandName, array $arguments = []
* @param string $commandName
* @param array $arguments
*/
private function runCommandExternally(string $commandName, array $arguments = [])
private function runCommandExternally(string $commandName, array $arguments = []): void
{
$command = $this->buildCommand($commandName, $arguments);
$this->runExternalProcess($command);
Expand Down
2 changes: 2 additions & 0 deletions shared/Commands/PostCreateCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down
6 changes: 4 additions & 2 deletions shared/Commands/PostDeleteCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down Expand Up @@ -97,7 +99,7 @@ public function exec(): void
* @throws ServiceException
* @throws BaseException
*/
private function deleteSinglePost(string $uuid)
private function deleteSinglePost(string $uuid): void
{
$postService = service(PostService::class);

Expand All @@ -120,7 +122,7 @@ private function deleteSinglePost(string $uuid)
* @throws ReflectionException
* @throws ServiceException
*/
private function deleteAllPosts()
private function deleteAllPosts(): void
{
service(PostService::class)->deleteAllPosts();

Expand Down
4 changes: 3 additions & 1 deletion shared/Commands/PostShowCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand All @@ -9,7 +11,7 @@
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.9
* @since 3.0.0
*/

namespace Shared\Commands;
Expand Down
2 changes: 2 additions & 0 deletions shared/Commands/PostUpdateCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down
2 changes: 2 additions & 0 deletions shared/Commands/UserCreateCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down
6 changes: 4 additions & 2 deletions shared/Commands/UserDeleteCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down Expand Up @@ -94,7 +96,7 @@ public function exec(): void
* @param string $uuid
* @throws BaseException|DiException|ServiceException|ReflectionException
*/
private function deleteSingleUser(string $uuid)
private function deleteSingleUser(string $uuid): void
{
$authService = service(AuthService::class);

Expand All @@ -107,7 +109,7 @@ private function deleteSingleUser(string $uuid)
* Deletes all users
* @throws BaseException|DiException|ServiceException|ReflectionException
*/
private function deleteAllUsers()
private function deleteAllUsers(): void
{
service(AuthService::class)->deleteAllUsers();

Expand Down
4 changes: 3 additions & 1 deletion shared/Commands/UserShowCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand All @@ -9,7 +11,7 @@
* @author Arman Ag. <arman.ag@softberg.org>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.9
* @since 3.0.0
*/

namespace Shared\Commands;
Expand Down
2 changes: 2 additions & 0 deletions shared/DTOs/CommentDTO.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Quantum PHP Framework
*
Expand Down
Loading
Loading