Skip to content

Commit a180b12

Browse files
More rector and pint rules (PER code style guide) (#7)
1 parent 1021615 commit a180b12

15 files changed

Lines changed: 110 additions & 61 deletions

config/config.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
* You can place your custom package configuration in here.
57
*/

pint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"preset": "per",
3+
"rules": {
4+
"increment_style": false
5+
},
6+
"exclude": [
7+
"vendor",
8+
"storage"
9+
]
10+
}

rector.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66

77
return RectorConfig::configure()
88
->withPaths([
9-
__DIR__.'/config',
10-
__DIR__.'/src',
9+
__DIR__ . '/config',
10+
__DIR__ . '/src',
1111
])
1212
->withPhpSets(
13-
php83: true
13+
php83: true,
1414
)
1515
->withPreparedSets(
1616
deadCode: true,
1717
codeQuality: true,
1818
codingStyle: true,
1919
typeDeclarations: true,
20-
earlyReturn: true
20+
earlyReturn: true,
21+
instanceOf: true,
22+
strictBooleans: true,
23+
carbon: true,
24+
rectorPreset: true,
25+
phpunitCodeQuality: true,
2126
);

src/Console/Commands/CheckMarkdown.php

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

3+
declare(strict_types=1);
4+
35
namespace HiFolks\Fusion\Console\Commands;
46

57
use Illuminate\Console\Command;
@@ -27,24 +29,24 @@ public function handle(): int
2729
{
2830

2931
$this->output->title('Parsing the Markdown Files');
30-
$filesystem = new FileSystem;
32+
$filesystem = new FileSystem();
3133
$contentDirectory = $this->option('dir');
3234
if (is_null($contentDirectory)) {
3335
$contentDirectory = resource_path('content');
3436
}
3537

3638
if (! is_dir($contentDirectory)) {
37-
$this->warn(' The directory `'.$contentDirectory."` doesn't exist.");
39+
$this->warn(' The directory `' . $contentDirectory . "` doesn't exist.");
3840
$this->newLine();
39-
$this->info(' You should create the directory `'.$contentDirectory.'` and start creating Markdown files in that directory.');
41+
$this->info(' You should create the directory `' . $contentDirectory . '` and start creating Markdown files in that directory.');
4042
$this->newLine();
4143
$this->output->listing(
4244
[
43-
'Create the `'.$contentDirectory.'` directory;',
44-
'Create the content type directory, for example `'.$contentDirectory.'/article`',
45+
'Create the `' . $contentDirectory . '` directory;',
46+
'Create the content type directory, for example `' . $contentDirectory . '/article`',
4547
'Create the Markdown files in the new directory;',
4648
'Execute the `php artisan fusion:sync` command for generating the model.',
47-
]
49+
],
4850
);
4951

5052
return Command::INVALID;
@@ -64,15 +66,15 @@ public function handle(): int
6466

6567
$object = YamlFrontMatter::parse($fileContent);
6668
if ($extension == 'md') {
67-
$numberMarkdown++;
68-
$this->components->twoColumnDetail(' - '.$filename, implode('; ', array_keys($object->matter())));
69+
++$numberMarkdown;
70+
$this->components->twoColumnDetail(' - ' . $filename, implode('; ', array_keys($object->matter())));
6971
} else {
70-
$numberNoMarkdown++;
72+
++$numberNoMarkdown;
7173
}
7274
}
7375

7476
if ($numberMarkdown === 0) {
75-
$this->warn('No Markdown files in '.$directory);
77+
$this->warn('No Markdown files in ' . $directory);
7678
}
7779

