Completed
Pull Request — develop (#645)
by Alejandro
05:15
created

NotFoundUrlHelpersTrait::buildShortUrlPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioApiTest\Shlink\Rest\Utils;
6
7
use Laminas\Diactoros\Uri;
8
9
use function GuzzleHttp\Psr7\build_query;
10
use function sprintf;
11
12
trait NotFoundUrlHelpersTrait
13
{
14
    public function provideInvalidUrls(): iterable
15
    {
16
        yield 'invalid shortcode' => ['invalid', null, 'No URL found with short code "invalid"'];
17
        yield 'invalid shortcode without domain' => [
18
            'abc123',
19
            'example.com',
20
            'No URL found with short code "abc123" for domain "example.com"',
21
        ];
22
        yield 'invalid shortcode + domain' => [
23
            'custom-with-domain',
24
            'example.com',
25
            'No URL found with short code "custom-with-domain" for domain "example.com"',
26
        ];
27
    }
28
29
    public function buildShortUrlPath(string $shortCode, ?string $domain, string $suffix = ''): string
30
    {
31
        $url = new Uri(sprintf('/short-urls/%s%s', $shortCode, $suffix));
32
        if ($domain !== null) {
33
            $url = $url->withQuery(build_query(['domain' => $domain]));
34
        }
35
36
        return (string) $url;
37
    }
38
}
39