Skip to content

Commit

Permalink
feat: switch to php-cs-fixer (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup authored Jul 2, 2024
1 parent 879b4da commit b06e753
Show file tree
Hide file tree
Showing 24 changed files with 290 additions and 305 deletions.
1 change: 1 addition & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<phar name="composer-normalize" version="^2.32.0" location="./tools/composer-normalize" copy="false" installed="2.32.0"/>
<phar name="phpunit" version="^10.4.0" location="./tools/phpunit.phar" copy="true" installed="10.4.1"/>
<phar name="overtrue/phplint" version="^9.0.4" location="./tools/phplint" copy="false" installed="9.0.4"/>
<phar name="php-cs-fixer" version="^3.58.1" installed="3.58.1" copy="false" location="./tools/php-cs-fixer"/>
</phive>
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

$finder = (new \PhpCsFixer\Finder())
->in(__DIR__ . '/src')
->in(__DIR__ . '/test');

return (new \PhpCsFixer\Config())
->setCacheFile('var/cache/php-cs-fixer')
->setFinder($finder)
->setRules(['@PER-CS' => true]);
8 changes: 3 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,24 @@
}
},
"scripts": {
"post-install-cmd": "phive --no-progress install --force-accept-unsigned --trust-gpg-keys C00543248C87FB13,4AA394086372C20A,CF1A108D0E7AE720,51C67305FFC2E5C0",
"post-install-cmd": "phive --no-progress install --force-accept-unsigned --trust-gpg-keys C00543248C87FB13,4AA394086372C20A,CF1A108D0E7AE720,51C67305FFC2E5C0,E82B2FB314E9906E",
"analyse": [
"@analyse:phplint",
"@analyse:phpstan",
"@analyse:phpcs",
"@analyse:phpcsfixer",
"@analyse:compatibilitycheck"
],
"analyse:compatibilitycheck": "./vendor/bin/phpcs --standard=./phpcs.compatibilitycheck.xml",
"analyse:phpcs": "./vendor/bin/phpcs",
"analyse:phpcsfixer": "./tools/php-cs-fixer check --diff --show-progress=dots",
"analyse:phplint": "./tools/phplint",
"analyse:phpstan": "./tools/phpstan analyse",
"cs-fix": [
"@cs-fix:phpcbf"
],
"cs-fix:phpcbf": "./vendor/bin/phpcbf",
"report": [
"@report:phpcs",
"@report:phpstan"
],
"report:phpcs": "./vendor/bin/phpcs || exit 0",
"report:phpstan": "./tools/phpstan analyse --no-progress --no-ansi --no-interaction --error-format=checkstyle > ./var/log/phpstan-report.xml || exit 0",
"test": [
"@test:phpunit"
Expand Down
182 changes: 92 additions & 90 deletions composer.lock

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions phpcs.xml.dist

This file was deleted.

4 changes: 2 additions & 2 deletions src/AtooloRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AtooloRuntime
*/
public function __construct(
private readonly string $projectDir,
private readonly array $options
private readonly array $options,
) {

$executors = [];
Expand All @@ -28,7 +28,7 @@ public function __construct(
static function (string $executorClass) {
return new $executorClass();
},
$packageOptions['executor'] ?? []
$packageOptions['executor'] ?? [],
);
}
$this->executor = array_merge(...$executors);
Expand Down
8 changes: 4 additions & 4 deletions src/Composer/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
private readonly Composer $composer,
string $composerJsonFile,
private readonly JsonManipulator $manipulator,
private array $jsonContent = []
private array $jsonContent = [],
) {
$this->jsonFile = new JsonFile($composerJsonFile);
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public function addAutoloadFile(string $autoloadFile): bool

file_put_contents(
$this->jsonFile->getPath(),
$this->manipulator->getContents()
$this->manipulator->getContents(),
);

$this->updateAutoloadConfig();
Expand All @@ -88,7 +88,7 @@ public function removeAutoloadFile(string $autoloadFile): bool
}
file_put_contents(
$this->jsonFile->getPath(),
$this->manipulator->getContents()
$this->manipulator->getContents(),
);

$this->updateAutoloadConfig();
Expand All @@ -99,7 +99,7 @@ public function removeAutoloadFile(string $autoloadFile): bool
public function updateAutoloadConfig(): void
{
$this->composer->getPackage()->setAutoload(
$this->jsonContent['autoload'] ?? []
$this->jsonContent['autoload'] ?? [],
);
}
}
12 changes: 6 additions & 6 deletions src/Composer/ComposerJsonFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class ComposerJsonFactory
{
public function create(
Composer $composer,
string $composerJsonFile
string $composerJsonFile,
): ComposerJson {

$composerJsonRealPath = realpath($composerJsonFile);
if ($composerJsonRealPath === false) {
throw new RuntimeException(
"Failed to resolve composer.json file: $composerJsonFile"
"Failed to resolve composer.json file: $composerJsonFile",
);
}

Expand All @@ -29,7 +29,7 @@ public function create(
$composer,
$composerJsonRealPath,
new JsonManipulator($content),
$jsonContent
$jsonContent,
);
}

Expand All @@ -41,7 +41,7 @@ private function loadContent(string $composerJsonFile): string
$content = @file_get_contents($composerJsonFile);
if ($content === false) {
throw new RuntimeException(
"Failed to read composer.json file: $composerJsonFile"
"Failed to read composer.json file: $composerJsonFile",
);
}
return $content;
Expand All @@ -61,12 +61,12 @@ private function parseJson(string $composerJsonFile, string $content): array
$content,
true,
512,
JSON_THROW_ON_ERROR
JSON_THROW_ON_ERROR,
);

