Skip to content

Commit 99a3808

Browse files
committed
wip pint fixes
1 parent 31ed4d0 commit 99a3808

File tree

7 files changed

+19
-33
lines changed

7 files changed

+19
-33
lines changed

src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ abstract class BaseCodeAnalyzerPreCommitHook
2929

3030
/**
3131
* The path to the analyzer executable.
32+
*
3233
* @var string
3334
*/
3435
protected $analyzerExecutable;
3536

3637
/**
3738
* The path to the fixer executable. In multiple cases it's the same of the analyzer executable.
39+
*
3840
* @var string
3941
*/
4042
protected $fixerExecutable;
4143

4244
/**
4345
* The list of paths of files that are badly formatted and should be fixed.
46+
*
4447
* @var array
4548
*/
4649
protected $filesBadlyFormattedPaths = [];
@@ -87,7 +90,7 @@ public function handleCommittedFiles(ChangedFiles $files, Closure $next)
8790
protected function analizeCommittedFiles($commitFiles)
8891
{
8992
foreach ($commitFiles as $file) {
90-
if (!in_array($file->extension(), $this->fileExtensions)) {
93+
if (! in_array($file->extension(), $this->fileExtensions)) {
9194
continue;
9295
}
9396

@@ -96,7 +99,7 @@ protected function analizeCommittedFiles($commitFiles)
9699

97100
$isProperlyFormatted = $this->runCommands($command)->isSuccessful();
98101

99-
if (!$isProperlyFormatted) {
102+
if (! $isProperlyFormatted) {
100103
if (empty($this->filesBadlyFormattedPaths)) {
101104
$this->command->newLine();
102105
}
@@ -113,6 +116,7 @@ protected function analizeCommittedFiles($commitFiles)
113116

114117
/**
115118
* Returns the message to display when the commit fails.
119+
*
116120
* @return $this
117121
*/
118122
protected function commitFailMessage()
@@ -131,6 +135,7 @@ protected function commitFailMessage()
131135
* Check if the BaseCodeAnalyzerPreCommitHook is installed.
132136
*
133137
* @return $this
138+
*
134139
* @throws HookFailException
135140
*/
136141
protected function checkAnalyzerInstallation()
@@ -153,6 +158,7 @@ protected function checkAnalyzerInstallation()
153158
* Suggests attempting to automatically fix the incorrectly formatted files or exit.
154159
*
155160
* @return void
161+
*
156162
* @throws HookFailException
157163
*/
158164
protected function suggestAutoFixOrExit()
@@ -164,7 +170,7 @@ protected function suggestAutoFixOrExit()
164170

165171
$this->runCommands([
166172
$this->fixerCommand().' '.$errorFilesString,
167-
'git add '.$errorFilesString
173+
'git add '.$errorFilesString,
168174
]);
169175
} else {
170176
throw new HookFailException();
@@ -178,11 +184,11 @@ protected function suggestAutoFixOrExit()
178184
public function setFileExtensions($fileExtensions)
179185
{
180186
$this->fileExtensions = (array) $fileExtensions;
187+
181188
return $this;
182189
}
183190

184191
/**
185-
* @param $executablePath
186192
* @return BaseCodeAnalyzerPreCommitHook
187193
*/
188194
public function setAnalyzerExecutable($executablePath, $isSameAsFixer = false)
@@ -192,27 +198,21 @@ public function setAnalyzerExecutable($executablePath, $isSameAsFixer = false)
192198
return $isSameAsFixer ? $this->setFixerExecutable($executablePath) : $this;
193199
}
194200

195-
/**
196-
* @return string
197-
*/
198201
public function getAnalyzerExecutable(): string
199202
{
200203
return $this->analyzerExecutable;
201204
}
202205

203206
/**
204-
* @param $exacutablePath
205207
* @return BaseCodeAnalyzerPreCommitHook
206208
*/
207209
public function setFixerExecutable($exacutablePath)
208210
{
209211
$this->fixerExecutable = './'.trim($exacutablePath, '/');
212+
210213
return $this;
211214
}
212215

213-
/**
214-
* @return string
215-
*/
216216
public function getFixerExecutable(): string
217217
{
218218
return $this->fixerExecutable;

src/Console/Commands/Hooks/PHPCodeSnifferPreCommitHook.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class PHPCodeSnifferPreCommitHook extends BaseCodeAnalyzerPreCommitHook implemen
1515

1616
/**
1717
* Get the name of the hook.
18-
* @return string|null
1918
*/
2019
public function getName(): ?string
2120
{
@@ -27,7 +26,6 @@ public function getName(): ?string
2726
*
2827
* @param ChangedFiles $files The files that have been changed in the current commit.
2928
* @param Closure $next A closure that represents the next middleware in the pipeline.
30-
*
3129
* @return mixed|null
3230
*/
3331
public function handle(ChangedFiles $files, Closure $next)
@@ -42,8 +40,6 @@ public function handle(ChangedFiles $files, Closure $next)
4240

4341
/**
4442
* Returns the command to run PHPCS
45-
*
46-
* @return string
4743
*/
4844
public function analyzerCommand(): string
4945
{
@@ -52,8 +48,6 @@ public function analyzerCommand(): string
5248

5349
/**
5450
* Returns the command to run PHPCS
55-
*
56-
* @return string
5751
*/
5852
public function fixerCommand(): string
5953
{
@@ -70,6 +64,7 @@ public function fixerCommand(): string
7064
public function analyzerConfigParam(): string
7165
{
7266
$phpCSStandard = trim(config('git-hooks.code_analyzers.php_code_sniffer.standard'), '/');
67+
7368
return empty($phpCSStandard) ? '' : '--standard='.$phpCSStandard;
7469
}
7570
}

src/Console/Commands/Hooks/PintPreCommitHook.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class PintPreCommitHook extends BaseCodeAnalyzerPreCommitHook implements CodeAna
1515

1616
/**
1717
* Get the name of the hook.
18-
* @return string|null
1918
*/
2019
public function getName(): ?string
2120
{
@@ -27,7 +26,6 @@ public function getName(): ?string
2726
*
2827
* @param ChangedFiles $files The files that have been changed in the current commit.
2928
* @param Closure $next A closure that represents the next middleware in the pipeline.
30-
*
3129
* @return mixed|null
3230
*/
3331
public function handle(ChangedFiles $files, Closure $next)
@@ -41,8 +39,6 @@ public function handle(ChangedFiles $files, Closure $next)
4139

4240
/**
4341
* Returns the command to run Pint tester
44-
*
45-
* @return string
4642
*/
4743
public function analyzerCommand(): string
4844
{
@@ -51,8 +47,6 @@ public function analyzerCommand(): string
5147

5248
/**
5349
* Returns the command to run Pint fixer
54-
*
55-
* @return string
5650
*/
5751
public function fixerCommand(): string
5852
{
@@ -68,11 +62,12 @@ protected function analyzerConfigParam(): string
6862
{
6963
$pintConfigFile = config('git-hooks.code_analyzers.laravel_pint.config');
7064

71-
if (!empty($pintConfigFile)) {
65+
if (! empty($pintConfigFile)) {
7266
return '--config '.trim($pintConfigFile, '/');
7367
}
7468

7569
$pintPreset = config('git-hooks.code_analyzers.laravel_pint.preset');
70+
7671
return empty($pintPreset) ? '' : '--preset '.trim($pintPreset, '/');
7772
}
7873
}

src/Contracts/CodeAnalyzerPreCommitHook.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ interface CodeAnalyzerPreCommitHook extends PreCommitHook
77
/**
88
* Returns the command to run the code analyzer/tester.
99
* i.e: Command to execute PHPCS
10-
*
11-
* @return string
1210
*/
1311
public function analyzerCommand(): string;
1412

1513
/**
1614
* Returns the command to run the code fixer.
1715
* i.e: Command to execute PHPCBF
18-
*
19-
* @return string
2016
*/
2117
public function fixerCommand(): string;
2218
}

src/Git/ChangedFiles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function getFiles(): Collection
3232

3333
/**
3434
* Get list of staged files
35+
*
3536
* @return Collection|ChangedFile[]
3637
*/
3738
public function getStaged(): Collection

src/Traits/ProcessHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ public function buildNoOutputCommand($command = '')
9595
}
9696

9797
/**
98-
* @param string $cwd
98+
* @param string $cwd
9999
* @return $this
100100
*/
101101
public function setCwd($cwd)
102102
{
103103
$this->cwd = $cwd;
104+
104105
return $this;
105106
}
106107
}

tests/Features/Commands/Hooks/PintPreCommitHookTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
test('Fails commit when Pint is not passing and user does not autofix the files', function ($listOfFixableFiles) {
6060
$this->config->set('git-hooks.code_analyzers.laravel_pint', [
6161
'path' => '../../../bin/pint',
62-
'preset' => 'psr12'
62+
'preset' => 'psr12',
6363
]);
6464
$this->config->set('git-hooks.pre-commit', [
6565
PintPreCommitHook::class,
@@ -77,13 +77,12 @@
7777
->expectsOutputToContain('COMMIT FAILED')
7878
->expectsConfirmation('Would you like to attempt to correct files automagically?', 'no')
7979
->assertExitCode(1);
80-
8180
})->with('listOfFixableFiles');
8281

8382
test('Commit passes when Pint fixes fix the files', function ($listOfFixableFiles) {
8483
$this->config->set('git-hooks.code_analyzers.laravel_pint', [
8584
'path' => '../../../bin/pint',
86-
'preset' => 'psr12'
85+
'preset' => 'psr12',
8786
]);
8887
$this->config->set('git-hooks.pre-commit', [
8988
PintPreCommitHook::class,
@@ -104,5 +103,4 @@
104103
$this->artisan('git-hooks:pre-commit')
105104
->doesntExpectOutputToContain('Pint Failed')
106105
->assertSuccessful();
107-
108106
})->with('listOfFixableFiles');

0 commit comments

Comments
 (0)