Passed
Push — master ( e00bfb...6b59e9 )
by Patrick
24:00
created

Str::substr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ShiftOneLabs\LaravelSqsFifoQueue\Support;
4
5
use Illuminate\Support\Str as BaseStr;
6
7
class Str extends BaseStr
8
{
9
    /**
10
     * Get the portion of a string before the last occurrence of a given value.
11
     *
12
     * The beforeLast method wasn't added to the Str class until Laravel 6.x.
13
     * Add the implementation here to support older versions of Laravel.
14
     *
15
     * @param  string  $subject
16
     * @param  string  $search
17
     *
18
     * @return string
19
     */
20 1099
    public static function beforeLast($subject, $search)
21
    {
22 1099
        if ($search === '') {
23 70
            return $subject;
24
        }
25
26 1099
        $pos = mb_strrpos($subject, $search, 0, 'UTF-8');
27
28 1099
        if ($pos === false) {
29 756
            return $subject;
30
        }
31
32 413
        return static::substr($subject, 0, $pos);
33
    }
34
35
    /**
36
     * Returns the portion of string specified by the start and length parameters.
37
     *
38
     * The substr method wasn't added to the Str class until Laravel 5.1.
39
     * Add the implementation here to support older versions of Laravel.
40
     *
41
     * @param  string  $string
42
     * @param  int  $start
43
     * @param  int|null  $length
44
     *
45
     * @return string
46
     */
47 483
    public static function substr($string, $start, $length = null)
48
    {
49 483
        return mb_substr($string, $start, $length, 'UTF-8');
50
    }
51
}
52