Skip to content

Commit e3c0be6

Browse files
committed
Add Pint for code style, apply changes and update Actions to check for code style issues with Pint
1 parent cbdb617 commit e3c0be6

File tree

10 files changed

+213
-56
lines changed

10 files changed

+213
-56
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml,json}]
15+
indent_size = 2

.github/workflows/php.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
1616

1717
- name: Validate composer.json and composer.lock
1818
run: composer validate
1919

2020
- name: Install dependencies
2121
run: composer install --prefer-dist --no-progress
2222

23-
- name: Run test suite
24-
run: composer test
23+
- name: Check code style
24+
run: composer test:lint
2525

26-
- name: Run php-cs-fixer
27-
run: composer csfix .
26+
- name: Run test suite
27+
run: composer test:unit

Command/Create/ContentController.php

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

3+
declare(strict_types=1);
4+
35
namespace librarianphp\Create;
46

5-
use Minicli\FileNotFoundException;
6-
use Minicli\Stencil;
77
use Minicli\Command\CommandController;
8+
use Minicli\FileNotFoundException;
89
use Minicli\Input;
10+
use Minicli\Stencil;
911

1012
class ContentController extends CommandController
1113
{
@@ -14,41 +16,44 @@ class ContentController extends CommandController
1416
*/
1517
public function handle(): void
1618
{
17-
if (!$this->getApp()->config->has('stencil_dir')) {
18-
$this->error("You must define a stencil_dir config option.");
19+
if (! $this->getApp()->config->has('stencil_dir')) {
20+
$this->error('You must define a stencil_dir config option.');
21+
1922
return;
2023
}
2124

22-
if (!$this->getApp()->config->has('stencil_locations')) {
23-
$this->error("You must define a stencil_locations array config option.");
25+
if (! $this->getApp()->config->has('stencil_locations')) {
26+
$this->error('You must define a stencil_locations array config option.');
27+
2428
return;
2529
}
2630

2731
$args = $this->getArgs();
2832
$template_name = $args[3] ?? null;
29-
if (!$template_name) {
33+
if (! $template_name) {
3034
$template_name = 'post';
3135
}
3236

3337
$stencil = new Stencil($this->getApp()->config->stencil_dir);
3438

3539
$input = new Input(' ');
3640

37-
$this->info("Content Title: ");
41+
$this->info('Content Title: ');
3842
$title = $input->read();
3943

40-
$this->info("Content Description: ");
44+
$this->info('Content Description: ');
4145
$description = $input->read();
4246

4347
$content = $stencil->applyTemplate($template_name, [
4448
'title' => $title,
45-
'description' => $description
49+
'description' => $description,
4650
]);
4751

4852
$save_locations = $this->getApp()->config->stencil_locations;
4953

50-
if (!array_key_exists($template_name, $save_locations)) {
51-
$this->error("Save location not found for template $template_name");
54+
if (! array_key_exists($template_name, $save_locations)) {
55+
$this->error("Save location not found for template {$template_name}");
56+
5257
return;
5358
}
5459

@@ -57,7 +62,7 @@ public function handle(): void
5762
$file = fopen($path . '/' . $save_name, 'a+');
5863

5964
fwrite($file, $content);
60-
$this->info("Content generated at " . $path . '/' . $save_name);
65+
$this->info('Content generated at ' . $path . '/' . $save_name);
6166
}
6267

6368
public function slugify($title)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace librarianphp\Create;
46

5-
use Minicli\App;
67
use Minicli\Command\CommandController;
78

89
class DefaultController extends CommandController
910
{
1011
public function handle(): void
1112
{
12-
$this->info("./librarian create [subcommand]", true);
13-
$this->info("Run \"./librarian create content\" to create a content file based on a template.");
13+
$this->info('./librarian create [subcommand]', true);
14+
$this->info('Run "./librarian create content" to create a content file based on a template.');
1415
}
1516
}

composer.json

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
{
2-
"name": "librarianphp/command-create",
3-
"type": "library",
4-
"description": "Librarian's built-in command to create new content",
5-
"license": "MIT",
6-
"homepage": "https://github.com/librarianphp/command-demo",
7-
"keywords": ["cli","command-line", "markdown"],
8-
"autoload": {
9-
"psr-4": {
10-
"librarianphp\\": "Command/"
11-
}
12-
},
13-
"require": {
14-
"minicli/minicli": "^4.0",
15-
"minicli/stencil": "^0.1.1"
16-
},
17-
"require-dev": {
18-
"pestphp/pest": "^2.4",
19-
"friendsofphp/php-cs-fixer": "^3.16"
20-
},
21-
"scripts": {
22-
"test" : ["pest"],
23-
"csfix": ["php-cs-fixer fix"]
24-
},
25-
"config": {
26-
"allow-plugins": {
27-
"pestphp/pest-plugin": true
28-
}
2+
"name": "librarianphp/command-create",
3+
"type": "library",
4+
"description": "Librarian's built-in command to create new content",
5+
"license": "MIT",
6+
"homepage": "https://github.com/librarianphp/command-demo",
7+
"keywords": [
8+
"cli",
9+
"command-line",
10+
"markdown"
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"librarianphp\\": "Command/"
2915
}
16+
},
17+
"require": {
18+
"minicli/minicli": "^4.0",
19+
"minicli/stencil": "^0.1.1"
20+
},
21+
"require-dev": {
22+
"pestphp/pest": "^2.4",
23+
"friendsofphp/php-cs-fixer": "^3.16",
24+
"laravel/pint": "^1.10"
25+
},
26+
"scripts": {
27+
"lint": ["pint"],
28+
"test:lint": ["pint --test"],
29+
"test:unit": ["pest"],
30+
"test": [
31+
"@test:lint",
32+
"@test:unit"
33+
]
34+
},
35+
"config": {
36+
"allow-plugins": {
37+
"pestphp/pest-plugin": true
38+
}
39+
}
3040
}

composer.lock

Lines changed: 67 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pint.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"array_push": true,
5+
"assign_null_coalescing_to_coalesce_equal": true,
6+
"combine_consecutive_issets": true,
7+
"combine_consecutive_unsets": true,
8+
"concat_space": {
9+
"spacing": "one"
10+
},
11+
"declare_strict_types": true,
12+
"explicit_indirect_variable": true,
13+
"explicit_string_variable": true,
14+
"global_namespace_import": true,
15+
"method_argument_space": {
16+
"on_multiline": "ensure_fully_multiline"
17+
},
18+
"modernize_strpos": true,
19+
"modernize_types_casting": true,
20+
"new_with_braces": true,
21+
"no_superfluous_elseif": true,
22+
"no_useless_else": true,
23+
"nullable_type_declaration_for_default_null_value": true,
24+
"ordered_imports": {
25+
"sort_algorithm": "alpha"
26+
},
27+
"ordered_class_elements": {
28+
"order": [
29+
"use_trait",
30+
"case",
31+
"constant",
32+
"constant_public",
33+
"constant_protected",
34+
"constant_private",
35+
"property_public",
36+
"property_protected",
37+
"property_private",
38+
"construct",
39+
"destruct",
40+
"magic",
41+
"phpunit",
42+
"method_abstract",
43+
"method_public_static",
44+
"method_public",
45+
"method_protected_static",
46+
"method_protected",
47+
"method_private_static",
48+
"method_private"
49+
],
50+
"sort_algorithm": "none"
51+
},
52+
"strict_comparison": true,
53+
"ternary_to_null_coalescing": true,
54+
"use_arrow_functions": true
55+
}
56+
}

tests/Feature/CommandTest.php

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

3+
declare(strict_types=1);
4+
35
test('command "create" is correctly loaded', function () {
46
$app = getMinicli();
57
$app->runCommand(['minicli', 'create']);
6-
})->expectOutputRegex("/librarian create/");
8+
})->expectOutputRegex('/librarian create/');
79

810
test('command "create content" throws error if stencil_dir is not defined', function () {
911
$app = getMinicli();
1012
$app->runCommand(['minicli', 'create', 'content']);
11-
})->expectOutputRegex("/You must define a stencil_dir config option/");
13+
})->expectOutputRegex('/You must define a stencil_dir config option/');

tests/Pest.php

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

3+
declare(strict_types=1);
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Test Case
@@ -26,9 +28,7 @@
2628

2729
use Minicli\App;
2830

29-
expect()->extend('toBeOne', function () {
30-
return $this->toBe(1);
31-
});
31+
expect()->extend('toBeOne', fn () => $this->toBe(1));
3232

3333
/*
3434
|--------------------------------------------------------------------------
@@ -45,8 +45,8 @@ function getMinicli()
4545
{
4646
return new App([
4747
'app_path' => [
48-
__DIR__ . '/../Command'
48+
__DIR__ . '/../Command',
4949
],
50-
'debug' => true
50+
'debug' => true,
5151
]);
5252
}

tests/TestCase.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
namespace Tests;
46

57
use PHPUnit\Framework\TestCase as BaseTestCase;

0 commit comments

Comments
 (0)