Skip to content

Commit 3f1abad

Browse files
committed
feat: improve Docker command execution and enhance file analysis methods
1 parent e1e5a65 commit 3f1abad

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

phpinsights.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
use NunoMaduro\PhpInsights\Domain\Metrics\Code\Code;
1212
use NunoMaduro\PhpInsights\Domain\Metrics\Style\Style;
1313
use PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterNotSniff;
14+
use PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ScopeClosingBraceSniff;
1415
use PhpCsFixer\Fixer\Alias\ArrayPushFixer;
1516
use PhpCsFixer\Fixer\Alias\BacktickToShellExecFixer;
1617
use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer;
18+
use PhpCsFixer\Fixer\Basic\BracesFixer;
1719
use PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer;
20+
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
1821
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
1922
use PhpCsFixer\Fixer\ClassNotation\OrderedInterfacesFixer;
2023
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
@@ -30,8 +33,11 @@
3033
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
3134
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
3235
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
36+
use SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff;
37+
use SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff;
3338
use SlevomatCodingStandard\Sniffs\Commenting\UselessFunctionDocCommentSniff;
3439
use SlevomatCodingStandard\Sniffs\ControlStructures\DisallowEmptySniff;
40+
use SlevomatCodingStandard\Sniffs\Functions\FunctionLengthSniff;
3541
use SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff;
3642
use SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff;
3743
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
@@ -92,6 +98,7 @@
9298
'src/Console/Commands/',
9399
'src/HooksPipeline.php',
94100
'src/Git/Log.php',
101+
'src/Traits/ProcessHelper.php',
95102
'tests/Files/*WithFixableIssues.php',
96103
'tests/TestCase.php',
97104
],
@@ -127,26 +134,34 @@
127134

128135
'remove' => [
129136
AlphabeticallySortedUsesSniff::class,
137+
BracesFixer::class, // Let Pint handle brace formatting
138+
ClassDefinitionFixer::class, // Let Pint handle class definitions
130139
DeclareStrictTypesSniff::class, // We use DeclareStrictTypesFixer from PHP-CS-Fixer instead
131140
DisallowEmptySniff::class, // Allow using empty() function
132141
DisallowMixedTypeHintSniff::class,
142+
DisallowYodaComparisonSniff::class, // Allow normal comparisons
143+
DocCommentSpacingSniff::class, // Let Pint handle PHPDoc spacing
133144
ForbiddenDefineFunctions::class,
134145
ForbiddenNormalClasses::class,
135146
ForbiddenTraits::class,
147+
NewWithParenthesesFixer::class, // Disabled as per pint.json
148+
NotOperatorWithSuccessorSpaceFixer::class, // Disabled as per pint.json
136149
ParameterTypeHintSniff::class,
137150
PropertyTypeHintSniff::class,
138151
ReturnTypeHintSniff::class,
139-
UselessFunctionDocCommentSniff::class,
140-
NewWithParenthesesFixer::class, // Disabled as per pint.json
141-
NotOperatorWithSuccessorSpaceFixer::class, // Disabled as per pint.json
142-
DisallowYodaComparisonSniff::class, // Allow normal comparisons
152+
ScopeClosingBraceSniff::class, // Let Pint handle closing brace style
143153
SpaceAfterNotSniff::class, // Don't require space after NOT operator - Pint handles this
154+
SuperfluousExceptionNamingSniff::class, // Allow Exception suffix for exception classes
155+
UselessFunctionDocCommentSniff::class,
144156
],
145157

146158
'config' => [
147159
ForbiddenPrivateMethods::class => [
148160
'title' => 'The usage of private methods is not idiomatic in Laravel.',
149161
],
162+
FunctionLengthSniff::class => [
163+
'maxLinesLength' => 25, // Allow functions up to 25 lines
164+
],
150165
OrderedClassElementsFixer::class => [
151166
'order' => [
152167
'use_trait',

src/Traits/WithDockerSupport.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public function dockerCommand(string $command): string
4040
return $command;
4141
}
4242

43-
return 'docker exec '.escapeshellarg($this->dockerContainer).' sh -c '.escapeshellarg($command);
43+
$container = escapeshellarg($this->dockerContainer);
44+
$escapedCommand = escapeshellarg($command);
45+
46+
return "docker exec {$container} sh -c {$escapedCommand}";
4447
}
4548
}

src/Traits/WithFileAnalysis.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public function canFileBeAnalyzed(ChangedFile $file): bool
5656
*/
5757
protected function getAnalyzableFilePaths(Collection $files): array
5858
{
59-
return $files->filter(fn ($file) => $this->canFileBeAnalyzed($file))->map(fn ($file) => $file->getFilePath())->toArray();
59+
return $files
60+
->filter(fn ($file) => $this->canFileBeAnalyzed($file))
61+
->map(fn ($file) => $file->getFilePath())
62+
->toArray();
6063
}
6164

6265
/**
@@ -82,8 +85,10 @@ protected function analyzeFiles(array $filePaths): void
8285
}
8386
}
8487

85-
protected function handleAnalysisFailure(string $filePath, mixed $process): void
86-
{
88+
protected function handleAnalysisFailure(
89+
string $filePath,
90+
mixed $process
91+
): void {
8792
if (empty($this->filesBadlyFormattedPaths)) {
8893
$this->command->newLine();
8994
}
@@ -93,7 +98,10 @@ protected function handleAnalysisFailure(string $filePath, mixed $process): void
9398
);
9499
$this->filesBadlyFormattedPaths[] = $filePath;
95100

96-
if (config('git-hooks.output_errors') && !config('git-hooks.debug_output')) {
101+
$outputErrors = config('git-hooks.output_errors');
102+
$debugOutput = config('git-hooks.debug_output');
103+
104+
if ($outputErrors && !$debugOutput) {
97105
$this->command->newLine();
98106
$this->command->getOutput()->write($process->getOutput());
99107
}

src/Traits/WithPipeline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function startHookConsoleTask(): Closure
5454
return function (Hook $hook): void {
5555
$this->hookExecuting = $hook;
5656

57-
// Binding the Command instance to the Hook, so it can be used inside the Hook
57+
// Bind Command instance to Hook for internal use
5858
$hook->setCommand($this);
5959

6060
$taskTitle = $this->getHookTaskTitle($hook);

0 commit comments

Comments
 (0)