Skip to content

Commit eefd509

Browse files
authored
Code Quality using Rector (#211)
## Description ## Checklist - [ ] Updated CHANGELOG files - [ ] Updated Documentation - [ ] Unit Tests Created - [x] php-cs-fixer
1 parent 98689bf commit eefd509

7 files changed

+30
-104
lines changed

EvolvableLink.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SonsOfPHP\Component\Link;
66

77
use Psr\Link\EvolvableLinkInterface;
8+
use Stringable;
89

910
/**
1011
* @author Joshua Estes <joshua@sonsofphp.com>
@@ -14,7 +15,7 @@ class EvolvableLink extends Link implements EvolvableLinkInterface
1415
/**
1516
* Returns an instance with the specified href.
1617
*
17-
* @param string|\Stringable $href
18+
* @param string|Stringable $href
1819
* The href value to include. It must be one of:
1920
* - An absolute URI, as defined by RFC 5988.
2021
* - A relative URI, as defined by RFC 5988. The base of the relative link
@@ -28,9 +29,9 @@ class EvolvableLink extends Link implements EvolvableLinkInterface
2829
*
2930
* @return static
3031
*/
31-
public function withHref(string|\Stringable $href): static
32+
public function withHref(string|Stringable $href): static
3233
{
33-
if ($href instanceof \Stringable) {
34+
if ($href instanceof Stringable) {
3435
$href = (string) $href;
3536
}
3637

@@ -92,11 +93,11 @@ public function withoutRel(string $rel): static
9293
*
9394
* @param string $attribute
9495
* The attribute to include.
95-
* @param string|\Stringable|int|float|bool|array $value
96+
* @param string|Stringable|int|float|bool|array $value
9697
* The value of the attribute to set.
9798
* @return static
9899
*/
99-
public function withAttribute(string $attribute, string|\Stringable|int|float|bool|array $value): static
100+
public function withAttribute(string $attribute, string|Stringable|int|float|bool|array $value): static
100101
{
101102
$that = clone $this;
102103
$that->attributes[$attribute] = $value;

Link.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SonsOfPHP\Component\Link;
66

7+
use InvalidArgumentException;
78
use Psr\Link\LinkInterface;
89

910
/**
@@ -19,7 +20,7 @@ public function __construct(
1920
protected array $attributes = [],
2021
) {
2122
if ('' === $href && !$this instanceof EvolvableLink) {
22-
throw new \InvalidArgumentException('MUST pass in href');
23+
throw new InvalidArgumentException('MUST pass in href');
2324
}
2425

2526
if (null === $rels) {

LinkProvider.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SonsOfPHP\Component\Link;
66

7+
use InvalidArgumentException;
78
use Psr\Link\LinkInterface;
89
use Psr\Link\LinkProviderInterface;
910

@@ -19,7 +20,7 @@ public function __construct(
1920
) {
2021
foreach ($links as $link) {
2122
if (!$link instanceof LinkInterface) {
22-
throw new \InvalidArgumentException('At least one link does not implement LinkInterface');
23+
throw new InvalidArgumentException('At least one link does not implement LinkInterface');
2324
}
2425

2526
$this->links[spl_object_hash($link)] = $link;

Tests/EvolvableLinkProviderTest.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44

55
namespace SonsOfPHP\Component\Link\Tests;
66

7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\UsesClass;
79
use PHPUnit\Framework\TestCase;
810
use Psr\Link\EvolvableLinkProviderInterface;
911
use SonsOfPHP\Component\Link\EvolvableLinkProvider;
1012
use SonsOfPHP\Component\Link\Link;
13+
use SonsOfPHP\Component\Link\LinkProvider;
1114

12-
/**
13-
* @coversDefaultClass \SonsOfPHP\Component\Link\EvolvableLinkProvider
14-
*
15-
* @uses \SonsOfPHP\Component\Link\Link
16-
* @uses \SonsOfPHP\Component\Link\EvolvableLinkProvider
17-
* @uses \SonsOfPHP\Component\Link\LinkProvider
18-
*/
15+
#[CoversClass(EvolvableLinkProvider::class)]
16+
#[UsesClass(Link::class)]
17+
#[UsesClass(LinkProvider::class)]
1918
final class EvolvableLinkProviderTest extends TestCase
2019
{
2120
/**
@@ -28,9 +27,6 @@ public function testItHasTheCorrectInterface(): void
2827
$this->assertInstanceOf(EvolvableLinkProviderInterface::class, $provider);
2928
}
3029

31-
/**
32-
* @covers ::withLink
33-
*/
3430
public function testWithLink(): void
3531
{
3632
$provider = new EvolvableLinkProvider();
@@ -40,9 +36,6 @@ public function testWithLink(): void
4036
$this->assertCount(1, $provider->getLinks());
4137
}
4238

43-
/**
44-
* @covers ::withoutLink
45-
*/
4639
public function testWithoutLink(): void
4740
{
4841
$provider = new EvolvableLinkProvider([

Tests/EvolvableLinkTest.php

+7-37
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,28 @@
44

55
namespace SonsOfPHP\Component\Link\Tests;
66

7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\UsesClass;
79
use PHPUnit\Framework\TestCase;
810
use Psr\Link\EvolvableLinkInterface;
911
use SonsOfPHP\Component\Link\EvolvableLink;
12+
use SonsOfPHP\Component\Link\Link;
13+
use Stringable;
1014

11-
/**
12-
* @coversDefaultClass \SonsOfPHP\Component\Link\EvolvableLink
13-
*
14-
* @uses \SonsOfPHP\Component\Link\EvolvableLink
15-
* @uses \SonsOfPHP\Component\Link\Link
16-
*/
15+
#[CoversClass(EvolvableLink::class)]
16+
#[UsesClass(Link::class)]
1717
final class EvolvableLinkTest extends TestCase
1818
{
19-
/**
20-
* @covers ::__construct
21-
*/
2219
public function testItHasTheCorrectInterface(): void
2320
{
2421
$link = new EvolvableLink();
2522

2623
$this->assertInstanceOf(EvolvableLinkInterface::class, $link);
2724
}
2825

29-
/**
30-
* @covers ::withHref
31-
*/
3226
public function testWithHrefWhenStringable(): void
3327
{
34-
$href = new class () implements \Stringable {
28+
$href = new class () implements Stringable {
3529
public function __toString(): string
3630
{
3731
return 'https://docs.sonsofphp.com';
@@ -43,9 +37,6 @@ public function __toString(): string
4337
$this->assertSame((string) $href, $link->withHref($href)->getHref());
4438
}
4539

46-
/**
47-
* @covers ::withHref
48-
*/
4940
public function testWithHref(): void
5041
{
5142
$href = 'https://docs.sonsofphp.com';
@@ -55,9 +46,6 @@ public function testWithHref(): void
5546
$this->assertSame($href, $link->withHref($href)->getHref());
5647
}
5748

58-
/**
59-
* @covers ::withRel
60-
*/
6149
public function testWithRelWhenAlreadyExists(): void
6250
{
6351
$rel = 'next';
@@ -66,9 +54,6 @@ public function testWithRelWhenAlreadyExists(): void
6654
$this->assertSame($link, $link->withRel($rel));
6755
}
6856

69-
/**
70-
* @covers ::withRel
71-
*/
7257
public function testWithRel(): void
7358
{
7459
$rel = 'next';
@@ -78,9 +63,6 @@ public function testWithRel(): void
7863
$this->assertContains($rel, $link->withRel($rel)->getRels());
7964
}
8065

81-
/**
82-
* @covers ::withoutRel
83-
*/
8466
public function testWithoutRelWhenRelNotPresent(): void
8567
{
8668
$rel = 'next';
@@ -90,9 +72,6 @@ public function testWithoutRelWhenRelNotPresent(): void
9072
$this->assertNotContains($rel, $link->withoutRel($rel)->getRels());
9173
}
9274

93-
/**
94-
* @covers ::withoutRel
95-
*/
9675
public function testWithoutRel(): void
9776
{
9877
$rel = 'next';
@@ -102,9 +81,6 @@ public function testWithoutRel(): void
10281
$this->assertNotContains($rel, $link->withoutRel($rel)->getRels());
10382
}
10483

105-
/**
106-
* @covers ::withAttribute
107-
*/
10884
public function testWithAttribute(): void
10985
{
11086
$key = 'key';
@@ -115,9 +91,6 @@ public function testWithAttribute(): void
11591
$this->assertArrayHasKey($key, $link->withAttribute($key, $value)->getAttributes());
11692
}
11793

118-
/**
119-
* @covers ::withoutAttribute
120-
*/
12194
public function testWithoutAttributeWhenKeyDoesNotExist(): void
12295
{
12396
$key = 'key';
@@ -127,9 +100,6 @@ public function testWithoutAttributeWhenKeyDoesNotExist(): void
127100
$this->assertArrayNotHasKey($key, $link->withoutAttribute($key)->getAttributes());
128101
}
129102

130-
/**
131-
* @covers ::withoutAttribute
132-
*/
133103
public function testWithoutAttribute(): void
134104
{
135105
$key = 'key';

Tests/LinkProviderTest.php

+4-21
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,24 @@
44

55
namespace SonsOfPHP\Component\Link\Tests;
66

7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\UsesClass;
79
use PHPUnit\Framework\TestCase;
810
use Psr\Link\LinkProviderInterface;
911
use SonsOfPHP\Component\Link\Link;
1012
use SonsOfPHP\Component\Link\LinkProvider;
1113

12-
/**
13-
* @coversDefaultClass \SonsOfPHP\Component\Link\LinkProvider
14-
*
15-
* @uses \SonsOfPHP\Component\Link\Link
16-
* @uses \SonsOfPHP\Component\Link\LinkProvider
17-
*/
14+
#[CoversClass(LinkProvider::class)]
15+
#[UsesClass(Link::class)]
1816
final class LinkProviderTest extends TestCase
1917
{
20-
/**
21-
* @covers ::__construct
22-
*/
2318
public function testItHasTheCorrectInterface(): void
2419
{
2520
$provider = new LinkProvider();
2621

2722
$this->assertInstanceOf(LinkProviderInterface::class, $provider);
2823
}
2924

30-
/**
31-
* @covers ::__construct
32-
*/
3325
public function testConstructWilThrowException(): void
3426
{
3527
$this->expectException('InvalidArgumentException');
@@ -38,9 +30,6 @@ public function testConstructWilThrowException(): void
3830
]);
3931
}
4032

41-
/**
42-
* @covers ::__construct
43-
*/
4433
public function testConstructCanAddLinks(): void
4534
{
4635
$provider = new LinkProvider([
@@ -50,19 +39,13 @@ public function testConstructCanAddLinks(): void
5039
$this->assertCount(1, $provider->getLinks());
5140
}
5241

53-
/**
54-
* @covers ::getLinks
55-
*/
5642
public function testGetLinks(): void
5743
{
5844
$provider = new LinkProvider();
5945

6046
$this->assertCount(0, $provider->getLinks());
6147
}
6248

63-
/**
64-
* @covers ::getLinksByRel
65-
*/
6649
public function testGetLinksByRel(): void
6750
{
6851
$provider = new LinkProvider([

0 commit comments

Comments
 (0)