if (!is_array($jsonContent)) {
throw new JsonException(
"Failed to parse composer.json file: $composerJsonFile"
"Failed to parse composer.json file: $composerJsonFile",
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/Composer/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ComposerPlugin implements PluginInterface, EventSubscriberInterface

public function __construct(
?ComposerJsonFactory $composerJsonFactory = null,
?RuntimeFileFactory $runtimeFileFactory = null
?RuntimeFileFactory $runtimeFileFactory = null,
) {
$this->composerJsonFactory = $composerJsonFactory
?? new ComposerJsonFactory();
Expand All @@ -46,7 +46,7 @@ public static function getSubscribedEvents()
$method = 'updateRuntime';
$priority = 1;
return [
ScriptEvents::PRE_AUTOLOAD_DUMP => [$method, $priority]
ScriptEvents::PRE_AUTOLOAD_DUMP => [$method, $priority],
];
}

Expand All @@ -58,11 +58,11 @@ public function activate(Composer $composer, IOInterface $io): void
$this->io = $io;
$this->composerJson = $this->composerJsonFactory->create(
$composer,
Factory::getComposerFile()
Factory::getComposerFile(),
);
$this->runtimeFile = $this->runtimeFileFactory->create(
$composer,
dirname($this->composerJson->getPath())
dirname($this->composerJson->getPath()),
);
self::$activated = true;
}
Expand All @@ -76,7 +76,7 @@ public function updateRuntime(): void
{
$this->runtimeFile->updateRuntimeFile($this->io);
$this->composerJson->addAutoloadFile(
$this->runtimeFile->getRuntimeFilePath()
$this->runtimeFile->getRuntimeFilePath(),
);
}

Expand All @@ -89,7 +89,7 @@ public function uninstall(Composer $composer, IOInterface $io)
{
$this->runtimeFile->removeRuntimeFile($this->io);
$this->composerJson->removeAutoloadFile(
$this->runtimeFile->getRuntimeFilePath()
$this->runtimeFile->getRuntimeFilePath(),
);
}
}
21 changes: 10 additions & 11 deletions src/Composer/RuntimeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class RuntimeFile

public function __construct(
private readonly Composer $composer,
private readonly string $projectDir
) {
}
private readonly string $projectDir,
) {}

