Skip to content

Commit 764ac56

Browse files
committed
Fix CS
1 parent aa5b363 commit 764ac56

5 files changed

Lines changed: 49 additions & 52 deletions

File tree

.php-cs-fixer.dist.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
->setRules(
2424
array_merge(
2525
require __DIR__ . '/vendor/rollerscapes/standards/php-cs-fixer-rules.php',
26-
['header_comment' => ['header' => $header]])
26+
[
27+
'header_comment' => ['header' => $header],
28+
'mb_str_functions' => false,
29+
'php_unit_test_annotation' => ['style' => 'annotation'], // For now
30+
])
2731
)
2832
->setFinder($finder);
2933

src/ContinuesVersionsValidator.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace Rollerworks\Component\Version;
1515

16-
use function count;
17-
1816
final class ContinuesVersionsValidator
1917
{
2018
/** @var Version[] */
@@ -33,7 +31,7 @@ public function __construct(Version ...$versions)
3331

3432
public function isContinues(Version $new): bool
3533
{
36-
if (count($this->versions) === 0) {
34+
if (\count($this->versions) === 0) {
3735
$this->possibleVersions = [
3836
Version::fromString('0.1.0'),
3937
Version::fromString('1.0.0-ALPHA1'),
@@ -53,9 +51,7 @@ public function isContinues(Version $new): bool
5351
return false;
5452
}
5553

56-
/**
57-
* @return Version[]
58-
*/
54+
/** @return Version[] */
5955
public function getPossibleVersions(): array
6056
{
6157
return $this->possibleVersions;
@@ -68,13 +64,13 @@ private function computePossibleVersions(Version $new): void
6864
$major = $new->major;
6965
$minor = $new->minor;
7066

71-
if (!isset($this->resolveVersions[$major])) {
67+
if (! isset($this->resolveVersions[$major])) {
7268
$this->computePossibleVersionsFromLastExisting();
7369

7470
return;
7571
}
7672

77-
if (!isset($this->resolveVersions[$major][$minor])) {
73+
if (! isset($this->resolveVersions[$major][$minor])) {
7874
$minor = $this->getLastArrayIndex($this->resolveVersions[$major]);
7975
}
8076

@@ -83,7 +79,7 @@ private function computePossibleVersions(Version $new): void
8379

8480
private function arrangeExistingVersions(): void
8581
{
86-
usort($this->versions, function (Version $a, Version $b) {
82+
usort($this->versions, static function (Version $a, Version $b) {
8783
return version_compare(strtolower($a->full), strtolower($b->full), '<') ? -1 : 1;
8884
});
8985

@@ -106,9 +102,7 @@ private function computePossibleVersionsFromLastExisting(): void
106102
$this->possibleVersions = $version->getNextVersionCandidates();
107103
}
108104

109-
/**
110-
* @param array<int, mixed> $array
111-
*/
105+
/** @param array<int, mixed> $array */
112106
private function getLastArrayIndex(array $array): int
113107
{
114108
end($array);

src/Version.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ final class Version
6161

6262
private function __construct(int $major, int $minor, int $patch, int $stability, int $metaver = 0)
6363
{
64-
if (0 === $major) {
64+
if ($major === 0) {
6565
$stability = self::STABILITY_ALPHA;
6666
}
6767

@@ -71,12 +71,12 @@ private function __construct(int $major, int $minor, int $patch, int $stability,
7171
$this->stability = $stability;
7272
$this->metaver = $metaver;
7373

74-
if (self::STABILITY_STABLE === $stability && $this->metaver > 0) {
74+
if ($stability === self::STABILITY_STABLE && $this->metaver > 0) {
7575
throw new \InvalidArgumentException('Meta version of the stability flag cannot be set for stable.');
7676
}
7777

7878
if ($major > 0 && $stability < self::STABILITY_STABLE) {
79-
$this->full = sprintf(
79+
$this->full = \sprintf(
8080
'%d.%d.%d-%s%d',
8181
$this->major,
8282
$this->minor,
@@ -85,7 +85,7 @@ private function __construct(int $major, int $minor, int $patch, int $stability,
8585
$this->metaver
8686
);
8787
} else {
88-
$this->full = sprintf('%d.%d.%d', $this->major, $this->minor, $this->patch);
88+
$this->full = \sprintf('%d.%d.%d', $this->major, $this->minor, $this->patch);
8989
}
9090
}
9191

@@ -96,7 +96,7 @@ public function __toString()
9696

9797
public static function fromString(string $version): self
9898
{
99-
if (preg_match('/^v?'.self::VERSION_REGEX.'$/i', $version, $matches)) {
99+
if (preg_match('/^v?' . self::VERSION_REGEX . '$/i', $version, $matches)) {
100100
return new self(
101101
(int) $matches['major'],
102102
(int) $matches['minor'],
@@ -107,8 +107,8 @@ public static function fromString(string $version): self
107107
}
108108

109109
throw new \InvalidArgumentException(
110-
sprintf(
111-
'Unable to parse version "%s" Expects an SemVer compatible version without build-metadata. '.
110+
\sprintf(
111+
'Unable to parse version "%s" Expects an SemVer compatible version without build-metadata. ' .
112112
'Either "1.0.0", "1.0", "1.0" or "1.0.0-beta1", "1.0.0-beta-1"',
113113
$version
114114
)
@@ -134,7 +134,7 @@ public function getNextVersionCandidates(): array
134134
// Pre first-stable, so 0.x-[rc,beta,stable] releases are not considered.
135135
// Use alpha as stability with metaver 1, 0.2-alpha2 is simple ignored.
136136
// If anyone really uses this... not our problem :)
137-
if (0 === $this->major) {
137+
if ($this->major === 0) {
138138
$candidates[] = $this->getNextIncreaseOf('patch');
139139
$candidates[] = $this->getNextIncreaseOf('minor');
140140
$candidates[] = self::fromString('1.0.0-BETA1');
@@ -220,7 +220,7 @@ public function getNextIncreaseOf(string $stability): self
220220

221221
default:
222222
throw new \InvalidArgumentException(
223-
sprintf(
223+
\sprintf(
224224
'Unknown stability "%s", accepts "%s".',
225225
$stability,
226226
implode('", "', ['alpha', 'beta', 'rc', 'stable', 'major', 'next', 'minor', 'patch'])

tests/ContinuesVersionsValidatorTest.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
use Rollerworks\Component\Version\ContinuesVersionsValidator;
1818
use Rollerworks\Component\Version\Version;
1919

20+
/**
21+
* @internal
22+
*/
2023
class ContinuesVersionsValidatorTest extends TestCase
2124
{
22-
/**
23-
* @return iterable<int, string[]>
24-
*/
25+
/** @return iterable<int, string[]> */
2526
public static function provideInitialContinuesVersions(): iterable
2627
{
2728
yield ['0.1.0'];
@@ -31,8 +32,9 @@ public static function provideInitialContinuesVersions(): iterable
3132
}
3233

3334
/**
34-
* @test
3535
* @dataProvider provideInitialContinuesVersions
36+
*
37+
* @test
3638
*/
3739
public function it_accepts_a_continues_version_with_no_pre_existing(string $new): void
3840
{
@@ -50,9 +52,7 @@ public function it_accepts_a_continues_version_with_no_pre_existing(string $new)
5052
);
5153
}
5254

53-
/**
54-
* @return iterable<string, array<int, string[]|string>>
55-
*/
55+
/** @return iterable<string, array<int, string[]|string>> */
5656
public static function provideContinuesVersions(): iterable
5757
{
5858
yield 'unstable #1' => ['0.3', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']];
@@ -67,17 +67,18 @@ public static function provideContinuesVersions(): iterable
6767
}
6868

6969
/**
70-
* @test
7170
* @dataProvider provideContinuesVersions
7271
*
7372
* @param array<int, string> $existing
7473
* @param array<int, string> $possible
74+
*
75+
* @test
7576
*/
7677
public function it_accepts_a_continues_version(string $new, array $existing, array $possible): void
7778
{
7879
$validator = new ContinuesVersionsValidator(...$this->createVersions($existing));
7980

80-
self::assertTrue($validator->isContinues(Version::fromString($new)), sprintf('Excepts instead %s', implode(',', $validator->getPossibleVersions())));
81+
self::assertTrue($validator->isContinues(Version::fromString($new)), \sprintf('Excepts instead %s', implode(',', $validator->getPossibleVersions())));
8182
self::assertEquals($this->createVersions($possible), array_merge([], $validator->getPossibleVersions()));
8283
}
8384

@@ -89,16 +90,14 @@ public function it_accepts_a_continues_version(string $new, array $existing, arr
8990
private function createVersions(array $existing): array
9091
{
9192
return array_map(
92-
function (string $version) {
93+
static function (string $version) {
9394
return Version::fromString($version);
9495
},
9596
$existing
9697
);
9798
}
9899

99-
/**
100-
* @return iterable<int, string[]>
101-
*/
100+
/** @return iterable<int, string[]> */
102101
public static function provideNotInitialContinuesVersions(): iterable
103102
{
104103
yield ['0.2.0'];
@@ -109,8 +108,9 @@ public static function provideNotInitialContinuesVersions(): iterable
109108
}
110109

111110
/**
112-
* @test
113111
* @dataProvider provideNotInitialContinuesVersions
112+
*
113+
* @test
114114
*/
115115
public function it_rejects_non_continues_version_with_no_pre_existing(string $new): void
116116
{
@@ -128,9 +128,7 @@ public function it_rejects_non_continues_version_with_no_pre_existing(string $ne
128128
);
129129
}
130130

131-
/**
132-
* @return iterable<string, array<int, string[]|string>>
133-
*/
131+
/** @return iterable<string, array<int, string[]|string>> */
134132
public static function provideNonContinuesVersions(): iterable
135133
{
136134
yield 'unstable #1' => ['0.5', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']];
@@ -146,11 +144,12 @@ public static function provideNonContinuesVersions(): iterable
146144
}
147145

148146
/**
149-
* @test
150147
* @dataProvider provideNonContinuesVersions
151148
*
152149
* @param array<int, string> $existing
153150
* @param array<int, string> $possible
151+
*
152+
* @test
154153
*/
155154
public function it_rejects_non_continues_version(string $new, array $existing, array $possible): void
156155
{

tests/VersionTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use PHPUnit\Framework\TestCase;
1717
use Rollerworks\Component\Version\Version;
1818

19+
/**
20+
* @internal
21+
*/
1922
class VersionTest extends TestCase
2023
{
2124
/** @test */
@@ -60,9 +63,7 @@ public function it_creates_without_patch(): void
6063
self::assertEquals('1.0.0', (string) $version);
6164
}
6265

63-
/**
64-
* @return array<string,string[]>
65-
*/
66+
/** @return array<string,string[]> */
6667
public static function provideValidFormats(): array
6768
{
6869
return [
@@ -77,8 +78,9 @@ public static function provideValidFormats(): array
7778
}
7879

7980
/**
80-
* @test
8181
* @dataProvider provideValidFormats
82+
*
83+
* @test
8284
*/
8385
public function it_supports_various_formats(string $version, string $expectedOutput): void
8486
{
@@ -116,9 +118,7 @@ public function it_fails_with_stable_plus_metaver(): void
116118
Version::fromString('1.0.0-stable-5');
117119
}
118120

119-
/**
120-
* @return array<string, array<int, array<int, string>|string>>>
121-
*/
121+
/** @return array<string, array<int, array<int, string>|string>>> */
122122
public static function provideExpectedNextVersionCandidates(): array
123123
{
124124
return [
@@ -136,10 +136,11 @@ public static function provideExpectedNextVersionCandidates(): array
136136
}
137137

138138
/**
139-
* @test
140139
* @dataProvider provideExpectedNextVersionCandidates
141140
*
142141
* @param array<int, string> $expected
142+
*
143+
* @test
143144
*/
144145
public function it_provides_next_version_candidates(string $current, array $expected): void
145146
{
@@ -149,9 +150,7 @@ public function it_provides_next_version_candidates(string $current, array $expe
149150
self::assertEquals($expected, $candidates);
150151
}
151152

152-
/**
153-
* @return array<string,string[]>
154-
*/
153+
/** @return array<string,string[]> */
155154
public static function provideExpectedIncreasedVersion(): array
156155
{
157156
return [
@@ -210,8 +209,9 @@ public static function provideExpectedIncreasedVersion(): array
210209
}
211210

212211
/**
213-
* @test
214212
* @dataProvider provideExpectedIncreasedVersion
213+
*
214+
* @test
215215
*/
216216
public function it_increases_to_next_version(string $current, string $expected, string $stability): void
217217
{

0 commit comments

Comments
 (0)