Skip to content

Commit a8bd1e0

Browse files
committed
Migrates internal tooling to Mago
1 parent 4b565f6 commit a8bd1e0

27 files changed

+92
-44
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ example/ export-ignore
1818
LICENSE.md export-ignore
1919
llms.txt export-ignore
2020
lpv-logo.png export-ignore
21+
mago.toml export-ignore
2122
peck.json export-ignore
2223
phpstan.neon.dist export-ignore
2324
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 = []
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: 9 additions & 9 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

@@ -652,8 +652,8 @@ public function getPresentExportIgnoresToPreserve(array $globPatternMatchingExpo
652652
$pattern = \trim($pattern);
653653

654654
if ($patternMatches
655-
&& !\in_array($pattern, $globPatternMatchingExportIgnores)
656-
&& !\in_array($pattern, $basenamedGlobPatternMatchingExportIgnores)
655+
&& !\in_array($pattern, $globPatternMatchingExportIgnores, strict: true)
656+
&& !\in_array($pattern, $basenamedGlobPatternMatchingExportIgnores, strict: true)
657657
) {
658658
return $exportIgnoresToPreserve[] = \trim($pattern);
659659
}
@@ -688,7 +688,7 @@ public function collectExpectedExportIgnores(): array
688688
}
689689

690690
foreach ($globMatches as $filename) {
691-
if (!\in_array($filename, $ignoredGlobMatches)) {
691+
if (!\in_array($filename, $ignoredGlobMatches, strict: true)) {
692692
if (\is_dir($filename)) {
693693
$expectedExportIgnores[] = $filename . '/';
694694
continue;
@@ -830,7 +830,7 @@ public function getPresentNonExportIgnoresContent(): string
830830
$exportIgnoresPlacementPlaceholderSet = false;
831831
$exportIgnoresPlacementPlaceholder = self::EXPORT_IGNORES_PLACEMENT_PLACEHOLDER;
832832

833-
\array_filter($gitattributesLines, function ($line) use (
833+
\array_filter($gitattributesLines, function (string $line) use (
834834
&$nonExportIgnoreLines,
835835
&$exportIgnoresPlacementPlaceholderSet,
836836
&$exportIgnoresPlacementPlaceholder
@@ -872,7 +872,7 @@ public function getPresentExportIgnores(bool $applyGlob = true, string $gitattri
872872
);
873873

874874
$exportIgnores = [];
875-
\array_filter($gitattributesLines, function ($line) use (&$exportIgnores, &$applyGlob) {
875+
\array_filter($gitattributesLines, function (string $line) use (&$exportIgnores, &$applyGlob) {
876876
if (\strstr($line, 'export-ignore', true)) {
877877
list($line, $void) = \explode('export-ignore', $line);
878878
if ($applyGlob) {
@@ -912,7 +912,7 @@ private function getAlignedExportIgnoreArtifacts(array $artifacts): array
912912
{
913913
$longestArtifact = \max(\array_map('strlen', $artifacts));
914914

915-
return \array_map(function ($artifact) use (&$longestArtifact) {
915+
return \array_map(function (string $artifact) use (&$longestArtifact) {
916916
if (\strlen($artifact) < $longestArtifact) {
917917
return $artifact . \str_repeat(
918918
' ',
@@ -930,7 +930,7 @@ private function getByDirectoriesToFilesExportIgnoreArtifacts(array $artifacts):
930930
return $artifact;
931931
}
932932
});
933-
$files = \array_filter($artifacts, function ($artifact) {
933+
$files = \array_filter($artifacts, function (string $artifact) {
934934
if (\strpos($artifact, '/') === false) {
935935
return $artifact;
936936
}

src/Archive.php

Lines changed: 5 additions & 2 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;
@@ -166,7 +169,7 @@ public function compareArchive(array $unexpectedArtifacts): array
166169
if ($archiveFile instanceof \SplFileInfo) {
167170
if ($archiveFile->isDir()) {
168171
$file = \basename($archiveFile) . '/';
169-
if (\in_array($file, $unexpectedArtifacts)) {
172+
if (\in_array($file, $unexpectedArtifacts, strict: true)) {
170173
$foundUnexpectedArtifacts[] = $file;
171174
}
172175
continue;
@@ -179,7 +182,7 @@ public function compareArchive(array $unexpectedArtifacts): array
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
122122
$this->analyser->setDirectory($directory);
123123
} catch (\RuntimeException $e) {
124124
$warning = "Warning: The provided directory "
125-
. "'$directory' does not exist or is not a directory.";
125+
. "'{$directory}' does not exist or is not a directory.";
126126
$outputContent = '<error>' . $warning . '</error>';
127127
$output->writeln($outputContent);
128128

@@ -145,7 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
145145
return Command::FAILURE;
146146
}
147147

148-
if ($chosenPreset && \in_array(\strtolower($chosenPreset), \array_map('strtolower', $this->finder->getAvailablePresets()))) {
148+
if ($chosenPreset && \in_array(\strtolower($chosenPreset), \array_map('strtolower', $this->finder->getAvailablePresets()), strict: true)) {
149149
$verboseOutput = '+ Loading preset ' . $chosenPreset . '.';
150150
$output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE);
151151
$globPatternFromPreset = true;
@@ -158,7 +158,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
158158
return Command::FAILURE;
159159
}
160160

161-
$lpvFileContent = \implode("\n", $defaultGlobPattern);
161+
$lpvFileContent = \implode(PHP_EOL, $defaultGlobPattern);
162162

163163
if ($input->getOption('dry-run') === true) {
164164
$output->writeln($lpvFileContent);
@@ -187,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
187187
return Command::FAILURE;
188188
}
189189

190-
$info = "<info>Created default '$defaultLpvFile' file.</info>";
190+
$info = "<info>Created default '{$defaultLpvFile}' file.</info>";
191191
$output->writeln($info);
192192

193193
return Command::SUCCESS;

src/Commands/TreeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6161

6262
if (!\is_dir($this->directoryToOperateOn)) {
6363
$warning = "Warning: The provided directory "
64-
. "'$this->directoryToOperateOn' does not exist or is not a directory.";
64+
. "'{$this->directoryToOperateOn}' does not exist or is not a directory.";
6565
$outputContent = '<error>' . $warning . '</error>';
6666
$output->writeln($outputContent);
6767

src/Commands/ValidateCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
241241
$this->analyser->setDirectory($directory);
242242
} catch (\RuntimeException $e) {
243243
$warning = "Warning: The provided directory "
244-
. "'$directory' does not exist or is not a directory.";
244+
. "'{$directory}' does not exist or is not a directory.";
245245
$outputContent = '<error>' . $warning . '</error>';
246246
$output->writeln($outputContent);
247247

@@ -370,7 +370,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
370370
$this->analyser->setKeepGlobPattern($keepGlobPattern);
371371
} catch (InvalidGlobPattern $e) {
372372
$warning = "Warning: The provided glob pattern "
373-
. "'$keepGlobPattern' is considered invalid.";
373+
. "'{$keepGlobPattern}' is considered invalid.";
374374
$outputContent = '<error>' . $warning . '</error>';
375375
$output->writeln($outputContent);
376376

@@ -391,13 +391,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
391391

392392
if ($globPattern || $globPattern === '') {
393393
try {
394-
$verboseOutput = "+ Using glob pattern <info>$globPattern</info>.";
394+
$verboseOutput = "+ Using glob pattern <info>{$globPattern}</info>.";
395395
$output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE);
396396

397397
$this->analyser->setGlobPattern((string) $globPattern);
398398
} catch (InvalidGlobPattern $e) {
399399
$warning = "Warning: The provided glob pattern "
400-
. "'$globPattern' is considered invalid.";
400+
. "'{$globPattern}' is considered invalid.";
401401
$outputContent = '<error>' . $warning . '</error>';
402402
$output->writeln($outputContent);
403403

@@ -420,7 +420,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
420420

421421
} catch (NonExistentGlobPatternFile $e) {
422422
$warning = "Warning: The provided glob pattern file "
423-
. "'$globPatternFile' doesn't exist.";
423+
. "'{$globPatternFile}' doesn't exist.";
424424
$outputContent = '<error>' . $warning . '</error>';
425425
$output->writeln($outputContent);
426426

@@ -429,7 +429,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
429429
return Command::FAILURE;
430430
} catch (InvalidGlobPatternFile $e) {
431431
$warning = "Warning: The provided glob pattern file "
432-
. "'$globPatternFile' is considered invalid.";
432+
. "'{$globPatternFile}' is considered invalid.";
433433
$outputContent = '<error>' . $warning . '</error>';
434434
$output->writeln($outputContent);
435435

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

0 commit comments

Comments
 (0)