Skip to content

Commit 88714ae

Browse files
committed
Fixes coding standard violations
1 parent 0b7dbab commit 88714ae

28 files changed

Lines changed: 131 additions & 107 deletions

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"scripts": {
4747
"lpv:test": "phpunit",
4848
"lpv:test-with-coverage": "export XDEBUG_MODE=coverage && phpunit --coverage-html coverage-reports",
49+
"lpv:cs-fix-classic": "php-cs-fixer --allow-risky=yes fix . -vv || true",
4950
"lpv:cs-fix": "mago lint --fix",
5051
"lpv:cs-lint": "mago lint",
5152
"lpv:configure-commit-template": "git config --add commit.template .gitmessage",
@@ -75,6 +76,7 @@
7576
"require-dev": {
7677
"carthage-software/mago": "^1.18.0",
7778
"dg/bypass-finals": "^1.9",
79+
"friendsofphp/php-cs-fixer": "^3.95",
7880
"laravel/pao": "^1.0",
7981
"mockery/mockery": "^1.0",
8082
"peckphp/peck": "^0.3",

src/Analyser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class Analyser
1313
private AbstractExportIgnoreAnalyser $exportIgnoreAnalyser;
1414

1515
public function __construct(
16-
AbstractExportIgnoreAnalyser $actualExportIgnoreAnalyser) {
16+
AbstractExportIgnoreAnalyser $actualExportIgnoreAnalyser
17+
) {
1718
$this->exportIgnoreAnalyser = $actualExportIgnoreAnalyser;
1819
}
1920

src/Analysers/AbstractExportIgnoreAnalyser.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Stolt\LeanPackage\Exceptions\InvalidGlobPatternFile;
99
use Stolt\LeanPackage\Exceptions\NonExistentGlobPatternFile;
1010
use Stolt\LeanPackage\Exceptions\PresetNotAvailable;
11-
use Stolt\LeanPackage\Gitattributes\ValueObject as GitattributesValueObject;
1211
use Stolt\LeanPackage\Gitattributes\FileRepository as GitattributesFileRepository;
12+
use Stolt\LeanPackage\Gitattributes\ValueObject as GitattributesValueObject;
1313
use Stolt\LeanPackage\Glob;
1414
use Stolt\LeanPackage\Helpers\Str;
1515
use Stolt\LeanPackage\Presets\Finder;
@@ -158,20 +158,20 @@ public function __construct(
158158
protected readonly Finder $finder,
159159
protected readonly GitattributesFileRepository $gitattributesFileRepository,
160160
string $directory = '',
161-
?ExportIgnoreConfiguration $configuration = null)
162-
{
161+
?ExportIgnoreConfiguration $configuration = null
162+
) {
163163
$this->defaultGlobPattern = $finder->getDefaultPreset();
164164

165165
$configuration ??= new ExportIgnoreConfiguration(
166166
directory: $directory,
167-
globPattern: '{' . implode(',', $this->defaultGlobPattern) . '}*',
167+
globPattern: '{' . \implode(',', $this->defaultGlobPattern) . '}*',
168168
);
169169

170170
$this->configuration = $configuration;
171171

172172
$this->directory = $configuration->directory;
173173

174-
if (!is_dir($this->directory) && defined('WORKING_DIRECTORY')) {
174+
if (!\is_dir($this->directory) && \defined('WORKING_DIRECTORY')) {
175175
$this->directory = WORKING_DIRECTORY;
176176
}
177177

@@ -206,9 +206,9 @@ public function getDirectory(): string
206206
* Set the directory to analyse.
207207
*
208208
* @param string $directory The directory to analyse.
209-
* @return AbstractExportIgnoreAnalyser
210209
*
211210
* @throws RuntimeException
211+
* @return AbstractExportIgnoreAnalyser
212212
*/
213213
public function setDirectory(string $directory = __DIR__): AbstractExportIgnoreAnalyser
214214
{
@@ -358,8 +358,8 @@ public function isKeepReadmeEnabled(): bool
358358
* Sets the glob pattern for not export-ignoring license files.
359359
*
360360
* @param string $globPattern
361-
* @return AbstractExportIgnoreAnalyser
362361
* @throws InvalidGlobPattern
362+
* @return AbstractExportIgnoreAnalyser
363363
*/
364364
public function setKeepGlobPattern(string $globPattern): AbstractExportIgnoreAnalyser
365365
{
@@ -538,9 +538,9 @@ public function getGitattributesFileRepository(): GitattributesFileRepository
538538
* Set the glob pattern file.
539539
*
540540
* @param string $file
541-
* @return AbstractExportIgnoreAnalyser
542541
* @throws InvalidGlobPatternFile
543542
* @throws NonExistentGlobPatternFile
543+
* @return AbstractExportIgnoreAnalyser
544544
*/
545545
public function setGlobPatternFromFile(string $file): AbstractExportIgnoreAnalyser
546546
{
@@ -580,9 +580,9 @@ public function setGlobPatternFromFile(string $file): AbstractExportIgnoreAnalys
580580
*
581581
* @param string $pattern The glob pattern to use to detect expected export-ignores files.
582582
*
583-
* @return AbstractExportIgnoreAnalyser
584583
*
585584
* @throws InvalidGlobPattern
585+
* @return AbstractExportIgnoreAnalyser
586586
*/
587587
public function setGlobPattern(string $pattern): AbstractExportIgnoreAnalyser
588588
{
@@ -604,7 +604,7 @@ protected function guardGlobPattern(string $pattern): void
604604
$invalidGlobPattern = false;
605605

606606
if (\substr($pattern, 0) !== '{'
607-
&& (!str_ends_with($pattern, '}') && !str_ends_with($pattern, '}*'))) {
607+
&& (!\str_ends_with($pattern, '}') && !\str_ends_with($pattern, '}*'))) {
608608
$invalidGlobPattern = true;
609609
}
610610

@@ -645,11 +645,11 @@ protected function getGitignorePatterns(string $gitignoreFile): array
645645

646646
\array_filter($gitignoreLines, static function ($line) use (&$gitignoredPatterns) {
647647
$line = \trim($line);
648-
if ($line !== '' && !str_contains($line, '#')) {
649-
if (str_starts_with($line, "/")) {
648+
if ($line !== '' && !\str_contains($line, '#')) {
649+
if (\str_starts_with($line, "/")) {
650650
$gitignoredPatterns[] = \substr($line, 1);
651651
}
652-
if (str_ends_with($line, "/")) {
652+
if (\str_ends_with($line, "/")) {
653653
$gitignoredPatterns[] = \substr($line, 0, -1);
654654
}
655655
$gitignoredPatterns[] = $line;
@@ -679,9 +679,9 @@ public function getGitignoredPatterns(): array
679679
*/
680680
protected function patternHasMatch(string $globPattern): bool
681681
{
682-
if (str_starts_with(\trim($globPattern), '/')) {
682+
if (\str_starts_with(\trim($globPattern), '/')) {
683683
$globPattern = \trim(\substr($globPattern, 1));
684-
} elseif (str_ends_with(\trim($globPattern), '/')) {
684+
} elseif (\str_ends_with(\trim($globPattern), '/')) {
685685
$globPattern = \trim(\substr($globPattern, 0, -1));
686686
} else {
687687
$globPattern = '{' . \trim($globPattern) . '}*';
@@ -800,7 +800,7 @@ public function getPresentNonExportIgnoresContent(): string
800800
\array_filter($gitattributesLines, static function (string $line) use (
801801
&$nonExportIgnoreLines
802802
) {
803-
if (!str_contains($line, 'export-ignore') || \strstr($line, '#')) {
803+
if (!\str_contains($line, 'export-ignore') || \strstr($line, '#')) {
804804
$nonExportIgnoreLines[] = \trim($line);
805805
}
806806
});
@@ -823,7 +823,7 @@ public function getPresentNonExportIgnoresContent(): string
823823
&$exportIgnoresPlacementPlaceholderSet,
824824
&$exportIgnoresPlacementPlaceholder
825825
) {
826-
if (!str_contains($line, 'export-ignore') || \strstr($line, '#')) {
826+
if (!\str_contains($line, 'export-ignore') || \strstr($line, '#')) {
827827
return $nonExportIgnoreLines[] = \trim($line);
828828
} else {
829829
if ($exportIgnoresPlacementPlaceholderSet === false) {
@@ -854,8 +854,8 @@ protected function getAlignedExportIgnoreArtifacts(array $artifacts): array
854854
return \array_map(static function (string $artifact) use (&$longestArtifact) {
855855
if (\strlen($artifact) < $longestArtifact) {
856856
return $artifact . \str_repeat(
857-
' ',
858-
$longestArtifact - \strlen($artifact)
857+
' ',
858+
$longestArtifact - \strlen($artifact)
859859
);
860860
}
861861
return $artifact;
@@ -871,7 +871,7 @@ protected function getByDirectoriesToFilesExportIgnoreArtifacts(array $artifacts
871871
});
872872

873873
$files = \array_filter($artifacts, static function (string $artifact) {
874-
if (!str_contains($artifact, '/')) {
874+
if (!\str_contains($artifact, '/')) {
875875
return $artifact;
876876
}
877877
});

src/Analysers/ClassicExportIgnoreAnalyser.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace Stolt\LeanPackage\Analysers;
44

5-
use Stolt\LeanPackage\Glob;
6-
75
use Stolt\LeanPackage\Gitattributes\ValueObject as GitattributesValueObject;
86

7+
use Stolt\LeanPackage\Glob;
8+
99
final class ClassicExportIgnoreAnalyser extends AbstractExportIgnoreAnalyser
1010
{
1111
public const EXPORT_IGNORE_CLASSIC = 'classic';
@@ -159,15 +159,15 @@ public function getPresentExportIgnores(bool $applyGlob = true, string $gitattri
159159
list($line, $void) = \explode('export-ignore', $line);
160160
if ($applyGlob) {
161161
if ($this->patternHasMatch(\trim($line))) {
162-
if (str_starts_with($line, '/')) {
162+
if (\str_starts_with($line, '/')) {
163163
$line = \substr($line, 1);
164164
}
165165

166166
return $exportIgnores[] = \trim($line);
167167
}
168168
} else {
169169
if ($this->patternHasMatch(\trim($line))) {
170-
if (str_starts_with($line, '/')) {
170+
if (\str_starts_with($line, '/')) {
171171
$line = \substr($line, 1);
172172
}
173173

@@ -190,11 +190,11 @@ public function getGitattributesContentToBe(array $postfixLessExportIgnores = []
190190
{
191191
$collectExpectedExportIgnores = $this->collectExpectedExportIgnores();
192192

193-
if (count($postfixLessExportIgnores) === 1 && $postfixLessExportIgnores[0] === '.gitattributes' && count($collectExpectedExportIgnores) === 0) {
193+
if (\count($postfixLessExportIgnores) === 1 && $postfixLessExportIgnores[0] === '.gitattributes' && \count($collectExpectedExportIgnores) === 0) {
194194
$postfixLessExportIgnores = [];
195195
}
196196

197-
$postfixLessExportIgnores = array_unique(array_merge($collectExpectedExportIgnores, $postfixLessExportIgnores));
197+
$postfixLessExportIgnores = \array_unique(\array_merge($collectExpectedExportIgnores, $postfixLessExportIgnores));
198198

199199
\sort($postfixLessExportIgnores, SORT_STRING | SORT_FLAG_CASE);
200200

src/Analysers/ExportIgnoreConfiguration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public function __construct(
1414
public string $keepGlobPattern = '',
1515
public bool $alignExportIgnores = false,
1616
public bool $enforceStrictOrderComparison = false,
17-
) {}
17+
) {
18+
}
1819

1920
public function withDirectory(string $directory): self
2021
{

src/Analysers/NegatedExportIgnoreAnalyser.php

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function collectExpectedExportIgnores(): array
1313
{
1414
$expectedNegatedExportIgnores = [];
1515

16-
if (!is_dir($this->getDirectory())) {
16+
if (!\is_dir($this->getDirectory())) {
1717
throw new \RuntimeException("Directory {$this->getDirectory()} doesn't exist.");
1818
}
1919

@@ -41,11 +41,11 @@ public function collectExpectedExportIgnores(): array
4141

4242
$allFiles = Glob::glob('{*}', Glob::GLOB_BRACE);
4343

44-
if (!\is_array($allFiles) || count ($allFiles) === 0) {
44+
if (!\is_array($allFiles) || \count($allFiles) === 0) {
4545
return $expectedNegatedExportIgnores;
4646
}
4747

48-
return array_diff($allFiles, $globMatches);
48+
return \array_diff($allFiles, $globMatches);
4949
}
5050

5151
public function getGitattributesContentToBe(array $postfixLessExportIgnores = []): GitattributesValueObject
@@ -142,7 +142,7 @@ private function expandBinaryDirectories(array $entries): array
142142
foreach ($entries as $entry) {
143143
$expanded[] = $entry;
144144

145-
if (!str_ends_with($entry, 'bin' . DIRECTORY_SEPARATOR)) {
145+
if (!\str_ends_with($entry, 'bin' . DIRECTORY_SEPARATOR)) {
146146
continue;
147147
}
148148

@@ -172,32 +172,36 @@ public function hasDoubleStarForDirectories(array $negatedEntries): bool
172172
$lookup = \array_flip($negatedEntries);
173173

174174
foreach ($negatedEntries as $entry) {
175-
if (!(\str_ends_with($entry, '/'))) { continue; }
175+
if (!(\str_ends_with($entry, '/'))) {
176+
continue;
177+
}
176178

177-
$directory = \rtrim($entry, '/');
178-
$expected = $directory . '/**';
179+
$directory = \rtrim($entry, '/');
180+
$expected = $directory . '/**';
179181

180-
$hasDirectFileEntry = false;
182+
$hasDirectFileEntry = false;
181183

182-
foreach ($negatedEntries as $candidate) {
183-
if (
184-
!(\str_starts_with($candidate, $directory . '/')
185-
&& !\str_ends_with($candidate, '/')
186-
&& $candidate !== $expected)
187-
) { continue; }
184+
foreach ($negatedEntries as $candidate) {
185+
if (
186+
!(\str_starts_with($candidate, $directory . '/')
187+
&& !\str_ends_with($candidate, '/')
188+
&& $candidate !== $expected)
189+
) {
190+
continue;
191+
}
188192

189-
$hasDirectFileEntry = true;
193+
$hasDirectFileEntry = true;
190194

191-
break;
192-
}
195+
break;
196+
}
193197

194-
if ($hasDirectFileEntry) {
195-
continue;
196-
}
198+
if ($hasDirectFileEntry) {
199+
continue;
200+
}
197201

198-
if (!isset($lookup[$expected])) {
199-
return false;
200-
}
202+
if (!isset($lookup[$expected])) {
203+
return false;
204+
}
201205
}
202206

203207
return true;
@@ -218,11 +222,11 @@ private function buildExportIgnoreContent(array $entries): string
218222
$lines = \array_map(
219223
static function (string $entry) use ($maxLength, $suffix): string {
220224
return \str_pad(
221-
$entry,
222-
$maxLength,
223-
' ',
224-
STR_PAD_RIGHT
225-
) . $suffix;
225+
$entry,
226+
$maxLength,
227+
' ',
228+
STR_PAD_RIGHT
229+
) . $suffix;
226230
},
227231
$entries
228232
);

src/Archive.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,28 @@ public function compareArchive(array $unexpectedArtifacts): array
166166
$hasLicenseFile = false;
167167

168168
foreach ($archive as $archiveFile) {
169-
if (!($archiveFile instanceof \SplFileInfo)) { continue; }
170-
171-
if ($archiveFile->isDir()) {
172-
$file = $archiveFile->getFilename() . '/';
173-
if (\in_array($file, $unexpectedArtifacts, strict: true)) {
174-
$foundUnexpectedArtifacts[] = $file;
175-
}
176-
continue;
177-
}
178-
179-
$file = $archiveFile->getFilename();
180-
if ($this->validateLicenseFilePresence()) {
181-
if (\preg_match('/(License.*)/i', $file)) {
182-
$hasLicenseFile = true;
183-
}
184-
}
169+
if (!($archiveFile instanceof \SplFileInfo)) {
170+
continue;
171+
}
185172

173+
if ($archiveFile->isDir()) {
174+
$file = $archiveFile->getFilename() . '/';
186175
if (\in_array($file, $unexpectedArtifacts, strict: true)) {
187176
$foundUnexpectedArtifacts[] = $file;
188177
}
178+
continue;
179+
}
180+
181+
$file = $archiveFile->getFilename();
182+
if ($this->validateLicenseFilePresence()) {
183+
if (\preg_match('/(License.*)/i', $file)) {
184+
$hasLicenseFile = true;
185+
}
186+
}
187+
188+
if (\in_array($file, $unexpectedArtifacts, strict: true)) {
189+
$foundUnexpectedArtifacts[] = $file;
190+
}
189191
}
190192

191193
if ($this->validateLicenseFilePresence() && $hasLicenseFile === false) {

src/Commands/CreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use Stolt\LeanPackage\Analyser;
88
use Stolt\LeanPackage\Analysers\ClassicExportIgnoreAnalyser;
9+
use Stolt\LeanPackage\Analysers\NegatedExportIgnoreAnalyser;
910
use Stolt\LeanPackage\Commands\Concerns\GeneratesGitattributesOptions;
1011
use Stolt\LeanPackage\Commands\Concerns\OutputOptions;
1112
use Stolt\LeanPackage\Gitattributes\FileRepository as GitattributesFileRepository;
12-
use Stolt\LeanPackage\Analysers\NegatedExportIgnoreAnalyser;
1313
use Symfony\Component\Console\Command\Command;
1414
use Symfony\Component\Console\Input\InputArgument;
1515
use Symfony\Component\Console\Input\InputInterface;

0 commit comments

Comments
 (0)