Completed
Push — master ( cb02b0...de8dbf )
by Alex
15s queued 12s
created

StringUtility   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 10
c 1
b 1
f 0
dl 0
loc 48
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A plural() 0 3 1
A startsWith() 0 9 4
A contains() 0 9 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alex
5
 * Date: 9/05/20
6
 * Time: 3:56 AM
7
 */
8
9
namespace POData;
10
11
/** To enable the dependency tree to get pruned (and drop illuminate/http and illuminate/support), the fragments of
12
/* illuminate/support we were using have been copied here.
13
 */
14
class StringUtility
15
{
16
    /**
17
     * Get the plural form of an English word.
18
     *
19
     * @param  string  $value
20
     * @param  int     $count
21
     * @return string
22
     */
23
    public static function plural($value, $count = 2)
24
    {
25
        return Pluralizer::plural($value, $count);
26
    }
27
28
    /**
29
     * Determine if a given string starts with a given substring.
30
     *
31
     * @param  string  $haystack
32
     * @param  string|array  $needles
33
     * @return bool
34
     */
35
    public static function startsWith($haystack, $needles)
36
    {
37
        foreach ((array) $needles as $needle) {
38
            if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {
39
                return true;
40
            }
41
        }
42
43
        return false;
44
    }
45
46
    /**
47
     * Determine if a given string contains a given substring.
48
     *
49
     * @param  string  $haystack
50
     * @param  string|array  $needles
51
     * @return bool
52
     */
53
    public static function contains($haystack, $needles)
54
    {
55
        foreach ((array) $needles as $needle) {
56
            if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
57
                return true;
58
            }
59
        }
60
61
        return false;
62
    }
63
}
64