Skip to content

Commit

Permalink
Fix ecs issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 20, 2024
1 parent d021652 commit 584e9b7
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 50 deletions.
8 changes: 4 additions & 4 deletions src/Asset/AbstractAssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ protected function buildCommand(string $defaultBin, string $action, array|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', ''));
$options = trim($this->config->get('manager-' . $action . '-options', ''));

return $bin.' '.implode(' ', (array) $command)
.(empty($gOptions) ? '' : ' '.$gOptions)
.(empty($options) ? '' : ' '.$options);
return $bin . ' ' . implode(' ', (array) $command)
. (empty($gOptions) ? '' : ' ' . $gOptions)
. (empty($options) ? '' : ' ' . $options);
}

protected function getVersion(): string|null
Expand Down
4 changes: 0 additions & 4 deletions src/Asset/AssetManagerFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public function addManager(AssetManagerInterface $manager): void
*
* @param null|string $manager The name of the asset manager
*
* @return AssetManagerInterface
*
* @throws RuntimeException When the asset manager does not exist
* @throws RuntimeException When the asset manager is not found
*/
Expand All @@ -72,8 +70,6 @@ public function findManager(string $manager = null): AssetManagerInterface
/**
* Find the available asset manager.
*
* @return AssetManagerInterface
*
* @throws RuntimeException When no asset manager is found
*/
private function findAvailableManager(): AssetManagerInterface
Expand Down
2 changes: 0 additions & 2 deletions src/Asset/AssetManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public function validate(): void;
*
* @param RootPackageInterface $rootPackage The composer root package
* @param array $dependencies The asset local dependencies
*
* @return AssetPackageInterface
*/
public function addDependencies(RootPackageInterface $rootPackage, array $dependencies): AssetPackageInterface;

