UrlUtils   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getResourceName() 0 5 1
A stripResourceName() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rico\Slib;
6
7
abstract class UrlUtils
8
{
9
    /**
10
     * Gets the name of a resource (image, pdf, …) out of an $url.
11
     *
12
     * @param string $url
13
     *
14
     * @return string
15
     */
16
    public static function getResourceName(string $url): string
17
    {
18
        preg_match("/\/([^\/\?]+)(?:[\?\#].*)?$/", $url, $matches);
19
20
        return $matches[1] ?? '';
21
    }
22
23
    /**
24
     * Gets the URL without the resource (image, pdf, …).
25
     *
26
     * @param string $url
27
     *
28
     * @return string
29
     */
30
    public static function stripResourceName(string $url): string
31
    {
32
        preg_match("#([^\?]+\/)(?:[^\/\?]*\??.*)$#", $url, $matches);
33
34
        return $matches[1] ?? '';
35
    }
36
}
37