Skip to content

Commit

Permalink
Psalm 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jan 20, 2024
1 parent e07c8f6 commit c88c6db
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 42 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="3"
errorLevel="2"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
Expand Down
8 changes: 3 additions & 5 deletions src/Converter/SemverUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ public static function convertVersionMetadata(string $version): string
{
$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)) {
if (preg_match_all($pattern, $version, $matches, PREG_OFFSET_CAPTURE) > 0) {
[$type, $version, $end] = self::cleanVersion(strtolower($version), $matches);
[$version, $patchVersion] = self::matchVersion($version, $type);

Expand All @@ -73,6 +69,8 @@ public static function convertVersionMetadata(string $version): string
* @param string $pattern The pattern without '/'.
*
* @return string The full pattern with '/'.
*
* @psalm-return non-empty-string
*/
public static function createPattern(string $pattern): string
{
Expand Down
42 changes: 10 additions & 32 deletions src/Foxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,18 @@
* Composer plugin.
*
* @author François Pluchino <francois.pluchino@gmail.com>
*
* @psalm-suppress MissingConstructor
*/
final class Foxy implements PluginInterface, EventSubscriberInterface
{
public const REQUIRED_COMPOSER_VERSION = '^2.0.0';

/**
* @var Config
*/
protected $config;

/**
* @var AssetManagerInterface
*/
protected $assetManager;

/**
* @var AssetFallback
*/
protected $assetFallback;

/**
* @var ComposerFallback
*/
protected $composerFallback;

/**
* @var SolverInterface
*/
protected $solver;

/**
* @var bool
*/
protected $initialized = false;
final public const REQUIRED_COMPOSER_VERSION = '^2.0.0';
private Config $config;
private AssetManagerInterface $assetManager;
private AssetFallback $assetFallback;
private ComposerFallback $composerFallback;
private SolverInterface $solver;
private bool $initialized = false;

/**
* The list of the classes of asset managers.
Expand All @@ -89,7 +67,7 @@ final class Foxy implements PluginInterface, EventSubscriberInterface
/**
* The default values of config.
*/
private static $defaultConfig = [
private static array $defaultConfig = [
'enabled' => true,
'manager' => null,
'manager-version' => [
Expand Down
4 changes: 2 additions & 2 deletions src/Json/JsonFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class JsonFile extends \Composer\Json\JsonFile
{
/**
* @psalm-var string[]|null
* @psalm-var string[]
*/
private array $arrayKeys = [];
private int|null $indent = null;
Expand All @@ -42,7 +42,7 @@ public function getArrayKeys(): array
$this->parseOriginalContent();
}

return $this->arrayKeys ?? [];
return $this->arrayKeys;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Json/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private static function formatInternal(string $json, bool $unescapeUnicode, bool
$array = \json_decode($json, true);

if ($unescapeUnicode) {
\array_walk_recursive($array, function (&$item): void {
\array_walk_recursive($array, function (mixed &$item): void {
if (\is_string($item)) {
$item = \preg_replace_callback(
'/\\\\u([0-9a-fA-F]{4})/',
Expand All @@ -106,7 +106,7 @@ static function (mixed $match) {
}

if ($unescapeSlashes) {
\array_walk_recursive($array, function (&$item): void {
\array_walk_recursive($array, function (mixed &$item): void {
if (\is_string($item)) {
$item = \str_replace('\\/', '/', $item);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Converter/SemverConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Foxy\Tests\Converter;

use Foxy\Converter\SemverConverter;
use Foxy\Converter\SemverUtil;
use Foxy\Converter\VersionConverterInterface;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -100,4 +101,12 @@ public static function getTestVersions(): array
['', '*'],
];
}

public function testConvertVersionMetadataWithEmptyPattern()
{
$version = '1.0.0';
$expected = '1.0.0';

static::assertSame($expected, SemverUtil::convertVersionMetadata($version));
}
}

0 comments on commit c88c6db

Please sign in to comment.