Skip to content

Commit 87c803b

Browse files
committed
!!![TASK] Remove unused UrlGeneratorInterface::generateUrl
It didnt do anything but leave each URL unchanged in a complicated way and was not used anymore
1 parent c3e67f4 commit 87c803b

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

packages/guides/src/UrlGenerator.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace phpDocumentor\Guides;
1515

16-
use InvalidArgumentException;
1716
use League\Uri\UriInfo;
1817

1918
use function array_pop;
@@ -24,20 +23,6 @@
2423

2524
final class UrlGenerator implements UrlGeneratorInterface
2625
{
27-
public function generateUrl(string $path): string
28-
{
29-
try {
30-
$uri = UriFactory::createUri($path);
31-
if (UriInfo::isAbsolutePath($uri)) {
32-
return $path;
33-
}
34-
35-
return $this->relativeUrl($path);
36-
} catch (InvalidArgumentException) {
37-
return $path;
38-
}
39-
}
40-
4126
/**
4227
* Returns the absolute path, including prefixing '/'.
4328
*

packages/guides/src/UrlGeneratorInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
interface UrlGeneratorInterface
88
{
9-
public function generateUrl(string $path): string;
10-
119
/**
1210
* Returns the absolute path, including prefixing '/'.
1311
*

packages/guides/tests/unit/UrlGeneratorTest.php

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,57 @@
99

1010
final class UrlGeneratorTest extends TestCase
1111
{
12+
#[DataProvider('fileUrlProvider')]
13+
public function testCreateFileUrl(string $expected, string $filename, string $outputFormat = 'html', string|null $anchor = null, string $skip = ''): void
14+
{
15+
if ($skip !== '') {
16+
self::markTestSkipped($skip);
17+
}
18+
19+
$urlGenerator = new UrlGenerator();
20+
self::assertSame($expected, $urlGenerator->createFileUrl($filename, $outputFormat, $anchor));
21+
}
22+
23+
/** @return array<string, array<string, string|null>> */
24+
public static function fileUrlProvider(): array
25+
{
26+
return [
27+
'Simple Filename' => [
28+
'expected' => 'file.html',
29+
'filename' => 'file',
30+
],
31+
'Complex Filename' => [
32+
'expected' => 'file-something.html',
33+
'filename' => 'file-something',
34+
],
35+
'Output Format' => [
36+
'expected' => 'texfile.tex',
37+
'filename' => 'texfile',
38+
'outputFormat' => 'tex',
39+
],
40+
'File with anchor' => [
41+
'expected' => 'file.html#anchor',
42+
'filename' => 'file',
43+
'outputFormat' => 'html',
44+
'anchor' => 'anchor',
45+
],
46+
'Empty File with anchor' => [
47+
'expected' => '#anchor',
48+
'filename' => '',
49+
'outputFormat' => 'html',
50+
'anchor' => 'anchor',
51+
'skip' => 'Empty filenames are not supported',
52+
],
53+
'Empty File with empty anchor' => [
54+
'expected' => '#',
55+
'filename' => '',
56+
'outputFormat' => 'html',
57+
'anchor' => null,
58+
'skip' => 'Empty filenames are not supported',
59+
],
60+
];
61+
}
62+
1263
#[DataProvider('canonicalUrlProvider')]
1364
public function testCanonicalUrl(string $basePath, string $url, string $result): void
1465
{
@@ -86,10 +137,4 @@ public static function abstractUrlProvider(): array
86137
],
87138
];
88139
}
89-
90-
public function testUrlGenerationOfInvalidUrlReturnsInput(): void
91-
{
92-
$urlGenerator = new UrlGenerator();
93-
self::assertSame('tcp://hostname:port', $urlGenerator->generateUrl('tcp://hostname:port'));
94-
}
95140
}

0 commit comments

Comments
 (0)