File tree Expand file tree Collapse file tree 5 files changed +43
-13
lines changed Expand file tree Collapse file tree 5 files changed +43
-13
lines changed Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ private function getSeeAlso(UrlList $urls): string
156
156
private function getLinkLines (UrlList $ urls ): array
157
157
{
158
158
return array_map (function (Url $ url ) {
159
- return "- [ $ url]( $ url) " ;
159
+ return "- [ { $ url-> getName ()} ]( { $ url-> getUrl ()} ) " ;
160
160
}, $ urls ->toArray ());
161
161
}
162
162
Original file line number Diff line number Diff line change 8
8
class Url
9
9
{
10
10
private string $ url ;
11
+ private string $ name ;
11
12
12
- public function __construct (string $ url )
13
+ public function __construct (string $ value )
13
14
{
15
+ $ parts = explode (' ' , $ value );
16
+ $ url = array_shift ($ parts );
17
+ $ name = implode (' ' , $ parts );
18
+
14
19
Assert::that ($ url )
15
20
->url ();
16
21
17
22
$ this ->url = $ url ;
23
+ $ this ->name = $ name !== '' ? $ name : $ this ->url ;
18
24
}
19
25
20
- public function __toString ()
26
+ public function getUrl (): string
21
27
{
22
- return $ this ->getUrl () ;
28
+ return $ this ->url ;
23
29
}
24
30
25
- public function getUrl (): string
31
+ public function getName (): string
26
32
{
27
- return $ this ->url ;
33
+ return $ this ->name ;
34
+ }
35
+
36
+ public function toString (): string
37
+ {
38
+ return $ this ->url . ($ this ->name !== $ this ->url ? ' ' . $ this ->name : '' );
28
39
}
29
40
}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ class UrlList
19
19
public function __construct (array $ urls )
20
20
{
21
21
$ strings = array_map (function (Url $ url ): string {
22
- return ( string ) $ url ;
22
+ return $ url-> toString () ;
23
23
}, $ urls );
24
24
25
25
$ strings = array_values (array_unique ($ strings ));
Original file line number Diff line number Diff line change 9
9
use PHPUnit \Framework \TestCase ;
10
10
11
11
/** @covers \App\Generator\JekyllPage */
12
- class JekyllPageTest extends TestCase
12
+ class JekyllPageGeneratorTest extends TestCase
13
13
{
14
14
private JekyllPageGenerator $ generator ;
15
15
Original file line number Diff line number Diff line change 10
10
/** @covers \App\Value\Url */
11
11
class UrlTest extends TestCase
12
12
{
13
- const URL = 'http://link.com ' ;
14
-
15
13
/** @test */
16
14
public function constructor_WithInvalidUrlString_ThrowException ()
17
15
{
@@ -20,11 +18,32 @@ public function constructor_WithInvalidUrlString_ThrowException()
20
18
}
21
19
22
20
/** @test */
23
- public function getUrl ()
21
+ public function getName_WithTextAfterUrl_ReturnTextName ()
22
+ {
23
+ $ url = new Url ('https://link.com Name with spaces ' );
24
+ self ::assertEquals (
25
+ 'Name with spaces ' ,
26
+ $ url ->getName ()
27
+ );
28
+ }
29
+
30
+ /** @test */
31
+ public function getUrl_WithUrlOnly_ReturnsUrl ()
32
+ {
33
+ $ url = new Url ('https://link.com ' );
34
+ self ::assertEquals (
35
+ 'https://link.com ' ,
36
+ $ url ->getUrl ()
37
+ );
38
+ }
39
+
40
+ /** @test */
41
+ public function getName_WithUrlOnly_ReturnsUrl ()
24
42
{
43
+ $ url = new Url ('https://link.com ' );
25
44
self ::assertEquals (
26
- self :: URL ,
27
- ( string )( new Url ( self :: URL ) )
45
+ ' https://link.com ' ,
46
+ $ url -> getName ( )
28
47
);
29
48
}
30
49
}
You can’t perform that action at this time.
0 commit comments