Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ jobs:
fail-fast: false
matrix:
include:
- php: '7.4'
phpcq_install: 'update'
phpcq_flags: ''
- php: '8.0'
phpcq_install: 'update'
phpcq_flags: ''
- php: '8.1'
phpcq_install: 'update'
phpcq_flags: ''
Expand All @@ -35,6 +29,9 @@ jobs:
- php: '8.4'
phpcq_install: 'update'
phpcq_flags: ''
- php: '8.5'
phpcq_install: 'update'
phpcq_flags: ''
steps:
- name: Pull source
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .phpcq.lock

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .phpcq.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ phpcq:
composer-normalize:
version: ^1.0
signed: false
rector:
version: ^1.0
signed: false

trusted-keys:
# composer-require-checker
- 033E5F8D801A2F8D
Expand All @@ -42,6 +46,7 @@ phpcq:
# psalm
- 8A03EA3B385DBAA1
- 12CE0F1D262429A5
- 99BF4D9A33D65E1E
# magl@magll.net
- D2CCAC42F6295E7D
# PHP_CodeSniffer
Expand All @@ -51,10 +56,13 @@ phpcq:
- C00543248C87FB13
# PHPMD
- 9093F8B32E4815AA
# PHPCQ
- 6659B17090D6C5D3

tasks:
fix:
- composer-normalize-fix
- rector-fix
- phpcbf

verify:
Expand All @@ -68,6 +76,7 @@ tasks:
- phpcs
- psalm
- phpunit
- rector

default:
- verify
Expand Down Expand Up @@ -106,3 +115,8 @@ tasks:
psalm:
config:
auto_php_version: false

rector-fix:
plugin: rector
config:
dry-run: false
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-filter": "*",
"ext-hash": "*",
"ext-json": "*"
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\Class_\AddTestsVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withRootFiles()
->withRules([
FinalizeTestCaseClassRector::class,
AddTestsVoidReturnTypeWhereNoReturnRector::class,
])
->withSets([
LevelSetList::UP_TO_PHP_81,
]);
17 changes: 4 additions & 13 deletions src/AbstractHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ abstract class AbstractHash
public const SHA_384 = 'sha-384';
public const SHA_512 = 'sha-512';

/** @var string */
private $type;

/** @var string */
private $value;

