Skip to content

Commit 44c41b7

Browse files
authored
Merge pull request #178 from armanist/177-Integrate-PHP-CS-Fixer-into-Quantum-Starter-Project
Integrate php cs fixer into quantum starter project
2 parents 0192922 + 634de96 commit 44c41b7

70 files changed

Lines changed: 326 additions & 280 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/php.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- name: Install dependencies
4343
run: composer update --prefer-dist --no-progress
4444

45+
- name: Run PHP-CS-Fixer
46+
run: composer cs:check
47+
4548
- name: Create env
4649
run: php qt core:env
4750

.gitignore

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
/vendor
22
/.idea
33
/nbproject/private/
4-
/shared/store/*
5-
/shared/emails/*
64
.env
75
composer.lock
8-
.phpunit.result.cache
6+
.phpunit.result.cache
7+
.php-cs-fixer.cache
8+
debug.log
9+
10+
# Runtime data
11+
/shared/store/*
12+
/shared/emails/*
13+
/shared/config/auth.php
14+
/shared/config/modules.php
15+
16+
# Generated modules
17+
/modules
18+
19+
# Published assets
20+
/public/assets/DebugBar
21+
/public/assets/OpenApiUi
22+
/public/assets/Web
23+
/public/uploads
24+
25+
# Test runtime
26+
/tests/_root/.env.testing
27+
/tests/_root/modules
28+
/tests/_root/shared/store/*
29+
/tests/_root/shared/config/auth.php
30+
/tests/_root/logs

.php-cs-fixer.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PhpCsFixer\Config;
6+
use PhpCsFixer\Finder;
7+
8+
$finder = Finder::create()
9+
->in(__DIR__)
10+
->exclude([
11+
'vendor',
12+
'modules',
13+
'public/assets',
14+
'public/uploads',
15+
])
16+
->name('*.php');
17+
18+
return (new Config())
19+
->setRiskyAllowed(false)
20+
->setRules([
21+
// Base standard
22+
'@PSR12' => true,
23+
24+
// Syntax & consistency
25+
'array_syntax' => ['syntax' => 'short'],
26+
'binary_operator_spaces' => ['default' => 'single_space'],
27+
'cast_spaces' => ['space' => 'single'],
28+
'concat_space' => ['spacing' => 'one'],
29+
'single_quote' => true,
30+
'trailing_comma_in_multiline' => true,
31+
'no_unused_imports' => true,
32+
'no_extra_blank_lines' => true,
33+
'blank_line_after_namespace' => true,
34+
'blank_line_after_opening_tag' => true,
35+
])
36+
->setFinder($finder);

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "MIT",
66
"type": "project",
77
"require": {
8+
"php": "^7.4 || ^8.0",
89
"quantum/framework": "dev-master",
910
"fakerphp/faker": "^1.15",
1011
"bluemmb/faker-picsum-photos-provider": "^2.0",
@@ -13,7 +14,8 @@
1314
},
1415
"require-dev": {
1516
"phpunit/phpunit": "^9.0",
16-
"mockery/mockery": "^1.2"
17+
"mockery/mockery": "^1.2",
18+
"friendsofphp/php-cs-fixer": "^3.94"
1719
},
1820
"autoload": {
1921
"psr-4": {
@@ -35,6 +37,8 @@
3537
"php qt install:debugbar",
3638
"php qt core:version"
3739
],
40+
"cs:check": "vendor/bin/php-cs-fixer check",
41+
"cs:fix": "vendor/bin/php-cs-fixer fix",
3842
"test": "vendor/bin/phpunit --stderr --coverage-clover coverage.xml"
3943
},
4044
"config": {

helpers/functions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
function url_with_lang(string $lang): string
2828
{
29-
if (!in_array($lang, (array)config()->get('lang.supported'))) {
29+
if (!in_array($lang, (array) config()->get('lang.supported'))) {
3030
$lang = config()->get('lang.default');
3131
}
3232

@@ -35,7 +35,7 @@ function url_with_lang(string $lang): string
3535
}
3636

3737
if (preg_match('/' . preg_quote(current_lang()) . '/', route_uri())) {
38-
return base_url() . preg_replace('/' . preg_quote(current_lang(), '/') . "/", $lang, route_uri(), 1);
38+
return base_url() . preg_replace('/' . preg_quote(current_lang(), '/') . '/', $lang, route_uri(), 1);
3939
}
4040

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

50-
$uri = preg_replace('/' . preg_quote(route_prefix(), '/') . "/", '', route_uri(), 1);
50+
$uri = preg_replace('/' . preg_quote(route_prefix(), '/') . '/', '', route_uri(), 1);
5151
}
5252

5353
$segments = explode('/', $uri);
@@ -103,7 +103,7 @@ function create_user_directory(string $uuid)
103103
{
104104
$userDirectory = uploads_dir() . DS . $uuid;
105105

106-
if(!fs()->isDirectory($userDirectory)) {
106+
if (!fs()->isDirectory($userDirectory)) {
107107
fs()->makeDirectory($userDirectory);
108108
}
109109
}
@@ -143,4 +143,4 @@ function nav_ref_decode(?string $ref): string
143143
$decoded = $ref ? base64_decode(strtr($ref, '-_', '+/'), true) : false;
144144

145145
return '/posts' . ($decoded ? '?' . $decoded : '');
146-
}
146+
}

migrations/create_table_comments_1698145440.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class Create_table_comments_1698145440 extends QtMigration
77
{
8-
98
public function up(?TableFactory $tableFactory)
109
{
1110
$table = $tableFactory->create('comments');

migrations/create_table_posts_1669639752.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class Create_table_posts_1669639752 extends QtMigration
77
{
8-
98
public function up(?TableFactory $tableFactory)
109
{
1110
$table = $tableFactory->create('posts');

migrations/create_table_users_1669639740.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class Create_table_users_1669639740 extends QtMigration
77
{
8-
98
public function up(?TableFactory $tableFactory)
109
{
1110
$table = $tableFactory->create('users');

public/index.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
* Directory separator
1616
* -----------------------------------------------------------------------------
1717
*/
18-
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
19-
18+
if (!defined('DS')) {
19+
define('DS', DIRECTORY_SEPARATOR);
20+
}
2021

2122
/*
2223
* -----------------------------------------------------------------------------
2324
* Starting the app
2425
* -----------------------------------------------------------------------------
2526
*/
26-
AppFactory::create(AppType::WEB, dirname(__DIR__))->start();
27+
AppFactory::create(AppType::WEB, dirname(__DIR__))->start();

shared/Commands/CommandValidationTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
trait CommandValidationTrait
2828
{
29-
3029
/**
3130
* @var Validator
3231
*/
@@ -78,4 +77,4 @@ public function firstError(): ?string
7877

7978
return null;
8079
}
81-
}
80+
}

0 commit comments

Comments
 (0)