Completed
Pull Request — master (#1984)
by Maciej
19:41
created

CollectionHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 44
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A usesSet() 0 12 1
A isAtomic() 0 4 2
A isHash() 0 4 2
A isList() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Utility;
6
7
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
8
use function in_array;
9
10
/**
11
 * Utility class used to unify checks on how collection strategies should behave.
12
 *
13
 * @internal
14
 */
15
final class CollectionHelper
16
{
17
    public const DEFAULT_STRATEGY = ClassMetadata::STORAGE_STRATEGY_PUSH_ALL;
18
19
    /**
20
     * Returns whether update query must be included in query updating owning document.
21
     */
22 267
    public static function isAtomic(string $strategy) : bool
23
    {
24 267
        return $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET || $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY;
25
    }
26
27
    /**
28
     * Returns whether Collection hold associative array.
29
     */
30 203
    public static function isHash(string $strategy) : bool
31
    {
32 203
        return $strategy === ClassMetadata::STORAGE_STRATEGY_SET || $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET;
33
    }
34
35
    /**
36
     * Returns whether Collection hold array indexed by consecutive numbers.
37
     */
38 395
    public static function isList(?string $strategy) : bool
39
    {
40 395
        return $strategy !== ClassMetadata::STORAGE_STRATEGY_SET && $strategy !== ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET;
41
    }
42
43
    /**
44
     * Returns whether strategy uses $set to update its data.
45
     */
46 1065
    public static function usesSet(string $strategy) : bool
47
    {
48
        return in_array(
49 1065
            $strategy,
50
            [
51
                ClassMetadata::STORAGE_STRATEGY_SET,
52
                ClassMetadata::STORAGE_STRATEGY_SET_ARRAY,
53
                ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET,
54
                ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY,
55
            ]
56
        );
57
    }
58
}
59