Passed
Push — master ( 4ac39c...ddccf7 )
by Alain
03:15
created

ExtensionCollection::hasExtension()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/**
3
 * Bright Nucleus View Component.
4
 *
5
 * @package   BrightNucleus\View
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   MIT
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\View\Support;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
16
/**
17
 * Class ExtensionCollection.
18
 *
19
 * @since   0.1.1
20
 *
21
 * @package BrightNucleus\View\Support
22
 * @author  Alain Schlesser <[email protected]>
23
 */
24 View Code Duplication
class ExtensionCollection extends ArrayCollection
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
{
26
27
    /**
28
     * Check whether a given URI has a specific extension.
29
     *
30
     * @since 0.1.0
31
     *
32
     * @param string $uri       URI to check the extension of.
33
     * @param string $extension Extension to check for.
34
     *
35
     * @return bool
36
     */
37
    public static function hasExtension($uri, $extension)
38
    {
39
        $uriLength       = mb_strlen($uri);
40
        $extensionLength = mb_strlen($extension);
41
        if ($extensionLength > $uriLength) {
42
            return false;
43
        }
44
45
        return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0;
46
    }
47
}
48