Skip to content

Commit

Permalink
Apply rector in directory src. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Jan 20, 2024
1 parent 4ab2818 commit 15c3fd6
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 89 deletions.
8 changes: 4 additions & 4 deletions src/Asset/AbstractAssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
abstract class AbstractAssetManager implements AssetManagerInterface
{
public const NODE_MODULES_PATH = './node_modules';
final public const NODE_MODULES_PATH = './node_modules';
protected bool $updatable = true;
protected VersionConverterInterface|null $versionConverter;
private null|string $version = '';
Expand Down Expand Up @@ -171,9 +171,9 @@ protected function actionWhenComposerDependenciesAreAlreadyInstalled(array $name
protected function buildCommand(string $defaultBin, string $action, array|string $command): string
{
$bin = $this->config->get('manager-bin', $defaultBin);
$bin = Platform::isWindows() ? str_replace('/', '\\', $bin) : $bin;
$gOptions = trim($this->config->get('manager-options', ''));
$options = trim($this->config->get('manager-' . $action . '-options', ''));
$bin = Platform::isWindows() ? str_replace('/', '\\', (string) $bin) : $bin;
$gOptions = trim((string) $this->config->get('manager-options', ''));
$options = trim((string) $this->config->get('manager-' . $action . '-options', ''));

return $bin . ' ' . implode(' ', (array) $command)
. (empty($gOptions) ? '' : ' ' . $gOptions)
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/AssetManagerFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class AssetManagerFinder
*
* @psalm-param AssetManagerInterface[] $managers The asset managers
*/
public function __construct(array $managers = array())
public function __construct(array $managers = [])
{
foreach ($managers as $manager) {
if ($manager instanceof AssetManagerInterface) {
Expand Down
8 changes: 4 additions & 4 deletions src/Asset/AssetPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function getPackage(): array

public function getInstalledDependencies(): array
{
$installedAssets = array();
$installedAssets = [];

if (isset($this->package[self::SECTION_DEPENDENCIES]) && \is_array($this->package[self::SECTION_DEPENDENCIES])) {
foreach ($this->package[self::SECTION_DEPENDENCIES] as $dependency => $version) {
if (0 === strpos($dependency, self::COMPOSER_PREFIX)) {
if (str_starts_with($dependency, self::COMPOSER_PREFIX)) {
$installedAssets[$dependency] = $version;
}
}
Expand All @@ -82,13 +82,13 @@ public function getInstalledDependencies(): array
public function addNewDependencies(array $dependencies): array
{
$installedAssets = $this->getInstalledDependencies();
$existingPackages = array();
$existingPackages = [];

foreach ($dependencies as $name => $path) {
if (isset($installedAssets[$name])) {
$existingPackages[] = $name;
} else {
$this->package[self::SECTION_DEPENDENCIES][$name] = 'file:./' . \dirname($path);
$this->package[self::SECTION_DEPENDENCIES][$name] = 'file:./' . \dirname((string) $path);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Asset/YarnManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isValidForUpdate(): bool
return true;
}

$cmd = $this->buildCommand('yarn', 'check', $this->mergeInteractiveCommand(array('check')));
$cmd = $this->buildCommand('yarn', 'check', $this->mergeInteractiveCommand(['check']));

return 0 === $this->executor->execute($cmd);
}
Expand All @@ -55,14 +55,14 @@ protected function getVersionCommand(): string

protected function getInstallCommand(): string
{
return $this->buildCommand('yarn', 'install', $this->mergeInteractiveCommand(array('install')));
return $this->buildCommand('yarn', 'install', $this->mergeInteractiveCommand(['install']));
}

protected function getUpdateCommand(): string
{
$commandName = $this->isYarnNext() ? 'up' : 'upgrade';

return $this->buildCommand('yarn', 'update', $this->mergeInteractiveCommand(array($commandName)));
return $this->buildCommand('yarn', 'update', $this->mergeInteractiveCommand([$commandName]));
}

private function isYarnNext(): bool
Expand Down
8 changes: 4 additions & 4 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function isBoolean(string $value): bool
{
$value = strtolower($value);

return \in_array($value, array('true', 'false', '1', '0', 'yes', 'no', 'y', 'n'), true);
return \in_array($value, ['true', 'false', '1', '0', 'yes', 'no', 'y', 'n'], true);
}

/**
Expand All @@ -125,7 +125,7 @@ private function isBoolean(string $value): bool
*/
private function convertBoolean(string $value): bool
{
return \in_array($value, array('true', '1', 'yes', 'y'), true);
return \in_array($value, ['true', '1', 'yes', 'y'], true);
}

/**
Expand Down Expand Up @@ -155,7 +155,7 @@ private function convertInteger(string $value): int
*/
private function isJson(string $value): bool
{
return 0 === strpos($value, '{') || 0 === strpos($value, '[');
return str_starts_with($value, '{') || str_starts_with($value, '[');
}

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ private function getDefaultValue(string $key, mixed $default = null): mixed
*/
private function getByManager(string $key, mixed $value, mixed $default = null): mixed
{
if (0 === strpos($key, 'manager-') && \is_array($value)) {
if (str_starts_with($key, 'manager-') && \is_array($value)) {
$manager = $manager = $this->get('manager', '');

$value = \array_key_exists($manager, $value)
Expand Down
4 changes: 2 additions & 2 deletions src/Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static function getConfigBase(Composer $composer, IOInterface $io = null
$packageConfig = $composer->getPackage()->getConfig();
$packageConfig = isset($packageConfig['foxy']) && \is_array($packageConfig['foxy'])
? $packageConfig['foxy']
: array();
: [];

return array_merge($globalPackageConfig, $globalConfig, $packageConfig);
}
Expand All @@ -67,7 +67,7 @@ private static function getGlobalConfig(Composer $composer, string $filename, IO
{
$home = self::getComposerHome($composer);
$file = new JsonFile($home . '/' . $filename . '.json');
$config = array();
$config = [];

if ($file->exists()) {
$data = $file->read();
Expand Down
4 changes: 2 additions & 2 deletions src/Converter/SemverConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ final class SemverConverter implements VersionConverterInterface
{
public function convertVersion(string $version = null): string
{
if (\in_array($version, array(null, '', 'latest'), true)) {
if (\in_array($version, [null, '', 'latest'], true)) {
return ('latest' === $version ? 'default || ' : '') . '*';
}

$version = str_replace('', '-', $version);
$prefix = preg_match('/^[a-z]/', $version) && 0 !== strpos($version, 'dev-') ? substr($version, 0, 1) : '';
$prefix = preg_match('/^[a-z]/', $version) && !str_starts_with($version, 'dev-') ? substr($version, 0, 1) : '';
$version = substr($version, \strlen($prefix));
$version = SemverUtil::convertVersionMetadata($version);
$version = SemverUtil::convertDateVersion($version);
Expand Down
22 changes: 11 additions & 11 deletions src/Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public static function convertVersionMetadata(string $version): string
$matches,
PREG_OFFSET_CAPTURE
)) {
list($type, $version, $end) = self::cleanVersion(strtolower($version), $matches);
list($version, $patchVersion) = self::matchVersion($version, $type);
[$type, $version, $end] = self::cleanVersion(strtolower($version), $matches);
[$version, $patchVersion] = self::matchVersion($version, $type);

$matches = array();
$hasPatchNumber = preg_match('/[0-9]+\.[0-9]+|[0-9]+|\.[0-9]+$/', $end, $matches);
$matches = [];
$hasPatchNumber = preg_match('/[0-9]+\.[0-9]+|[0-9]+|\.[0-9]+$/', (string) $end, $matches);
$end = $hasPatchNumber ? $matches[0] : '1';

if ($patchVersion) {
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function createPattern(string $pattern): string
*/
private static function cleanWildcard(string $version): string
{
while (false !== strpos($version, '.x.x')) {
while (str_contains($version, '.x.x')) {
$version = str_replace('.x.x', '.x', $version);
}

Expand All @@ -105,20 +105,20 @@ private static function cleanWildcard(string $version): string
*/
private static function cleanVersion(string $version, array $matches): array
{
$end = substr($version, \strlen($matches[1][0][0]));
$end = substr($version, \strlen((string) $matches[1][0][0]));
$version = $matches[1][0][0] . '-';

$matches = array();
$matches = [];
if (preg_match('/^([-+])/', $end, $matches)) {
$end = substr($end, 1);
}

$matches = array();
$matches = [];
preg_match('/^[a-z]+/', $end, $matches);
$type = isset($matches[0]) ? VersionParser::normalizeStability($matches[0]) : '';
$end = substr($end, \strlen($type));

return array($type, $version, $end);
return [$type, $version, $end];
}

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ private static function matchVersion(string $version, string $type): array
break;

default:
if (!\in_array($type, array('alpha', 'beta', 'RC'), true)) {
if (!\in_array($type, ['alpha', 'beta', 'RC'], true)) {
$type = 'patch';
}

Expand All @@ -162,7 +162,7 @@ private static function matchVersion(string $version, string $type): array

$version .= $type;

return array($version, $patchVersion);
return [$version, $patchVersion];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AbstractSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class AbstractSolveEvent extends Event
*
* @psalm-param PackageInterface[] $packages All installed Composer packages.
*/
public function __construct(string $name, private string $assetDir, private array $packages = [])
public function __construct(string $name, private readonly string $assetDir, private readonly array $packages = [])
{
parent::__construct($name, [], []);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Event/PostSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class PostSolveEvent extends AbstractSolveEvent
*
* @psalm-param PackageInterface[] $packages All installed Composer packages.
*/
public function __construct($assetDir, array $packages, private int $runResult)
public function __construct($assetDir, array $packages, private readonly int $runResult)
{
parent::__construct(FoxyEvents::POST_SOLVE, $assetDir, $packages);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Fallback/ComposerFallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function save(): self
try {
$lock = $locker->getLockData();
$this->lock = PackageUtil::loadLockPackages($lock);
} catch (\LogicException $e) {
$this->lock = array();
} catch (\LogicException) {
$this->lock = [];
}

return $this;
Expand Down Expand Up @@ -95,16 +95,16 @@ public function restore(): void
protected function restoreLockData(): bool
{
$this->composer->getLocker()->setLockData(
$this->getLockValue('packages', array()),
$this->getLockValue('packages', []),
$this->getLockValue('packages-dev'),
$this->getLockValue('platform', array()),
$this->getLockValue('platform-dev', array()),
$this->getLockValue('aliases', array()),
$this->getLockValue('platform', []),
$this->getLockValue('platform-dev', []),
$this->getLockValue('aliases', []),
$this->getLockValue('minimum-stability', ''),
$this->getLockValue('stability-flags', array()),
$this->getLockValue('stability-flags', []),
$this->getLockValue('prefer-stable', false),
$this->getLockValue('prefer-lowest', false),
$this->getLockValue('platform-overrides', array())
$this->getLockValue('platform-overrides', [])
);

$isLocked = $this->composer->getLocker()->isLocked();
Expand All @@ -120,7 +120,7 @@ protected function restoreLockData(): bool
protected function restorePreviousLockFile(): void
{
$config = $this->composer->getConfig();
list($preferSource, $preferDist) = ConsoleUtil::getPreferredInstallOptions($config, $this->input);
[$preferSource, $preferDist] = ConsoleUtil::getPreferredInstallOptions($config, $this->input);
$optimize = $this->input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
$authoritative = $this->input->getOption('classmap-authoritative') || $config->get('classmap-authoritative');
$apcu = $this->input->getOption('apcu-autoloader') || $config->get('apcu-autoloader');
Expand Down Expand Up @@ -168,14 +168,14 @@ protected function restorePreviousLockFile(): void
*/
private function getLockValue(string $key, mixed $default = null): mixed
{
return isset($this->lock[$key]) ? $this->lock[$key] : $default;
return $this->lock[$key] ?? $default;
}

/**
* Get the installer.
*/
private function getInstaller(): Installer
{
return null !== $this->installer ? $this->installer : Installer::create($this->io, $this->composer);
return $this->installer ?? Installer::create($this->io, $this->composer);
}
}
42 changes: 17 additions & 25 deletions src/Foxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,23 @@ final class Foxy implements PluginInterface, EventSubscriberInterface
/**
* The list of the classes of asset managers.
*/
private static $assetManagers = array(
'Foxy\Asset\NpmManager',
'Foxy\Asset\PnpmManager',
'Foxy\Asset\YarnManager',
);
private static $assetManagers = [
\Foxy\Asset\NpmManager::class,
\Foxy\Asset\PnpmManager::class,
\Foxy\Asset\YarnManager::class,
];

/**
* The default values of config.
*/
private static $defaultConfig = array(
private static $defaultConfig = [
'enabled' => true,
'manager' => null,
'manager-version' => array(
'manager-version' => [
'npm' => '>=5.0.0',
'pnpm' => '>=7.0.0',
'yarn' => '>=1.0.0',
),
],
'manager-bin' => null,
'manager-options' => null,
'manager-install-options' => null,
Expand All @@ -104,25 +104,17 @@ final class Foxy implements PluginInterface, EventSubscriberInterface
'run-asset-manager' => true,
'fallback-asset' => true,
'fallback-composer' => true,
'enable-packages' => array(),
);
'enable-packages' => [],
];

public static function getSubscribedEvents(): array
{
return array(
ComposerUtil::getInitEventName() => array(
array('init', 100),
),
PackageEvents::POST_PACKAGE_INSTALL => array(
array('initOnInstall', 100),
),
ScriptEvents::POST_INSTALL_CMD => array(
array('solveAssets', 100),
),
ScriptEvents::POST_UPDATE_CMD => array(
array('solveAssets', 100),
),
);
return [
ComposerUtil::getInitEventName() => [['init', 100]],
PackageEvents::POST_PACKAGE_INSTALL => [['initOnInstall', 100]],
ScriptEvents::POST_INSTALL_CMD => [['solveAssets', 100]],
ScriptEvents::POST_UPDATE_CMD => [['solveAssets', 100]],
];
}

public function activate(Composer $composer, IOInterface $io): void
Expand Down Expand Up @@ -199,7 +191,7 @@ public function setSolver(SolverInterface $solver): void
*/
public function solveAssets(Event $event): void
{
$this->solver->setUpdatable(false !== strpos($event->getName(), 'update'));
$this->solver->setUpdatable(str_contains($event->getName(), 'update'));
$this->solver->solve($event->getComposer(), $event->getIO());
}

Expand Down
Loading

0 comments on commit 15c3fd6

Please sign in to comment.