Skip to content

Commit 586c33b

Browse files
author
cradu
committed
Added option for validate_paths
1 parent 80962dd commit 586c33b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

config/git-hooks.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@
254254
*/
255255
'artisan_path' => base_path('artisan'),
256256

257+
/*
258+
|--------------------------------------------------------------------------
259+
| Validate paths
260+
|--------------------------------------------------------------------------
261+
|
262+
| This configuration option allows you enable (or not) validation
263+
| of paths. This can be useful when binary files are not part of the
264+
| project directly.
265+
|
266+
*/
267+
'validate_paths' => env('GITHOOKS_VALIDATE_PATHS', true),
268+
257269
/*
258270
|--------------------------------------------------------------------------
259271
| Output errors

src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function setFileExtensions(array|string $fileExtensions): self
135135

136136
public function setAnalyzerExecutable(string $executablePath, bool $isSameAsFixer = false): self
137137
{
138-
$this->analyzerExecutable = './'.trim($executablePath, '/');
138+
$this->analyzerExecutable = $executablePath;
139139

140140
return $isSameAsFixer ? $this->setFixerExecutable($executablePath) : $this;
141141
}
@@ -147,7 +147,7 @@ public function getAnalyzerExecutable(): string
147147

148148
public function setFixerExecutable(string $executablePath): self
149149
{
150-
$this->fixerExecutable = './'.trim($executablePath, '/');
150+
$this->fixerExecutable = $executablePath;
151151

152152
return $this;
153153
}
@@ -274,7 +274,7 @@ protected function commitFailMessage(): self
274274
*/
275275
protected function validateAnalyzerInstallation(): self
276276
{
277-
if (file_exists($this->analyzerExecutable)) {
277+
if (! config('git-hooks.validate_paths') || file_exists($this->analyzerExecutable)) {
278278
return $this;
279279
}
280280

@@ -297,7 +297,7 @@ protected function validateAnalyzerInstallation(): self
297297
*/
298298
protected function validateConfigPath(string $path): self
299299
{
300-
if (file_exists($path)) {
300+
if (! config('git-hooks.validate_paths') || file_exists($path)) {
301301
return $this;
302302
}
303303

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function defineEnvironment($app): void
5252
'code_analyzers' => [],
5353
'artisan_path' => base_path('artisan'),
5454
'output_errors' => false,
55+
'validate_paths' => true,
5556
'automatically_fix_errors' => false,
5657
'rerun_analyzer_after_autofix' => false,
5758
'stop_at_first_analyzer_failure' => true,

0 commit comments

Comments
 (0)