Passed
Push — master ( 6bd3f8...af1281 )
by Sebastian
02:31
created

Str::endsWith()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
crap 3
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2017, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Helper;
13
14
class Str
15
{
16
    /**
17
     * Determine if a given string starts with a given substring.
18
     *
19
     * @param string $haystack
20
     * @param array $needles
21
     * @return bool
22
     */
23 32 View Code Duplication
    public static function startsWith(string $haystack, array $needles = []) : bool
0 ignored issues
show
Duplication introduced by
This method 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...
24
    {
25 32
        foreach ($needles as $needle) {
26 32
            if (strpos($haystack, (string) $needle) === 0) {
27 3
                return true;
28
            }
29
        }
30
        
31 29
        return false;
32
    }
33
    
34
    /**
35
     * Determine if a given string ends with a given substring.
36
     *
37
     * @param string $haystack
38
     * @param array $needles
39
     * @return bool
40
     */
41 32 View Code Duplication
    public static function endsWith(string $haystack, array $needles = []) : bool
0 ignored issues
show
Duplication introduced by
This method 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...
42
    {
43 32
        foreach ($needles as $needle) {
44 32
            if (strpos(strrev($haystack), (string) $needle) === 0) {
45 3
                return true;
46
            }
47
        }
48
        
49 29
        return false;
50
    }
51
}
52