GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StartEndWith   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 15.63 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 10
loc 64
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A startsWith() 5 18 2
A endsWith() 5 20 2

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 namespace Gears\String\Methods;
2
////////////////////////////////////////////////////////////////////////////////
3
// __________ __             ________                   __________
4
// \______   \  |__ ______  /  _____/  ____ _____ ______\______   \ _______  ___
5
//  |     ___/  |  \\____ \/   \  ____/ __ \\__  \\_  __ \    |  _//  _ \  \/  /
6
//  |    |   |   Y  \  |_> >    \_\  \  ___/ / __ \|  | \/    |   (  <_> >    <
7
//  |____|   |___|  /   __/ \______  /\___  >____  /__|  |______  /\____/__/\_ \
8
//                \/|__|           \/     \/     \/             \/            \/
9
// -----------------------------------------------------------------------------
10
//          Designed and Developed by Brad Jones <brad @="bjc.id.au" />
11
// -----------------------------------------------------------------------------
12
////////////////////////////////////////////////////////////////////////////////
13
14
use voku\helper\UTF8;
15
16
trait StartEndWith
17
{
18
    /**
19
     * Returns true if the string begins with $substring, false otherwise.
20
     *
21
     * By default, the comparison is case-sensitive,
22
     * but can be made insensitive by setting $caseSensitive
23
     * to false.
24
     *
25
     * @param  string $substring     The substring to look for
26
     * @param  bool   $caseSensitive Whether or not to enforce case-sensitivity
27
     *
28
     * @return bool   Whether or not $str starts with $substring
29
     */
30
    public function startsWith($substring, $caseSensitive = true)
31
    {
32
        $startOfStr = UTF8::substr
33
        (
34
            $this->scalarString,
35
            0,
36
            UTF8::strlen($substring, $this->encoding),
37
            $this->encoding
38
        );
39
40 View Code Duplication
        if (!$caseSensitive)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
41
        {
42
            $substring = UTF8::strtolower($substring, $this->encoding);
43
            $startOfStr = UTF8::strtolower($startOfStr, $this->encoding);
44
        }
45
46
        return (string)$substring === $startOfStr;
47
    }
48
49
    /**
50
     * Returns true if the string ends with $substring, false otherwise. By
51
     * default, the comparison is case-sensitive, but can be made insensitive
52
     * by setting $caseSensitive to false.
53
     *
54
     * @param  string $substring     The substring to look for
55
     * @param  bool   $caseSensitive Whether or not to enforce case-sensitivity
56
     *
57
     * @return bool   Whether or not $str ends with $substring
58
     */
59
    public function endsWith($substring, $caseSensitive = true)
60
    {
61
        $substringLength = UTF8::strlen($substring, $this->encoding);
62
63
        $endOfStr = UTF8::substr
64
        (
65
            $this->scalarString,
66
            $this->getLength() - $substringLength,
67
            $substringLength,
68
            $this->encoding
69
        );
70
71 View Code Duplication
        if (!$caseSensitive)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
72
        {
73
            $substring = UTF8::strtolower($substring, $this->encoding);
74
            $endOfStr = UTF8::strtolower($endOfStr, $this->encoding);
75
        }
76
77
        return (string)$substring === $endOfStr;
78
    }
79
}
80