7880
if ($numberNoMarkdown > 0) {

src/Console/Commands/CheckModel.php

Lines changed: 20 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
namespace HiFolks\Fusion\Console\Commands;
46

57
use HiFolks\Fusion\Models\FusionBaseModel;
@@ -36,36 +38,42 @@ public function handle(): int
3638

3739
if (class_exists($model)) {
3840
$this->components->twoColumnDetail(
39-
'<info>'.$model.'</info>',
40-
'<info>Exists</info>');
41+
'<info>' . $model . '</info>',
42+
'<info>Exists</info>',
43+
);
4144

4245
} else {
4346
$this->components->twoColumnDetail(
44-
'<info>'.$model.'</info>',
45-
"<error>Doesn't exist</error>");
47+
'<info>' . $model . '</info>',
48+
"<error>Doesn't exist</error>",
49+
);
4650

4751
return Command::INVALID;
4852
}
4953

5054
if (is_subclass_of($model, FusionBaseModel::class)) {
5155
$this->components->twoColumnDetail(
52-
'<info>'.$model.'</info>',
53-
'<info>Extends correctly the class '.FusionBaseModel::class.'</info>');
56+
'<info>' . $model . '</info>',
57+
'<info>Extends correctly the class ' . FusionBaseModel::class . '</info>',
58+
);
5459

5560
} else {
5661
$this->components->twoColumnDetail(
57-
'<info>'.$model.'</info>',
58-
'<error>Does not extend correctly the class '.FusionBaseModel::class.'</error>');
62+
'<info>' . $model . '</info>',
63+
'<error>Does not extend correctly the class ' . FusionBaseModel::class . '</error>',
64+
);
5965
}
6066

6167
if (trait_exists(FusionModelTrait::class) && in_array(FusionModelTrait::class, class_uses($model))) {
6268
$this->components->twoColumnDetail(
63-
'<info>'.$model.'</info>',
64-
'<info>Uses correctly the trait '.FusionModelTrait::class.'</info>');
69+
'<info>' . $model . '</info>',
70+
'<info>Uses correctly the trait ' . FusionModelTrait::class . '</info>',
71+
);
6572
} else {
6673
$this->components->twoColumnDetail(
67-
'<info>'.$model.'</info>',
68-
'<error>Does not use correctly the trait '.FusionModelTrait::class.'</error>');
74+
'<info>' . $model . '</info>',
75+
'<error>Does not use correctly the trait ' . FusionModelTrait::class . '</error>',
76+
);
6977

7078
}
7179

src/Console/Commands/SyncModel.php

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

3+
declare(strict_types=1);
4+
35
namespace HiFolks\Fusion\Console\Commands;
46

57
use Illuminate\Console\Command;
@@ -63,13 +65,15 @@ public function handle(): ?bool
6365

6466
$this->components->twoColumnDetail(
6567
'Parsing the Markdown Directory',
66-
sprintf('<info>%s</info>', $markdownPath));
68+
sprintf('<info>%s</info>', $markdownPath),
69+
);
6770

6871
$modelName = basename($markdownPath);
6972

7073
$this->components->twoColumnDetail(
7174
'Folder Markdown Name',
72-
sprintf('<info>%s</info>', $modelName));
75+
sprintf('<info>%s</info>', $modelName),
76+
);
7377

7478
if (! is_dir($markdownPath)) {
7579
$this->error(sprintf('The Folder %s does not exist!', $markdownPath));
@@ -78,7 +82,7 @@ public function handle(): ?bool
7882
// return Command::INVALID;
7983
}
8084

81-
$filesystem = new FileSystem;
85+
$filesystem = new FileSystem();
8286

8387
$collectedFields = [];
8488
foreach (File::files($markdownPath) as $file) {
@@ -92,49 +96,55 @@ public function handle(): ?bool
9296
$collectedFields = array_unique(
9397
array_merge(
9498
$collectedFields,
95-
array_keys($object->matter())
96-
)
99+
array_keys($object->matter()),
100+
),
97101
);
98102

99103
}
100104

