Skip to content

Commit df4cb4c

Browse files
committed
Fix @link matcher
1 parent 5bc3e88 commit df4cb4c

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

src/Generator/MarkdownGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private function getSeeAlso(UrlList $urls): string
156156
private function getLinkLines(UrlList $urls): array
157157
{
158158
return array_map(function (Url $url) {
159-
return "- [$url]($url)";
159+
return "- [{$url->getName()}]({$url->getUrl()})";
160160
}, $urls->toArray());
161161
}
162162

src/Value/Url.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,33 @@
88
class Url
99
{
1010
private string $url;
11+
private string $name;
1112

12-
public function __construct(string $url)
13+
public function __construct(string $value)
1314
{
15+
$parts = explode(' ', $value);
16+
$url = array_shift($parts);
17+
$name = implode(' ', $parts);
18+
1419
Assert::that($url)
1520
->url();
1621

1722
$this->url = $url;
23+
$this->name = $name !== '' ? $name : $this->url;
1824
}
1925

20-
public function __toString()
26+
public function getUrl(): string
2127
{
22-
return $this->getUrl();
28+
return $this->url;
2329
}
2430

25-
public function getUrl(): string
31+
public function getName(): string
2632
{
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 : '');
2839
}
2940
}

src/Value/UrlList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UrlList
1919
public function __construct(array $urls)
2020
{
2121
$strings = array_map(function (Url $url): string {
22-
return (string)$url;
22+
return $url->toString();
2323
}, $urls);
2424

2525
$strings = array_values(array_unique($strings));

tests/Generator/JekyllPageGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PHPUnit\Framework\TestCase;
1010

1111
/** @covers \App\Generator\JekyllPage */
12-
class JekyllPageTest extends TestCase
12+
class JekyllPageGeneratorTest extends TestCase
1313
{
1414
private JekyllPageGenerator $generator;
1515

tests/Value/UrlTest.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
/** @covers \App\Value\Url */
1111
class UrlTest extends TestCase
1212
{
13-
const URL = 'http://link.com';
14-
1513
/** @test */
1614
public function constructor_WithInvalidUrlString_ThrowException()
1715
{
@@ -20,11 +18,32 @@ public function constructor_WithInvalidUrlString_ThrowException()
2018
}
2119

2220
/** @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()
2442
{
43+
$url = new Url('https://link.com');
2544
self::assertEquals(
26-
self::URL,
27-
(string)(new Url(self::URL))
45+
'https://link.com',
46+
$url->getName()
2847
);
2948
}
3049
}

0 commit comments

Comments
 (0)