ResourceNames::buildEndpoint()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
ccs 10
cts 10
cp 1
rs 9.9666
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
namespace TarfinLabs\Parasut\Enums;
4
5
class ResourceNames
6
{
7
    public const CONTACT = 'contacts';
8
    public const PRODUCT = 'products';
9
10
    /**
11
     * Build the endpoint string from array or string parts.
12
     *
13
     * @param  mixed  ...$endpoints
14
     *
15
     * @return string
16
     */
17 11
    public static function buildEndpoint(...$endpoints): string
18
    {
19 11
        $url = '';
20
21 11
        foreach ($endpoints as $endpoint) {
22 11
            if (is_string($endpoint)) {
23 11
                $url = implode('/', array_filter([$url, $endpoint]));
24 11
                continue;
25
            }
26
27 10
            if (is_array($endpoint)) {
28 10
                $url .= '/'.implode('/', $endpoint);
29 10
                continue;
30
            }
31
        }
32
33 11
        return $url;
34
    }
35
}
36