Skip to content

Commit 9671584

Browse files
committed
Migrates internal tooling to Mago
1 parent 1c752ab commit 9671584

29 files changed

Lines changed: 105 additions & 55 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Formula/ export-ignore
2020
LICENSE.md export-ignore
2121
llms.txt export-ignore
2222
lpv-logo.png export-ignore
23+
mago.toml export-ignore
2324
peck.json export-ignore
2425
phpstan.neon.dist export-ignore
2526
phpunit.xml.dist export-ignore

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"scripts": {
4545
"lpv:test": "phpunit",
4646
"lpv:test-with-coverage": "export XDEBUG_MODE=coverage && phpunit --coverage-html coverage-reports",
47-
"lpv:cs-fix": "php-cs-fixer --allow-risky=yes fix . -vv || true",
48-
"lpv:cs-lint": "php-cs-fixer fix --diff --stop-on-violation --verbose --dry-run --allow-risky=yes",
47+
"lpv:cs-fix": "mago lint --fix",
48+
"lpv:cs-lint": "mago lint",
4949
"lpv:configure-commit-template": "git config --add commit.template .gitmessage",
5050
"lpv:application-version-guard": "php bin/application-version --verify-tag-match=bin",
5151
"lpv:application-phar-version-guard": "php bin/application-version --verify-tag-match=phar",
@@ -65,9 +65,13 @@
6565
"config": {
6666
"preferred-install": "dist",
6767
"sort-packages": true,
68-
"optimize-autoloader": true
68+
"optimize-autoloader": true,
69+
"allow-plugins": {
70+
"carthage-software/mago": true
71+
}
6972
},
7073
"require-dev": {
74+
"carthage-software/mago": "^0.26.1",
7175
"friendsofphp/php-cs-fixer": "^3.70.1",
7276
"mockery/mockery": "^1.0",
7377
"peckphp/peck": "^0.1.2",

mago.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Mago configuration file
2+
# For more information, see https://mago.carthage.software/#/getting-started/configuration
3+
php_version = "8.1.0"
4+
5+
[source]
6+
paths = ["src/", "tests/"]
7+
includes = ["vendor"]
8+
excludes = ["src/Glob.php"]
9+
10+
[format]
11+
print_width = 120
12+
tab_width = 4
13+
use_tabs = false
14+
15+
[linter]
16+
default_plugins = true
17+
plugins = ["symfony", "php-unit"]

src/Analyser.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function setGlobPatternFromFile(string $file): Analyser
211211
);
212212

213213
$globPatterns = [];
214-
\array_filter($globPatternLines, function ($line) use (&$globPatterns) {
214+
\array_filter($globPatternLines, function (string $line) use (&$globPatterns) {
215215
if (\trim($line) !== '') {
216216
$globPatterns[] = \trim($line);
217217
}
@@ -253,7 +253,7 @@ private function guardGlobPattern(string $pattern): void
253253

254254
$globPatterns = \explode(',', $bracesContent);
255255

256-
if (\count($globPatterns) == 1) {
256+
if (\count($globPatterns) === 1) {
257257
$invalidGlobPattern = true;
258258
}
259259

@@ -650,8 +650,8 @@ public function getPresentExportIgnoresToPreserve(array $globPatternMatchingExpo
650650
$pattern = \trim($pattern);
651651

652652
if ($patternMatches
653-
&& !\in_array($pattern, $globPatternMatchingExportIgnores)
654-
&& !\in_array($pattern, $basenamedGlobPatternMatchingExportIgnores)
653+
&& !\in_array($pattern, $globPatternMatchingExportIgnores, strict: true)
654+
&& !\in_array($pattern, $basenamedGlobPatternMatchingExportIgnores, strict: true)
655655
) {
656656
return $exportIgnoresToPreserve[] = \trim($pattern);
657657
}
@@ -686,7 +686,7 @@ public function collectExpectedExportIgnores(): array
686686
}
687687

688688
foreach ($globMatches as $filename) {
689-
if (!\in_array($filename, $ignoredGlobMatches)) {
689+
if (!\in_array($filename, $ignoredGlobMatches, strict: true)) {
690690
if (\is_dir($filename)) {
691691
$expectedExportIgnores[] = $filename . '/';
692692
continue;
@@ -828,7 +828,7 @@ public function getPresentNonExportIgnoresContent(): string
828828
$exportIgnoresPlacementPlaceholderSet = false;
829829
$exportIgnoresPlacementPlaceholder = self::EXPORT_IGNORES_PLACEMENT_PLACEHOLDER;
830830

831-
\array_filter($gitattributesLines, function ($line) use (
831+
\array_filter($gitattributesLines, function (string $line) use (
832832
&$nonExportIgnoreLines,
833833
&$exportIgnoresPlacementPlaceholderSet,
834834
&$exportIgnoresPlacementPlaceholder
@@ -870,7 +870,7 @@ public function getPresentExportIgnores(bool $applyGlob = true, string $gitattri
870870
);
871871

872872
$exportIgnores = [];
873-
\array_filter($gitattributesLines, function ($line) use (&$exportIgnores, &$applyGlob) {
873+
\array_filter($gitattributesLines, function (string $line) use (&$exportIgnores, &$applyGlob) {
874874
if (\strstr($line, 'export-ignore', true)) {
875875
list($line, $void) = \explode('export-ignore', $line);
876876
if ($applyGlob) {
@@ -910,7 +910,7 @@ private function getAlignedExportIgnoreArtifacts(array $artifacts): array
910910
{
911911
$longestArtifact = \max(\array_map('strlen', $artifacts));
912912

913-
return \array_map(function ($artifact) use (&$longestArtifact) {
913+
return \array_map(function (string $artifact) use (&$longestArtifact) {
914914
if (\strlen($artifact) < $longestArtifact) {
915915
return $artifact . \str_repeat(
916916
' ',
@@ -923,12 +923,13 @@ private function getAlignedExportIgnoreArtifacts(array $artifacts): array
923923

924924
private function getByDirectoriesToFilesExportIgnoreArtifacts(array $artifacts): array
925925
{
926-
$directories = \array_filter($artifacts, function ($artifact) {
926+
$directories = \array_filter($artifacts, function (string $artifact) {
927927
if (\strpos($artifact, '/')) {
928928
return $artifact;
929929
}
930930
});
931-
$files = \array_filter($artifacts, function ($artifact) {
931+
932+
$files = \array_filter($artifacts, function (string $artifact) {
932933
if (\strpos($artifact, '/') === false) {
933934
return $artifact;
934935
}

src/Archive.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
36
namespace Stolt\LeanPackage;
47

58
use PharData;
@@ -165,21 +168,21 @@ public function compareArchive(array $unexpectedArtifacts): array
165168
foreach ($archive as $archiveFile) {
166169
if ($archiveFile instanceof \SplFileInfo) {
167170
if ($archiveFile->isDir()) {
168-
$file = \basename($archiveFile) . '/';
169-
if (\in_array($file, $unexpectedArtifacts)) {
171+
$file = \basename($archiveFile->getRealPath());
172+
if (\in_array($file, $unexpectedArtifacts, strict: true)) {
170173
$foundUnexpectedArtifacts[] = $file;
171174
}
172175
continue;
173176
}
174177

175-
$file = \basename($archiveFile);
178+
$file = \basename($archiveFile->getRealPath());
176179
if ($this->validateLicenseFilePresence()) {
177180
if (\preg_match('/(License.*)/i', $file)) {
178181
$hasLicenseFile = true;
179182
}
180183
}
181184

182-
if (\in_array($file, $unexpectedArtifacts)) {
185+
if (\in_array($file, $unexpectedArtifacts, strict: true)) {
183186
$foundUnexpectedArtifacts[] = $file;
184187
}
185188
}

src/Archive/Validator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
36
namespace Stolt\LeanPackage\Archive;
47

58
use Stolt\LeanPackage\Archive;

src/Commands/InitCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
136136
return Command::FAILURE;
137137
}
138138

139-
if ($chosenPreset && \in_array(\strtolower($chosenPreset), \array_map('strtolower', $this->finder->getAvailablePresets()))) {
139+
if ($chosenPreset && \in_array(\strtolower($chosenPreset), \array_map('strtolower', $this->finder->getAvailablePresets()), strict: true)) {
140140
$verboseOutput = '+ Loading preset ' . $chosenPreset . '.';
141141
$output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE);
142142
$globPatternFromPreset = true;
@@ -151,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
151151
return Command::FAILURE;
152152
}
153153

154-
$lpvFileContent = \implode("\n", $defaultGlobPattern);
154+
$lpvFileContent = \implode(PHP_EOL, $defaultGlobPattern);
155155

156156
if ($this->isDryRun($input)) {
157157
$output->writeln($lpvFileContent);

src/Commands/ValidateCommand.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Stolt\LeanPackage\Exceptions\NonExistentGlobPatternFile;
2222
use Stolt\LeanPackage\Exceptions\PresetNotAvailable;
2323
use Stolt\LeanPackage\GitattributesFileRepository;
24-
use Stolt\LeanPackage\Helpers\InputReader;
24+
use Stolt\LeanPackage\Helpers\InputReaderInterface;
2525
use Symfony\Component\Console\Command\Command;
2626
use Symfony\Component\Console\Input\InputArgument;
2727
use Symfony\Component\Console\Input\InputInterface;
@@ -61,16 +61,16 @@ final class ValidateCommand extends Command
6161
/**
6262
* Input reader.
6363
*
64-
* @var InputReader
64+
* @var InputReaderInterface
6565
*/
66-
protected InputReader $inputReader;
66+
protected InputReaderInterface $inputReader;
6767

6868
/**
6969
* @param Analyser $analyser
7070
* @param Validator $archiveValidator
71-
* @param InputReader $inputReader
71+
* @param InputReaderInterface $inputReader
7272
*/
73-
public function __construct(Analyser $analyser, Validator $archiveValidator, InputReader $inputReader)
73+
public function __construct(Analyser $analyser, Validator $archiveValidator, InputReaderInterface $inputReader)
7474
{
7575
$this->analyser = $analyser;
7676
$this->archiveValidator = $archiveValidator;
@@ -253,6 +253,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
253253
} else {
254254
$output->writeln('<error>' . $warning . '</error>');
255255
}
256+
256257
$output->writeln($e->getMessage(), OutputInterface::VERBOSITY_DEBUG);
257258

258259
return Command::FAILURE;
@@ -385,7 +386,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
385386
$this->analyser->setKeepGlobPattern($keepGlobPattern);
386387
} catch (InvalidGlobPattern $e) {
387388
$warning = "Warning: The provided glob pattern "
388-
. "'$keepGlobPattern' is considered invalid.";
389+
. "'{$keepGlobPattern}' is considered invalid.";
389390
$outputContent = '<error>' . $warning . '</error>';
390391
$output->writeln($outputContent);
391392

@@ -406,13 +407,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
406407

407408
if ($globPattern || $globPattern === '') {
408409
try {
409-
$verboseOutput = "+ Using glob pattern <info>$globPattern</info>.";
410+
$verboseOutput = "+ Using glob pattern <info>{$globPattern}</info>.";
410411
$output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE);
411412

412413
$this->analyser->setGlobPattern((string) $globPattern);
413414
} catch (InvalidGlobPattern $e) {
414415
$warning = "Warning: The provided glob pattern "
415-
. "'$globPattern' is considered invalid.";
416+
. "'{$globPattern}' is considered invalid.";
416417
$outputContent = '<error>' . $warning . '</error>';
417418
$output->writeln($outputContent);
418419

@@ -435,7 +436,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
435436

436437
} catch (NonExistentGlobPatternFile $e) {
437438
$warning = "Warning: The provided glob pattern file "
438-
. "'$globPatternFile' doesn't exist.";
439+
. "'{$globPatternFile}' doesn't exist.";
439440
$outputContent = '<error>' . $warning . '</error>';
440441
$output->writeln($outputContent);
441442

@@ -444,7 +445,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
444445
return Command::FAILURE;
445446
} catch (InvalidGlobPatternFile $e) {
446447
$warning = "Warning: The provided glob pattern file "
447-
. "'$globPatternFile' is considered invalid.";
448+
. "'{$globPatternFile}' is considered invalid.";
448449
$outputContent = '<error>' . $warning . '</error>';
449450
$output->writeln($outputContent);
450451

src/Exceptions/GitArchiveNotValidatedYet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Stolt\LeanPackage\Exceptions;
46

57
class GitArchiveNotValidatedYet extends \Exception
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace Stolt\LeanPackage\Exceptions;
3+
declare(strict_types=1);
44

5+
namespace Stolt\LeanPackage\Exceptions;
56
class GitHeadNotAvailable extends \Exception
67
{
78
}

0 commit comments

Comments
 (0)