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

Str   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 52.63 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A startsWith() 10 10 3
A endsWith() 10 10 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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