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
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: Install dependencies
run: composer update --prefer-dist --no-progress

- name: Run PHP-CS-Fixer
run: composer cs:check

- name: Create env
run: php qt core:env

Expand Down
28 changes: 25 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
/vendor
/.idea
/nbproject/private/
/shared/store/*
/shared/emails/*
.env
composer.lock
.phpunit.result.cache
.phpunit.result.cache
.php-cs-fixer.cache
debug.log

# Runtime data
/shared/store/*
/shared/emails/*
/shared/config/auth.php
/shared/config/modules.php

# Generated modules
/modules

# Published assets
/public/assets/DebugBar
/public/assets/OpenApiUi
/public/assets/Web
/public/uploads

# Test runtime
/tests/_root/.env.testing
/tests/_root/modules
/tests/_root/shared/store/*
/tests/_root/shared/config/auth.php
/tests/_root/logs
36 changes: 36 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__)
->exclude([
'vendor',
'modules',
'public/assets',
'public/uploads',
])
->name('*.php');

return (new Config())
->setRiskyAllowed(false)
->setRules([
// Base standard
'@PSR12' => true,

// Syntax & consistency
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['default' => 'single_space'],
'cast_spaces' => ['space' => 'single'],
'concat_space' => ['spacing' => 'one'],
'single_quote' => true,
'trailing_comma_in_multiline' => true,
'no_unused_imports' => true,
'no_extra_blank_lines' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
])
->setFinder($finder);
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "MIT",
"type": "project",
"require": {
"php": "^7.4 || ^8.0",
"quantum/framework": "dev-master",
"fakerphp/faker": "^1.15",
"bluemmb/faker-picsum-photos-provider": "^2.0",
Expand All @@ -13,7 +14,8 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.2"
"mockery/mockery": "^1.2",
"friendsofphp/php-cs-fixer": "^3.94"
},
"autoload": {
"psr-4": {
Expand All @@ -35,6 +37,8 @@
"php qt install:debugbar",
"php qt core:version"
],
"cs:check": "vendor/bin/php-cs-fixer check",
"cs:fix": "vendor/bin/php-cs-fixer fix",
"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 @@ -26,7 +26,7 @@
*/
function url_with_lang(string $lang): string
{
if (!in_array($lang, (array)config()->get('lang.supported'))) {
if (!in_array($lang, (array) config()->get('lang.supported'))) {
$lang = config()->get('lang.default');
}

Expand All @@ -35,7 +35,7 @@ function url_with_lang(string $lang): string
}

if (preg_match('/' . preg_quote(current_lang()) . '/', route_uri())) {
return base_url() . preg_replace('/' . preg_quote(current_lang(), '/') . "/", $lang, route_uri(), 1);
return base_url() . preg_replace('/' . preg_quote(current_lang(), '/') . '/', $lang, route_uri(), 1);
}

$url = base_url(true);
Expand All @@ -47,7 +47,7 @@ function url_with_lang(string $lang): string
if (!empty(route_prefix()) && $langSegmentIndex == 1) {
$langSegmentIndex += 1;

$uri = preg_replace('/' . preg_quote(route_prefix(), '/') . "/", '', route_uri(), 1);
$uri = preg_replace('/' . preg_quote(route_prefix(), '/') . '/', '', route_uri(), 1);
}

$segments = explode('/', $uri);
Expand Down Expand Up @@ -103,7 +103,7 @@ function create_user_directory(string $uuid)
{
$userDirectory = uploads_dir() . DS . $uuid;

if(!fs()->isDirectory($userDirectory)) {
if (!fs()->isDirectory($userDirectory)) {
fs()->makeDirectory($userDirectory);
}
}
Expand Down Expand Up @@ -143,4 +143,4 @@ function nav_ref_decode(?string $ref): string
$decoded = $ref ? base64_decode(strtr($ref, '-_', '+/'), true) : false;

return '/posts' . ($decoded ? '?' . $decoded : '');
}
}
1 change: 0 additions & 1 deletion migrations/create_table_comments_1698145440.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class Create_table_comments_1698145440 extends QtMigration
{

public function up(?TableFactory $tableFactory)
{
$table = $tableFactory->create('comments');
Expand Down
1 change: 0 additions & 1 deletion migrations/create_table_posts_1669639752.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class Create_table_posts_1669639752 extends QtMigration
{

public function up(?TableFactory $tableFactory)
{
$table = $tableFactory->create('posts');
Expand Down
1 change: 0 additions & 1 deletion migrations/create_table_users_1669639740.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class Create_table_users_1669639740 extends QtMigration
{

public function up(?TableFactory $tableFactory)
{
$table = $tableFactory->create('users');
Expand Down
7 changes: 4 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
* Directory separator
* -----------------------------------------------------------------------------
*/
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);

if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}

/*
* -----------------------------------------------------------------------------
* Starting the app
* -----------------------------------------------------------------------------
*/
AppFactory::create(AppType::WEB, dirname(__DIR__))->start();
AppFactory::create(AppType::WEB, dirname(__DIR__))->start();
3 changes: 1 addition & 2 deletions shared/Commands/CommandValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
trait CommandValidationTrait
{

/**
* @var Validator
*/
Expand Down Expand Up @@ -78,4 +77,4 @@ public function firstError(): ?string

return null;
}
}
}
3 changes: 1 addition & 2 deletions shared/Commands/CommentCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
class CommentCreateCommand extends QtCommand
{

use CommandValidationTrait;

/**
Expand Down Expand Up @@ -102,4 +101,4 @@ protected function validationRules(): array
],
];
}
}
}
2 changes: 1 addition & 1 deletion shared/Commands/CommentDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ private function deleteAllComments()

$this->info('All comments have been deleted successfully');
}
}
}
53 changes: 27 additions & 26 deletions shared/Commands/DemoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@
*/
class DemoCommand extends QtCommand
{

/**
* Default password for generated users
*/
const DEFAULT_PASSWORD = 'password';
public const DEFAULT_PASSWORD = 'password';

/**
* Command name
Expand All @@ -70,7 +69,7 @@ class DemoCommand extends QtCommand
* @var array
*/
protected array $options = [
['yes', 'y', 'none', 'Acceptance of the confirmations']
['yes', 'y', 'none', 'Acceptance of the confirmations'],
];

/**
Expand Down Expand Up @@ -150,7 +149,7 @@ public function exec(): void
}

$progress->finish();
$this->info(PHP_EOL . "Demo project created successfully");
$this->info(PHP_EOL . 'Demo project created successfully');
}

/**
Expand All @@ -162,39 +161,39 @@ private function getSteps(): array
return [
[
'message' => 'Creating API module',
'action' => function() {
'action' => function () {
$this->createModule('Api', 'DemoApi', false);
}
},
],
[
'message' => 'Creating Web module',
'action' => function() {
'action' => function () {
$this->createModule('Web', 'DemoWeb', true);
}
},
],
[
'message' => 'Cleaning up uploads & rebuilding database',
'action' => function() {
'action' => function () {
$this->resetDatabase();
}
},
],
[
'message' => 'Generating users',
'action' => function() {
'action' => function () {
$this->generatedUsers = $this->generateUsers();
}
},
],
[
'message' => 'Generating posts',
'action' => function() {
'action' => function () {
$this->generatedPosts = $this->generatePosts($this->generatedUsers);
}
},
],
[
'message' => 'Generating comments',
'action' => function() {
'action' => function () {
$this->generateComments($this->generatedUsers, $this->generatedPosts);
}
},
],
];
}
Expand Down Expand Up @@ -227,7 +226,7 @@ private function createModule(string $moduleName, string $template, bool $withAs
'module' => $moduleName,
'--yes' => true,
'--template' => $template,
'--with-assets' => $withAssets
'--with-assets' => $withAssets,
]);
}

Expand Down Expand Up @@ -296,7 +295,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(rand(20, 100))),
]);
}
}
Expand Down Expand Up @@ -332,7 +331,7 @@ private function generateUserData(): array
'lastname' => $this->faker->lastName(),
'uuid' => $userUuid,
'role' => Role::EDITOR,
'image' => $imageName
'image' => $imageName,
];
}

Expand Down Expand Up @@ -375,7 +374,7 @@ private function generatePostData(array $user): array
*/
private function getRandomUserExcept(array $users, string $excludeUuid): array
{
$candidates = array_filter($users, function($u) use ($excludeUuid) {
$candidates = array_filter($users, function ($u) use ($excludeUuid) {
return $u['uuid'] !== $excludeUuid;
});

Expand Down Expand Up @@ -458,7 +457,7 @@ private function resetDatabase(): void
private function runCommandInternally(string $commandName, array $arguments = [])
{
$command = $this->getApplication()->find($commandName);
$command->run(new ArrayInput($arguments), new NullOutput);
$command->run(new ArrayInput($arguments), new NullOutput());
}

/**
Expand Down Expand Up @@ -496,19 +495,21 @@ private function buildCommand(string $commandName, array $arguments): array

foreach ($arguments as $key => $value) {
if (!is_int($key) && substr($key, 0, 2) !== '--') {
$command[] = (string)$value;
$command[] = (string) $value;
continue;
}

if (is_bool($value)) {
if ($value) $command[] = $key;
if ($value) {
$command[] = $key;
}
continue;
}

if (is_array($value)) {
foreach ($value as $item) {
$command[] = $key;
$command[] = (string)$item;
$command[] = (string) $item;
}
continue;
}
Expand All @@ -519,9 +520,9 @@ private function buildCommand(string $commandName, array $arguments): array
continue;
}

$command[] = (string)$value;
$command[] = (string) $value;
}

return $command;
}
}
}
Loading
Loading