public function getType(): string
{
return $this->type;
Expand Down Expand Up @@ -66,20 +60,17 @@ public static function createForFile(string $absolutePath, string $type = self::
/** @return static */
public static function createForString(string $contents, string $type = self::SHA_512): self
{
return static::create($type, (string) hash(self::HASHMAP[$type], $contents));
return static::create($type, hash(self::HASHMAP[$type], $contents));
}

/**
* @throws InvalidHashException When the hash type is unknown.
*/
final private function __construct(string $type, string $value)
final private function __construct(private readonly string $type, private readonly string $value)
{
if (!in_array($type, [self::SHA_1, self::SHA_256, self::SHA_384, self::SHA_512])) {
throw new InvalidHashException($type, $value);
if (!in_array($this->type, [self::SHA_1, self::SHA_256, self::SHA_384, self::SHA_512])) {
throw new InvalidHashException($this->type, $this->value);
}

$this->type = $type;
$this->value = $value;
}

final public function equals(AbstractHash $other): bool
Expand Down
18 changes: 2 additions & 16 deletions src/Exception/InvalidHashException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@

class InvalidHashException extends RuntimeException
{
/** @var string */
private $hashType;

/** @var string */
private $hashValue;

/**
* Create a new instance.
*
* @param string $hashType
* @param string $hashValue
*/
public function __construct(string $hashType, string $hashValue)
public function __construct(private readonly string $hashType, private readonly string $hashValue)
{
$this->hashType = $hashType;
$this->hashValue = $hashValue;
parent::__construct('Invalid hash type: ' . $hashType . ' (' . $hashValue . ')');
parent::__construct('Invalid hash type: ' . $this->hashType . ' (' . $this->hashValue . ')');
}

public function getHashType(): string
Expand Down
29 changes: 7 additions & 22 deletions src/Plugin/AbstractPluginVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,23 @@

abstract class AbstractPluginVersion implements PluginVersionInterface
{
private string $name;
private readonly string $apiVersion;

private string $version;

private string $apiVersion;

private PluginHash $hash;

private PluginRequirements $requirements;

private string $filePath;

private ?string $signaturePath;
private readonly PluginRequirements $requirements;

public function __construct(
string $name,
string $version,
private readonly string $name,
private readonly string $version,
string $apiVersion,
?PluginRequirements $requirements,
string $filePath,
?string $signaturePath,
PluginHash $hash
private readonly string $filePath,
private readonly ?string $signaturePath,
private readonly PluginHash $hash
) {
if ($apiVersion !== '1.0.0') {
throw new RuntimeException('Invalid version string: ' . $apiVersion);
}
$this->name = $name;
$this->version = $version;
$this->apiVersion = $apiVersion;
$this->hash = $hash;
$this->filePath = $filePath;
$this->signaturePath = $signaturePath;
$this->requirements = $requirements ?? new PluginRequirements();
}

Expand Down
8 changes: 1 addition & 7 deletions src/Plugin/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
*/
class Plugin implements IteratorAggregate, PluginInterface
{
/**
* The name of the plugin.
*/
private string $name;

/**
* All versions of the plugin.
*
Expand All @@ -34,9 +29,8 @@ class Plugin implements IteratorAggregate, PluginInterface
*
* @param string $name The name of the plugin.
*/
public function __construct(string $name)
public function __construct(private readonly string $name)
{
$this->name = $name;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/RepositoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class RepositoryLoader
/** @psalm-var array<string, Plugin> */
private array $plugins = [];

private JsonFileLoaderInterface $fileLoader;
private readonly JsonFileLoaderInterface $fileLoader;

/**
* @psalm-param TRepositoryCheckSum|null $checksum
Expand Down Expand Up @@ -336,7 +336,7 @@ private function validateUrlOrFile(string $url, string $baseDir): string
}
// Perform URL check.
$path = (string) parse_url($url, PHP_URL_PATH);
$encodedPath = array_map('urlencode', explode('/', $path));
$encodedPath = array_map(urlencode(...), explode('/', $path));
$newUrl = str_replace($path, implode('/', $encodedPath), $url);
if (filter_var($newUrl, FILTER_VALIDATE_URL)) {
return $newUrl;
Expand Down
8 changes: 1 addition & 7 deletions src/Tool/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
*/
class Tool implements IteratorAggregate, ToolInterface
{
/**
* The name of the tool.
*/
private string $name;

/**
* All versions of the tool.
*
Expand All @@ -34,9 +29,8 @@ class Tool implements IteratorAggregate, ToolInterface
*
* @param string $name The name of the tool.
*/
public function __construct(string $name)
public function __construct(private readonly string $name)
{
$this->name = $name;
}

/**
Expand Down
27 changes: 6 additions & 21 deletions src/Tool/ToolVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,16 @@

class ToolVersion implements ToolVersionInterface
{
private string $name;

private string $version;

private ?string $pharUrl;

private ?string $signatureUrl;

private ?ToolHash $hash;

private ToolRequirements $requirements;
private readonly ToolRequirements $requirements;

public function __construct(
string $name,
string $version,
?string $pharUrl,
private readonly string $name,
private readonly string $version,
private ?string $pharUrl,
?ToolRequirements $requirements,
?ToolHash $hash,
?string $signatureUrl
private ?ToolHash $hash,
private ?string $signatureUrl
) {
$this->name = $name;
$this->version = $version;
$this->pharUrl = $pharUrl;
$this->hash = $hash;
$this->signatureUrl = $signatureUrl;
$this->requirements = $requirements ?? new ToolRequirements();
}

Expand Down
8 changes: 1 addition & 7 deletions src/VersionRequirement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

class VersionRequirement
{
private string $name;

private string $constraint;

/**
* Create a new instance.
*
* @param string $name
* @param string $constraint
*/
public function __construct(string $name, string $constraint = '*')
public function __construct(private readonly string $name, private readonly string $constraint = '*')
{
$this->name = $name;
$this->constraint = $constraint;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Plugin/PhpFilePluginVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @covers \Phpcq\RepositoryDefinition\Plugin\AbstractPluginVersion
* @covers \Phpcq\RepositoryDefinition\Plugin\PhpFilePluginVersion
*/
class PhpFilePluginVersionTest extends TestCase
final class PhpFilePluginVersionTest extends TestCase
{
public function testGetters(): void
{
Expand Down
Loading
Loading