Completed
Push — master ( 232d56...e29d39 )
by Ducatel
04:51
created

StringSpecialization   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 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