Skip to content

Commit

Permalink
Psalm 3. (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Jan 20, 2024
1 parent 3ec935d commit e07c8f6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
errorLevel="3"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
Expand Down
16 changes: 11 additions & 5 deletions src/Asset/AbstractAssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ abstract class AbstractAssetManager implements AssetManagerInterface
{
final public const NODE_MODULES_PATH = './node_modules';
protected bool $updatable = true;
protected VersionConverterInterface|null $versionConverter;
private null|string $version = '';

public function __construct(
Expand All @@ -44,9 +43,9 @@ public function __construct(
protected ProcessExecutor $executor,
protected Filesystem $fs,
protected FallbackInterface|null $fallback = null,
VersionConverterInterface|null $versionConverter = null
protected VersionConverterInterface|null $versionConverter = null
) {
$this->versionConverter = $versionConverter ?? new SemverConverter();
$this->versionConverter ??= new SemverConverter();
}

public function isAvailable(): bool
Expand Down Expand Up @@ -107,7 +106,14 @@ public function validate(): void
$constraint = $parser->parseConstraints($constraintVersion);

if (!$constraint->matches($parser->parseConstraints($version))) {
throw new RuntimeException(sprintf('The installed %s version "%s" doesn\'t match with the constraint version "%s"', $this->getName(), $version, $constraintVersion));
throw new RuntimeException(
sprintf(
'The installed %s version "%s" doesn\'t match with the constraint version "%s"',
$this->getName(),
$version,
$constraintVersion
)
);
}
}
}
Expand Down Expand Up @@ -182,7 +188,7 @@ protected function buildCommand(string $defaultBin, string $action, array|string

protected function getVersion(): string|null
{
if ('' === $this->version) {
if ($this->version === '' && $this->versionConverter !== null) {
$this->executor->execute($this->getVersionCommand(), $version);
$this->version = '' !== trim((string) $version) ? $this->versionConverter->convertVersion(trim((string) $version)) : null;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Asset/AssetPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public function getInstalledDependencies(): array
return $installedAssets;
}

/**
* Add new dependencies.
*
* @param array $dependencies The dependencies
*
* @return array The existing packages.
*
* @psalm-return list<string> The existing packages.
*/
public function addNewDependencies(array $dependencies): array
{
$installedAssets = $this->getInstalledDependencies();
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/YarnManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function isYarnNext(): bool
$parser = new VersionParser();
$constraint = $parser->parseConstraints('>=2.0.0');

return $constraint->matches($parser->parseConstraints($version));
return $version !== null ? $constraint->matches($parser->parseConstraints($version)) : false;
}

private function mergeInteractiveCommand(array $command): array
Expand Down
18 changes: 11 additions & 7 deletions src/Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ 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));

if ($pos !== false) {
$version = substr($version, 0, $pos) . self::convertDateMinorVersion(substr($version, $pos + 1));
}
}

return $version;
Expand All @@ -42,12 +45,13 @@ public static function convertDateVersion(string $version): string
*/
public static function convertVersionMetadata(string $version): string
{
if (preg_match_all(
self::createPattern('([a-zA-Z]+|(\-|\+)[a-zA-Z]+|(\-|\+)[0-9]+)'),
$version,
$matches,
PREG_OFFSET_CAPTURE
)) {
$pattern = self::createPattern('([a-zA-Z]+|(\-|\+)[a-zA-Z]+|(\-|\+)[0-9]+)');

if ($pattern === '') {
return $version;
}

if (preg_match_all($pattern, $version, $matches, PREG_OFFSET_CAPTURE)) {
[$type, $version, $end] = self::cleanVersion(strtolower($version), $matches);
[$version, $patchVersion] = self::matchVersion($version, $type);

Expand Down
2 changes: 2 additions & 0 deletions src/Foxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ final class Foxy implements PluginInterface, EventSubscriberInterface

/**
* The list of the classes of asset managers.
*
* @psalm-var list<class-string<AssetManagerInterface>>
*/
private static $assetManagers = [
Asset\NpmManager::class,
Expand Down

0 comments on commit e07c8f6

Please sign in to comment.