101105
$this->modelName = Str::studly($modelName);
102106
$this->components->twoColumnDetail(
103107
'Model Name',
104-
sprintf('<info>%s</info>', $this->modelName));
108+
sprintf('<info>%s</info>', $this->modelName),
109+
);
105110
$className = $this->qualifyClass($this->getNameInput());
106111
$path = $this->getPath($className);
107112
$this->components->twoColumnDetail(
108113
'Model Name (with Namespace)',
109-
sprintf('<info>%s</info>', $className));
114+
sprintf('<info>%s</info>', $className),
115+
);
110116
$this->components->twoColumnDetail(
111117
'Model path',
112-
sprintf('<info>%s</info>', $path));
118+
sprintf('<info>%s</info>', $path),
119+
);
113120
if (is_file($path)) {
114121
$this->components->twoColumnDetail(
115122
'Check file',
116-
'<info>File exists</info>');
123+
'<info>File exists</info>',
124+
);
117125
} else {
118126
$this->components->twoColumnDetail(
119127
'Check file',
120-
'<fg=yellow>Does NOT exists</>');
128+
'<fg=yellow>Does NOT exists</>',
129+
);
121130
}
122131

123132
$this->output->newLine();
124133
if ($collectedFields === []) {
125134
$this->components->twoColumnDetail(
126135
'Frontmatter fields',
127-
sprintf('<fg=yellow>NO frontmatter fields found in %s path</>', $markdownPath));
136+
sprintf('<fg=yellow>NO frontmatter fields found in %s path</>', $markdownPath),
137+
);
128138

129139
} else {
130-
$this->frontmatterFields = '"'.implode('","', $collectedFields).'"';
140+
$this->frontmatterFields = '"' . implode('","', $collectedFields) . '"';
131141
$this->components->twoColumnDetail(
132142
'In the frontmatterFields() method you have to return:',
133-
''
143+
'',
134144
);
135145
$this->components->twoColumnDetail(
136146
'',
137-
$this->frontmatterFields
147+
$this->frontmatterFields,
138148
);
139149

140150
}
@@ -150,15 +160,15 @@ public function handle(): ?bool
150160

151161
protected function getNameInput()
152162
{
153-
return '\\App\\Models\\'.$this->modelName;
163+
return '\\App\\Models\\' . $this->modelName;
154164
}
155165

156166
protected function getStub()
157167
{
158168
return realpath(
159-
__DIR__.
160-
'/../../..'.
161-
'/stubs/app/Models/BasicFusionTemplateModel.stub'
169+
__DIR__
170+
. '/../../..'
171+
. '/stubs/app/Models/BasicFusionTemplateModel.stub',
162172
);
163173
}
164174

@@ -167,7 +177,7 @@ protected function replaceClass($stub, $name)
167177
$stub = str_replace(
168178
'{{ fields }}',
169179
$this->frontmatterFields,
170-
$stub
180+
$stub,
171181
);
172182

173183
return parent::replaceClass($stub, $name);

src/Fusion.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 HiFolks\Fusion;
46

57
class Fusion {}

src/FusionFacade.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 HiFolks\Fusion;
46

57
use Illuminate\Support\Facades\Facade;

src/FusionServiceProvider.php

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

3+
declare(strict_types=1);
4+
35
namespace HiFolks\Fusion;
46

57
use HiFolks\Fusion\Console\Commands\CheckMarkdown;
@@ -24,7 +26,7 @@ public function boot(): void
2426

2527
if ($this->app->runningInConsole()) {
2628
$this->publishes([
27-
__DIR__.'/../config/config.php' => config_path('fusion.php'),
29+
__DIR__ . '/../config/config.php' => config_path('fusion.php'),
2830
], 'config');
2931

3032
// Publishing the views.
@@ -57,9 +59,9 @@ public function boot(): void
5759
public function register(): void
5860
{
5961
// Automatically apply the package configuration
60-
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'fusion');
62+
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'fusion');
6163

6264
// Register the main class to use with the facade
63-
$this->app->singleton('fusion', static fn (): \HiFolks\Fusion\Fusion => new Fusion);
65+
$this->app->singleton('fusion', static fn(): \HiFolks\Fusion\Fusion => new Fusion());
6466
}
6567
}

0 commit comments

Comments
 (0)