NotFoundUrlHelpersTrait::buildShortUrlPath()   A
last analyzed

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]));
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\build_query() has been deprecated: build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

33
            $url = $url->withQuery(/** @scrutinizer ignore-deprecated */ build_query(['domain' => $domain]));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
34
        }
35
36
        return (string) $url;
37
    }
38
}
39