StringSpecialization::__construct()   A
last analyzed

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\Base\Traits;
4
5
/**
6
 * trait used to define a string specialization
7
 * Should be used in subclass of AbstractTypedCollection
8
 * @package Ducatel\PHPCollection\Specialized
9
 */
10
trait StringSpecialization
11
{
12
    /**
13
     * Constructor of string specialized AbstractTypedCollection
14
     *
15
     * @param bool $caseSensitive True if the collection should be case sensitive
16
     */
17 2
    public function __construct(bool $caseSensitive = true)
18
    {
19
        $isStringFct = function ($obj) {
20 2
            return is_string($obj);
21 2
        };
22
23 2
        if ($caseSensitive) {
24
            $isEquals = function ($obj1, $obj2) {
25 1
                return (strcmp($obj1, $obj2) == 0);
26 1
            };
27
        } else {
28 1
            $isEquals = function ($obj1, $obj2) {
29 1
                return (strcasecmp($obj1, $obj2) == 0);
30 1
            };
31
        }
32
33
34 2
        parent::__construct($isStringFct, $isEquals);
35 2
    }
36
}
37