Completed
Push — master ( afe7e9...2d02b0 )
by Thibaud
02:35
created

PathUtil   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 38
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A basename() 0 4 2
A sanitizeExtension() 0 4 1
A extractExtension() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of alchemy/resource-component.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alchemy\Resource;
13
14
final class PathUtil
15
{
16
    /**
17
     * Extracts the file basename from a file path
18
     *
19
     * @param string $path File path
20
     * @return string The file basename or the input value if it has no path component.
21
     */
22 24
    public static function basename($path)
23
    {
24 24
        return (false === $pos = strrpos(strtr($path, '\\', '/'), '/')) ? $path : substr($path, $pos + 1);
25
    }
26
27
    /**
28
     * Sanitizes an extension.
29
     *
30
     * Strips dot from the beginning, converts to lowercase and remove trailing
31
     * whitespaces
32
     *
33
     * @param string $extension
34
     * @return string The sanitized extension
35
     */
36 28
    public static function sanitizeExtension($extension)
37
    {
38 28
        return ltrim(trim(mb_strtolower($extension)), '.');
39
    }
40
41
    /**
42
     * Returns the extension of a file
43
     *
44
     * @param string $path
45
     * @return string
46
     */
47 28
    public static function extractExtension($path)
48
    {
49 28
        return self::sanitizeExtension(pathinfo($path, PATHINFO_EXTENSION));
50
    }
51
}
52