public function getRuntimeFilePath(): string
{
Expand All @@ -39,7 +38,7 @@ public function updateRuntimeFile(IOInterface $io): void
$projectDir = $this->getProjectDir();

$rootRuntimeOptions = $this->getPackageRuntimeOptions(
$this->composer->getPackage()
$this->composer->getPackage(),
);
$runtimeClass = $rootRuntimeOptions['class']
?? AtooloRuntime::class;
Expand All @@ -50,7 +49,7 @@ public function updateRuntimeFile(IOInterface $io): void
if ($runtimeTemplate === false) {
throw new RuntimeException(
'Failed to read runtime template file: '
. $runtimeTemplateFile
. $runtimeTemplateFile,
);
}
$code = strtr($runtimeTemplate, [
Expand Down Expand Up @@ -82,13 +81,13 @@ private function getVendorDir(): string
if (!is_string($vendorDir)) {
throw new RuntimeException(
'Unable to determine the vendor directory: '
. print_r($vendorDir, true)
. print_r($vendorDir, true),
);
}
$vendorDir = realpath($vendorDir);
if ($vendorDir === false) {
throw new RuntimeException(
'Unable to determine the vendor directory.'
'Unable to determine the vendor directory.',
);
}

Expand All @@ -105,7 +104,7 @@ private function getRuntimeOptions(): array

$packages = array_merge(
$repo->getPackages(),
[$this->composer->getPackage()]
[$this->composer->getPackage()],
);
foreach ($packages as $package) {
$packageOptions = $this->getPackageRuntimeOptions($package);
Expand All @@ -128,7 +127,7 @@ private function getRuntimeTemplateFile(): string

/** @var RuntimeRootPackageOptions $rootPackageOptions */
$rootPackageOptions = $this->getPackageRuntimeOptions(
$this->composer->getPackage()
$this->composer->getPackage(),
);
$runtimeTemplateFile = $rootPackageOptions['template'] ?? null;
if ($runtimeTemplateFile === null) {
Expand All @@ -144,8 +143,8 @@ private function getRuntimeTemplateFile(): string
'File "%s" defined under '
. '"extra.atoolo.runtime.template"'
. ' in your composer.json not found.',
$runtimeTemplateFile
)
$runtimeTemplateFile,
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Composer/RuntimeFileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RuntimeFileFactory
{
public function create(
Composer $composer,
string $projectDir
string $projectDir,
): RuntimeFile {
return new RuntimeFile($composer, $projectDir);
}
Expand Down
19 changes: 9 additions & 10 deletions src/Executor/IniSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class IniSetter implements RuntimeExecutor
private $alreadySet = [];

public function __construct(
private readonly Platform $platform = new Platform()
) {
}
private readonly Platform $platform = new Platform(),
) {}

/**
* @param RuntimeOptions $options
Expand All @@ -40,7 +39,7 @@ public function execute(string $projectDir, array $options): void
if ($value !== null) {
$settings[$key] = [
'value' => $value,
'package' => $package
'package' => $package,
];
}
}
Expand All @@ -52,7 +51,7 @@ public function execute(string $projectDir, array $options): void
$package = $setting['package'];
throw new RuntimeException(
"[atoolo.runtime.init.set]: "
. "Failed to set $key to $value for, package: $package"
. "Failed to set $key to $value for, package: $package",
);
}
}
Expand All @@ -66,7 +65,7 @@ public function execute(string $projectDir, array $options): void
private function validate(
string $package,
string $key,
mixed $value
mixed $value,
): bool|float|int|string|null {

if ($value === null) {
Expand All @@ -76,7 +75,7 @@ private function validate(
if (is_scalar($value) === false) {
throw new RuntimeException(
"[atoolo.runtime.init.set]: "
. "Value for $key in package $package must be scalar"
. "Value for $key in package $package must be scalar",
);
}

Expand All @@ -88,20 +87,20 @@ private function validate(
$package = $this->alreadySet[$key]['package'];
throw new RuntimeException(
"[atoolo.runtime.init.set]: "
. "$key is already set to '$existsValue', package: $package"
. "$key is already set to '$existsValue', package: $package",
);
}

if (ini_set($key, $value) === false) {
throw new RuntimeException(
"[atoolo.runtime.init.set]: "
. "Failed to set $key to $value for, package: $package"
. "Failed to set $key to $value for, package: $package",
);
}

$this->alreadySet[$key] = [
'value' => $value,
'package' => $package
'package' => $package,
];

return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Executor/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function umask(int $umask): int

public function setIni(
string $name,
bool|float|int|string $value
bool|float|int|string $value,
): false|string {
return ini_set($name, $value);
}
Expand Down
Loading

0 comments on commit b06e753

Please sign in to comment.