Skip to content

Commit 8889a2c

Browse files
committed
Fixes coding standard violations
1 parent 0b7dbab commit 8889a2c

28 files changed

Lines changed: 132 additions & 108 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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
namespace Stolt\LeanPackage\Analysers;
44

55
use RuntimeException;
6-
use Stolt\LeanPackage\Analyser;
76
use Stolt\LeanPackage\Exceptions\InvalidGlobPattern;
87
use Stolt\LeanPackage\Exceptions\InvalidGlobPatternFile;
98
use Stolt\LeanPackage\Exceptions\NonExistentGlobPatternFile;
109
use Stolt\LeanPackage\Exceptions\PresetNotAvailable;
11-
use Stolt\LeanPackage\Gitattributes\ValueObject as GitattributesValueObject;
1210
use Stolt\LeanPackage\Gitattributes\FileRepository as GitattributesFileRepository;
11+
use Stolt\LeanPackage\Gitattributes\ValueObject as GitattributesValueObject;
1312
use Stolt\LeanPackage\Glob;
1413
use Stolt\LeanPackage\Helpers\Str;
1514
use Stolt\LeanPackage\Presets\Finder;
@@ -158,20 +157,20 @@ public function __construct(
158157
protected readonly Finder $finder,
159158
protected readonly GitattributesFileRepository $gitattributesFileRepository,
160159
string $directory = '',
161-
?ExportIgnoreConfiguration $configuration = null)
162-
{
160+
?ExportIgnoreConfiguration $configuration = null
161+
) {
163162
$this->defaultGlobPattern = $finder->getDefaultPreset();
164163

165164
$configuration ??= new ExportIgnoreConfiguration(
166165
directory: $directory,
167-
globPattern: '{' . implode(',', $this->defaultGlobPattern) . '}*',
166+
globPattern: '{' . \implode(',', $this->defaultGlobPattern) . '}*',
168167
);
169168

170169
$this->configuration = $configuration;
171170

172171
$this->directory = $configuration->directory;
173172

174-
if (!is_dir($this->directory) && defined('WORKING_DIRECTORY')) {
173+
if (!\is_dir($this->directory) && \defined('WORKING_DIRECTORY')) {
175174
$this->directory = WORKING_DIRECTORY;
176175
}
177176

@@ -206,9 +205,9 @@ public function getDirectory(): string
206205
* Set the directory to analyse.
207206
*
208207
* @param string $directory The directory to analyse.
209-
* @return AbstractExportIgnoreAnalyser
210208
*
211209
* @throws RuntimeException
210+
* @return AbstractExportIgnoreAnalyser
212211
*/
213212
public function setDirectory(string $directory = __DIR__): AbstractExportIgnoreAnalyser
214213
{
@@ -358,8 +357,8 @@ public function isKeepReadmeEnabled(): bool
358357
* Sets the glob pattern for not export-ignoring license files.
359358
*
360359
* @param string $globPattern
361-
* @return AbstractExportIgnoreAnalyser
362360
* @throws InvalidGlobPattern
361+
* @return AbstractExportIgnoreAnalyser
363362
*/
364363
public function setKeepGlobPattern(string $globPattern): AbstractExportIgnoreAnalyser
365364
{
@@ -538,9 +537,9 @@ public function getGitattributesFileRepository(): GitattributesFileRepository
538537
* Set the glob pattern file.
539538
*
540539
* @param string $file
541-
* @return AbstractExportIgnoreAnalyser
542540
* @throws InvalidGlobPatternFile
543541
* @throws NonExistentGlobPatternFile
542+
* @return AbstractExportIgnoreAnalyser
544543
*/
545544
public function setGlobPatternFromFile(string $file): AbstractExportIgnoreAnalyser
546545
{
@@ -580,9 +579,9 @@ public function setGlobPatternFromFile(string $file): AbstractExportIgnoreAnalys
580579
*
581580
* @param string $pattern The glob pattern to use to detect expected export-ignores files.
582581
*
583-
* @return AbstractExportIgnoreAnalyser
584582
*
585583
* @throws InvalidGlobPattern
584+
* @return AbstractExportIgnoreAnalyser
586585
*/
587586
public function setGlobPattern(string $pattern): AbstractExportIgnoreAnalyser
588587
{
@@ -604,7 +603,7 @@ protected function guardGlobPattern(string $pattern): void
604603
$invalidGlobPattern = false;
605604

606605
if (\substr($pattern, 0) !== '{'
607-
&& (!str_ends_with($pattern, '}') && !str_ends_with($pattern, '}*'))) {
606+
&& (!\str_ends_with($pattern, '}') && !\str_ends_with($pattern, '}*'))) {
608607
$invalidGlobPattern = true;
609608
}
610609

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

646645
\array_filter($gitignoreLines, static function ($line) use (&$gitignoredPatterns) {
647646
$line = \trim($line);
648-
if ($line !== '' && !str_contains($line, '#')) {
649-
if (str_starts_with($line, "/")) {
647+
if ($line !== '' && !\str_contains($line, '#')) {
648+
if (\str_starts_with($line, "/")) {
650649
$gitignoredPatterns[] = \substr($line, 1);
651650
}
652-
if (str_ends_with($line, "/")) {
651+
if (\str_ends_with($line, "/")) {
653652
$gitignoredPatterns[] = \substr($line, 0, -1);
654653
}
655654
$gitignoredPatterns[] = $line;
@@ -679,9 +678,9 @@ public function getGitignoredPatterns(): array
679678
*/
680679
protected function patternHasMatch(string $globPattern): bool
681680
{
682-
if (str_starts_with(\trim($globPattern), '/')) {
681+
if (\str_starts_with(\trim($globPattern), '/')) {
683682
$globPattern = \trim(\substr($globPattern, 1));
684-
} elseif (str_ends_with(\trim($globPattern), '/')) {
683+
} elseif (\str_ends_with(\trim($globPattern), '/')) {
685684
$globPattern = \trim(\substr($globPattern, 0, -1));
686685
} else {
687686
$globPattern = '{' . \trim($globPattern) . '}*';
@@ -800,7 +799,7 @@ public function getPresentNonExportIgnoresContent(): string
800799
\array_filter($gitattributesLines, static function (string $line) use (
801800
&$nonExportIgnoreLines
802801
) {
803-
if (!str_contains($line, 'export-ignore') || \strstr($line, '#')) {
802+
if (!\str_contains($line, 'export-ignore') || \strstr($line, '#')) {
804803
$nonExportIgnoreLines[] = \trim($line);
805804
}
806805
});
@@ -823,7 +822,7 @@ public function getPresentNonExportIgnoresContent(): string
823822
&$exportIgnoresPlacementPlaceholderSet,
824823
&$exportIgnoresPlacementPlaceholder
825824
) {
826-
if (!str_contains($line, 'export-ignore') || \strstr($line, '#')) {
825+
if (!\str_contains($line, 'export-ignore') || \strstr($line, '#')) {
827826
return $nonExportIgnoreLines[] = \trim($line);
828827
} else {
829828
if ($exportIgnoresPlacementPlaceholderSet === false) {
@@ -854,8 +853,8 @@ protected function getAlignedExportIgnoreArtifacts(array $artifacts): array
854853
return \array_map(static function (string $artifact) use (&$longestArtifact) {
855854
if (\strlen($artifact) < $longestArtifact) {
856855
return $artifact . \str_repeat(
857-
' ',
858-
$longestArtifact - \strlen($artifact)
856+
' ',
857+
$longestArtifact - \strlen($artifact)
859858
);
860859
}
861860
return $artifact;
@@ -871,7 +870,7 @@ protected function getByDirectoriesToFilesExportIgnoreArtifacts(array $artifacts
871870
});
872871

873872
$files = \array_filter($artifacts, static function (string $artifact) {
874-
if (!str_contains($artifact, '/')) {
873+
if (!\str_contains($artifact, '/')) {
875874
return $artifact;
876875
}
877876
});

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: 33 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
);
@@ -311,6 +315,7 @@ public function hasCompleteExportIgnores(): bool
311315
if ($this->isStaleExportIgnoresComparisonEnabled()) {
312316
$allNegatedIgnores = $this->getPresentExportIgnores(false);
313317
$staleNegatedIgnores = \array_diff($allNegatedIgnores, $presentNegatedExportIgnores);
318+
314319
if ($staleNegatedIgnores !== []) {
315320
return false;
316321
}

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) {

0 commit comments

Comments
 (0)