Completed
Push — master ( a6bdc8...dc87b2 )
by Ducatel
02:27
created

StringArray::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Ducatel\PHPCollection\Specialized;
4
5
use Ducatel\PHPCollection\TypedArray;
6
7
/**
8
 * Class StringArray
9
 * This collection is a specialization of TypedArray for string variables.
10
 * @package Ducatel\PHPCollection\Specialized
11
 */
12
class StringArray extends TypedArray
13
{
14
    /**
15
     * StringArray constructor.
16
     *
17
     * @param bool $caseSensitive True if the collection should be case sensitive
18
     */
19 2
    public function __construct(bool $caseSensitive = true)
20
    {
21
        $isStringFct = function ($obj) {
22 2
            return is_string($obj);
23 2
        };
24
25 2
        if ($caseSensitive) {
26
            $isEquals = function ($obj1, $obj2) {
27 1
                return (strcmp($obj1, $obj2) == 0);
28 1
            };
29
        } else {
30 1
            $isEquals = function ($obj1, $obj2) {
31 1
                return (strcasecmp($obj1, $obj2) == 0);
32 1
            };
33
        }
34
35
36 2
        parent::__construct($isStringFct, $isEquals);
37 2
    }
38
}
39