Expand Down
2 changes: 1 addition & 1 deletion src/Asset/AssetPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function addNewDependencies(array $dependencies): array
if (isset($installedAssets[$name])) {
$existingPackages[] = $name;
} else {
$this->package[self::SECTION_DEPENDENCIES][$name] = 'file:./'.\dirname($path);
$this->package[self::SECTION_DEPENDENCIES][$name] = 'file:./' . \dirname($path);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function get(string $key, mixed $default = null): mixed
*/
private function convertEnvKey(string $key): string
{
return 'FOXY__'.strtoupper(str_replace('-', '_', $key));
return 'FOXY__' . strtoupper(str_replace('-', '_', $key));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static function getConfigBase(Composer $composer, IOInterface $io = null
private static function getGlobalConfig(Composer $composer, string $filename, IOInterface $io = null): array
{
$home = self::getComposerHome($composer);
$file = new JsonFile($home.'/'.$filename.'.json');
$file = new JsonFile($home . '/' . $filename . '.json');
$config = array();

if ($file->exists()) {
Expand All @@ -76,7 +76,7 @@ private static function getGlobalConfig(Composer $composer, string $filename, IO
$config = $data['config']['foxy'];

if ($io instanceof IOInterface && $io->isDebug()) {
$io->writeError('Loading Foxy config in file '.$file->getPath());
$io->writeError('Loading Foxy config in file ' . $file->getPath());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Converter/SemverConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class SemverConverter implements VersionConverterInterface
public function convertVersion(string $version = null): string
{
if (\in_array($version, array(null, '', 'latest'), true)) {
return ('latest' === $version ? 'default || ' : '').'*';
return ('latest' === $version ? 'default || ' : '') . '*';
}

$version = str_replace('', '-', $version);
Expand All @@ -32,6 +32,6 @@ public function convertVersion(string $version = null): string
$version = SemverUtil::convertVersionMetadata($version);
$version = SemverUtil::convertDateVersion($version);

return $prefix.$version;
return $prefix . $version;
}
}
14 changes: 6 additions & 8 deletions src/Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ public static function convertDateVersion(string $version): string
{
if (preg_match('/^\d{7,}\./', $version)) {
$pos = strpos($version, '.');
$version = substr($version, 0, $pos).self::convertDateMinorVersion(substr($version, $pos + 1));
$version = substr($version, 0, $pos) . self::convertDateMinorVersion(substr($version, $pos + 1));
}

return $version;
}

/**
* Converts the version metadata.
*
* @param string $version
*/
public static function convertVersionMetadata(string $version): string
{
Expand Down Expand Up @@ -75,10 +73,10 @@ public static function convertVersionMetadata(string $version): string
public static function createPattern(string $pattern): string
{
$numVer = '([0-9]+|x|\*)';
$numVer2 = '('.$numVer.'\.'.$numVer.')';
$numVer3 = '('.$numVer.'\.'.$numVer.'\.'.$numVer.')';
$numVer2 = '(' . $numVer . '\.' . $numVer . ')';
$numVer3 = '(' . $numVer . '\.' . $numVer . '\.' . $numVer . ')';

return '/^('.$numVer.'|'.$numVer2.'|'.$numVer3.')'.$pattern.'/';
return '/^(' . $numVer . '|' . $numVer2 . '|' . $numVer3 . ')' . $pattern . '/';
}

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

$matches = array();
if (preg_match('/^([-+])/', $end, $matches)) {
Expand Down Expand Up @@ -178,6 +176,6 @@ private static function convertDateMinorVersion(string $minor): string
$minor = (int) $split[0];
$revision = isset($split[1]) ? (int) $split[1] : 0;

return '.'.sprintf('%03d', $minor).sprintf('%03d', $revision);
return '.' . sprintf('%03d', $minor) . sprintf('%03d', $revision);
}
}
2 changes: 1 addition & 1 deletion src/Event/AbstractSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractSolveEvent extends Event
* @param string $name The event name.
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
*
*
* @psalm-param PackageInterface[] $packages All installed Composer packages.
*/
public function __construct(string $name, private string $assetDir, private array $packages = [])
Expand Down
2 changes: 1 addition & 1 deletion src/Event/GetAssetsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class GetAssetsEvent extends AbstractSolveEvent
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
* @param array $assets The map of asset package name and the asset package path.
*
*
* @psalm-param PackageInterface[] $packages All installed Composer packages.
*/
public function __construct(string $assetDir, array $packages, private array $assets = [])
Expand Down
2 changes: 1 addition & 1 deletion src/Event/PostSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class PostSolveEvent extends AbstractSolveEvent
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
* @param int $runResult The process result of asset manager execution.
*
*
* @psalm-param PackageInterface[] $packages All installed Composer packages.
*/
public function __construct($assetDir, array $packages, private int $runResult)
Expand Down
2 changes: 1 addition & 1 deletion src/Event/PreSolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class PreSolveEvent extends AbstractSolveEvent
*
* @param string $assetDir The directory of mock assets.
* @param array $packages All installed Composer packages.
*
*
* @psalm-param PackageInterface[] $packages All installed Composer packages.
*/
public function __construct(string $assetDir, array $packages = [])
Expand Down
1 change: 0 additions & 1 deletion src/Fallback/AssetFallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Composer\IO\IOInterface;
use Composer\Util\Filesystem;
use Foxy\Config\Config;
use PHPUnit\TextUI\XmlConfiguration\File;

/**
* Asset fallback.
Expand Down
4 changes: 1 addition & 3 deletions src/Json/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public function write(array $hash, int $options = 448): void
self::$encodeIndent = 4;
}

/**
* {@inheritdoc}
*/

public static function encode(mixed $data, int $options = 448, string $indent = self::INDENT_DEFAULT): string
{
$result = parent::encode($data, $options, $indent);
Expand Down
4 changes: 0 additions & 4 deletions src/Json/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public static function getIndent(string $content): int
* @param array $arrayKeys The list of keys to be retained with an array representation if they are empty.
* @param int $indent The space count for indent.
* @param bool $formatJson Check if the json must be formatted.
*
* @return string
*/
public static function format(
string $json,
Expand Down Expand Up @@ -125,8 +123,6 @@ static function (mixed $match) {
* @param array $arrayKeys The list of keys to be retained with an array representation if they are empty.
*
* @psalm-param string[] $arrayKeys The list of keys to be retained with an array representation if they are empty.
*
* @return string
*/
private static function replaceArrayByMap(string $json, array $arrayKeys): string
{
Expand Down
13 changes: 6 additions & 7 deletions src/Solver/Solver.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ final class Solver implements SolverInterface
/**
* Constructor.
*
* @param AssetManagerInterface $assetManager The asset manager
* @param Config $config The config
* @param Filesystem $filesystem The composer filesystem
* @param null|FallbackInterface $composerFallback The composer fallback
* @param AssetManagerInterface $assetManager The asset manager instance.
* @param Config $config The config instance.
* @param null|FallbackInterface $composerFallback The composer fallback instance.
*/
public function __construct(
protected AssetManagerInterface $assetManager,
Expand All @@ -66,7 +65,7 @@ public function solve(Composer $composer, IOInterface $io): void
$dispatcher = $composer->getEventDispatcher();
$packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();
$vendorDir = $composer->getConfig()->get('vendor-dir');
$assetDir = $this->config->get('composer-asset-dir', $vendorDir.'/foxy/composer-asset/');
$assetDir = $this->config->get('composer-asset-dir', $vendorDir . '/foxy/composer-asset/');
$dispatcher->dispatch(FoxyEvents::PRE_SOLVE, new PreSolveEvent($assetDir, $packages));
$this->fs->remove($assetDir);

Expand Down Expand Up @@ -125,8 +124,8 @@ protected function getAssets(Composer $composer, string $assetDir, array $packag
protected function getMockPackagePath(PackageInterface $package, string $assetDir, string $filename): array
{
$packageName = AssetUtil::getName($package);
$packagePath = \rtrim($assetDir, '/').'/'.$package->getName();
$newFilename = $packagePath.'/'. \basename($filename);
$packagePath = \rtrim($assetDir, '/') . '/' . $package->getName();
$newFilename = $packagePath . '/' . \basename($filename);

\mkdir($packagePath, 0777, true);
\copy($filename, $newFilename);
Expand Down
10 changes: 5 additions & 5 deletions src/Util/AssetUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AssetUtil
*
* @param PackageInterface $package The package instance.
*/
public static function getName(PackageInterface $package): string
public static function getName(PackageInterface $package): string
{
return AssetPackage::COMPOSER_PREFIX . \str_replace(array('/'), '--', $package->getName());
}
Expand All @@ -45,16 +45,16 @@ public static function getName(PackageInterface $package): string
* @param array $configPackages The packages defined in config.
*/
public static function getPath(
InstallationManager $installationManager,
AssetManagerInterface $assetManager,
PackageInterface $package,
InstallationManager $installationManager,
AssetManagerInterface $assetManager,
PackageInterface $package,
array $configPackages = []
): string|null {
$path = null;

if (static::isAsset($package, $configPackages)) {
$installPath = $installationManager->getInstallPath($package);
$filename = $installPath.'/'.$assetManager->getPackageName();
$filename = $installPath . '/' . $assetManager->getPackageName();
$path = \file_exists($filename) ? \str_replace('\\', '/', \realpath($filename)) : null;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Util/LockerUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

namespace Foxy\Util;

use Composer\Composer;
use Composer\Installer\InstallationManager;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Package\Locker;
use Composer\Repository\RepositoryManager;

/**
* Helper for Locker.
Expand Down

0 comments on commit 584e9b7

Please sign in to comment.