Completed
Pull Request — master (#1984)
by Maciej
22:01
created

CollectionHelper::isAtomic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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