Passed
Branch validation-refactor (de59e2)
by Jason
03:09
created

CollectionFactory::getValidator()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 0
crap 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jwalker
5
 * Date: 5/22/2018
6
 * Time: 9:27 AM
7
 */
8
9
namespace Fusion\Collection;
10
11
12
use Fusion\Collection\Contracts\CollectionValidationInterface;
13
14
class CollectionFactory
15
{
16
    /** @var \Fusion\Collection\Contracts\CollectionValidationInterface */
17
    private static $cachedValidator;
18
19 93
    private static function getValidator(): CollectionValidationInterface
20
    {
21 93
        if (self::$cachedValidator === null || (self::$cachedValidator instanceof CollectionValidationInterface) === false)
22
        {
23 1
            self::$cachedValidator = new CollectionValidator();
24
        }
25
26 93
        return self::$cachedValidator;
27
    }
28
29 49
    public static function newCollection(array $starterItems = []): Collection
30
    {
31 49
        return new Collection(self::getValidator(), $starterItems);
32
    }
33
34 13
    public static function newTypedCollection(string $acceptedType, array $starterItems = []): TypedCollection
35
    {
36 13
        return new TypedCollection(self::getValidator(), $acceptedType, $starterItems);
37
    }
38
39 21
    public static function newDictionary(array $starterItems = []): Dictionary
40
    {
41 21
        return new Dictionary(self::getValidator(), $starterItems);
42
    }
43
44 10
    public static function newTypedDictionary(string $acceptedType, array $starterItems = []): TypedDictionary
45
    {
46 10
        return new TypedDictionary(self::getValidator(), $acceptedType, $starterItems);
47
    }
48
}