From 4c392377f7ae06f5425bbcce8c898c91f9c986aa Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Thu, 13 May 2021 00:35:28 +0200 Subject: [PATCH 1/2] applied php-cs-fixer "Symfony:risky" --- .php-cs-fixer.dist.php | 1 + src/BuildParseTrait.php | 6 +++--- src/PackageUrl.php | 2 +- src/PackageUrlBuilder.php | 10 +++++----- src/PackageUrlParser.php | 2 +- tests/PackageUrlBuilderTest.php | 2 +- tests/PackageUrlParserTest.php | 2 +- tests/PackageUrlTest.php | 6 +++--- tests/_data/TestSuiteData.php | 2 +- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 3c02ad6..116919d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -43,6 +43,7 @@ ->setRules([ '@PHP73Migration' => true, '@Symfony' => true, + '@Symfony:risky' => true, 'declare_strict_types' => true, 'phpdoc_order' => true, 'header_comment' => ['header' => $header], diff --git a/src/BuildParseTrait.php b/src/BuildParseTrait.php index a2a0ebc..d8b8798 100644 --- a/src/BuildParseTrait.php +++ b/src/BuildParseTrait.php @@ -51,7 +51,7 @@ private function isNotEmpty(string $data): bool */ private function isUsefulSubpathSegment(string $segment): bool { - return false === in_array($segment, ['', '.', '..'], true); + return false === \in_array($segment, ['', '.', '..'], true); } /** @@ -62,7 +62,7 @@ private function getNormalizerForNamespace(?string $type): Closure if (null !== $type) { $type = strtolower($type); } - if (in_array($type, ['bitbucket', 'deb', 'github', 'golang', 'hex', 'rpm'], true)) { + if (\in_array($type, ['bitbucket', 'deb', 'github', 'golang', 'hex', 'rpm'], true)) { return static function (string $data): string { return strtolower($data); }; @@ -92,7 +92,7 @@ private function normalizeNameForType(string $name, ?string $type): string $name = str_replace('_', '-', $name); } - if (in_array($type, ['bitbucket', 'deb', 'github', 'golang', 'hex', 'npm', 'pypi'], true)) { + if (\in_array($type, ['bitbucket', 'deb', 'github', 'golang', 'hex', 'npm', 'pypi'], true)) { $name = strtolower($name); } diff --git a/src/PackageUrl.php b/src/PackageUrl.php index 7259734..20738ce 100644 --- a/src/PackageUrl.php +++ b/src/PackageUrl.php @@ -186,7 +186,7 @@ public function getQualifiers(): ?array */ public function setQualifiers(?array $qualifiers): self { - if ($qualifiers && array_key_exists(self::CHECKSUM_QUALIFIER, $qualifiers)) { + if ($qualifiers && \array_key_exists(self::CHECKSUM_QUALIFIER, $qualifiers)) { throw new DomainException('Checksums must not be part of the qualifiers. Use setChecksums().'); } $this->qualifiers = $qualifiers; diff --git a/src/PackageUrlBuilder.php b/src/PackageUrlBuilder.php index 173877c..409afd7 100644 --- a/src/PackageUrlBuilder.php +++ b/src/PackageUrlBuilder.php @@ -168,7 +168,7 @@ public function normalizeQualifiers(?array $data): ?string $segments = []; - $data = array_change_key_case($data, CASE_LOWER); + $data = array_change_key_case($data, \CASE_LOWER); $checksum = $this->normalizeChecksum($data[PackageUrl::CHECKSUM_QUALIFIER] ?? null); unset($data[PackageUrl::CHECKSUM_QUALIFIER]); @@ -190,7 +190,7 @@ public function normalizeQualifiers(?array $data): ?string $segments[] = PackageUrl::CHECKSUM_QUALIFIER.'='.$checksum; } - sort($segments, SORT_STRING); + sort($segments, \SORT_STRING); $qualifiers = implode('&', $segments); return '' === $qualifiers @@ -207,9 +207,9 @@ private function normalizeChecksum($data): ?string if (null === $data) { return null; } - if (is_string($data)) { + if (\is_string($data)) { $data = explode(',', $data); - } elseif (!is_array($data)) { + } elseif (!\is_array($data)) { return null; } @@ -276,7 +276,7 @@ private function encode(string $data): string rawurlencode($data), self::RAWURLENCODE_REVERT ); - assert('' !== $encoded); + \assert('' !== $encoded); return $encoded; } diff --git a/src/PackageUrlParser.php b/src/PackageUrlParser.php index 62094e1..1ee9da2 100644 --- a/src/PackageUrlParser.php +++ b/src/PackageUrlParser.php @@ -233,7 +233,7 @@ public function normalizeQualifiers(?string $data): array continue; } $key = strtolower(substr($dataKeyValue, 0, $eqPos)); - assert('' !== $key); + \assert('' !== $key); $qualifiers[$key] = $value; } diff --git a/tests/PackageUrlBuilderTest.php b/tests/PackageUrlBuilderTest.php index 2a74e59..0ca5df8 100644 --- a/tests/PackageUrlBuilderTest.php +++ b/tests/PackageUrlBuilderTest.php @@ -47,7 +47,7 @@ class PackageUrlBuilderTest extends TestCase /** @var PackageUrlBuilder */ private $sut; - public function setUp(): void + protected function setUp(): void { $this->sut = new PackageUrlBuilder(); } diff --git a/tests/PackageUrlParserTest.php b/tests/PackageUrlParserTest.php index 6a78e5d..5f960d3 100644 --- a/tests/PackageUrlParserTest.php +++ b/tests/PackageUrlParserTest.php @@ -45,7 +45,7 @@ class PackageUrlParserTest extends TestCase /** @var PackageUrlParser */ private $sut; - public function setUp(): void + protected function setUp(): void { $this->sut = new PackageUrlParser(); } diff --git a/tests/PackageUrlTest.php b/tests/PackageUrlTest.php index 41a9192..5fd920c 100644 --- a/tests/PackageUrlTest.php +++ b/tests/PackageUrlTest.php @@ -43,7 +43,7 @@ class PackageUrlTest extends TestCase /** @var PackageUrl */ private $sut; - public function setUp(): void + protected function setUp(): void { $randomString = bin2hex(random_bytes(255)); $this->sut = (new PackageUrl($randomString, $randomString)) @@ -282,7 +282,7 @@ public function testFromString(): void // act $purl = $this->sut::fromString($purlString, $parser); // assert - self::assertInstanceOf(get_class($this->sut), $purl); + self::assertInstanceOf(\get_class($this->sut), $purl); self::assertEquals($purlNormalized['type'], $purl->getType()); self::assertEquals($purlNormalized['namespace'], $purl->getNamespace()); self::assertEquals($purlNormalized['name'], $purl->getName()); @@ -311,7 +311,7 @@ private static function parsedToNulls(): array public function testAsString(): void { $expected = bin2hex(random_bytes(32)); - $sut = $this->createPartialMock(get_class($this->sut), ['toString']); + $sut = $this->createPartialMock(\get_class($this->sut), ['toString']); $sut->expects(self::once())->method('toString')->willReturn($expected); $toString = (string) $sut; self::assertEquals($expected, $toString); diff --git a/tests/_data/TestSuiteData.php b/tests/_data/TestSuiteData.php index 0a75973..31565cb 100644 --- a/tests/_data/TestSuiteData.php +++ b/tests/_data/TestSuiteData.php @@ -65,7 +65,7 @@ abstract class TestSuiteData */ public static function data(): Generator { - $testSuite = json_decode(file_get_contents(__DIR__.'/../_examples/test-suite-data.json'), true, 521, JSON_THROW_ON_ERROR); + $testSuite = json_decode(file_get_contents(__DIR__.'/../_examples/test-suite-data.json'), true, 521, \JSON_THROW_ON_ERROR); foreach ($testSuite as $data) { yield $data['description'] => [$data]; } From 83a51d44152d0c221e2e12adf6b6bad082e48cc6 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Thu, 13 May 2021 00:46:06 +0200 Subject: [PATCH 2/2] wrote latest HISTORY --- HISTORY.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 81fb990..3423902 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,20 @@ # Changes +## 1.0.2 + +Maintenance release: +* Misc + * Applied QA tool `php-cs-fixer` rule `@Symfony:risky`. + +## 1.0.1 + +Maintenance release: +* Docs + * Upgraded install instructions in the `README.md`. +* Misc + * Upgraded the internally used QA tools in development processes, + Update `php-cs-fixer` to v3. + ## 1.0.0 * First implementation