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.

Replace::replace()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 3
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 Replace
17
{
18
    /**
19
     * Replaces all occurrences of $search in $str by $replacement.
20
     *
21
     * @param  string|array $search        The needle to search for.
22
     *
23
     * @param  string|array $replacement   The string to replace with.
24
     *
25
     * @param  bool         $caseSensitive To enforce case-sensitivity or not.
26
     *
27
     * @return static                      String after the replacements.
28
     */
29
    public function replace($search, $replacement, $caseSensitive = true)
30
    {
31
        if ($caseSensitive)
32
        {
33
            $return = UTF8::str_replace
34
            (
35
                $search,
36
                $replacement,
37
                $this->scalarString
38
            );
39
        }
40
        else
41
        {
42
            $return = UTF8::str_ireplace
43
            (
44
                $search,
45
                $replacement,
46
                $this->scalarString
47
            );
48
        }
49
50
        return $this->newSelf($return);
51
    }
52
53
    /**
54
     * Replaces all occurrences of $search from the
55
     * beginning of string with $replacement.
56
     *
57
     * @param string $search
58
     * @param string $replacement
59
     * @return static
60
     */
61
    public function replaceBeginning($search, $replacement)
62
    {
63
        return $this->regexReplace
64
        (
65
            '^'.preg_quote($search, '/'),
66
            UTF8::str_replace('\\', '\\\\', $replacement)
67
        );
68
    }
69
70
    /**
71
     * Replaces all occurrences of $search from the
72
     * ending of string with $replacement.
73
     *
74
     * @param string $search
75
     * @param string $replacement
76
     * @return static
77
     */
78
    public function replaceEnding($search, $replacement)
79
    {
80
        return $this->regexReplace
81
        (
82
            preg_quote($search, '/').'$',
83
            UTF8::str_replace('\\', '\\\\', $replacement)
84
        );
85
    }
86
}
87