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

NotFoundUrlHelpersTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildShortUrlPath() 0 8 2
A provideInvalidUrls() 0 12 1
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