Completed
Pull Request — master (#1984)
by Maciej
21:32
created

CollectionHelper::usesSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 3
cts 3
cp 1
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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
    public static function isAtomic(string $strategy) : bool
23
    {
24
        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
    public static function isHash(string $strategy) : bool
31
    {
32
        return $strategy === ClassMetadata::STORAGE_STRATEGY_SET || $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET;
33
    }
34
35
    /**
36 267
     * Returns whether Collection hold array indexed by consecutive numbers.
37
     */
38 267
    public static function isList(?string $strategy) : bool
39
    {
40
        return $strategy !== ClassMetadata::STORAGE_STRATEGY_SET && $strategy !== ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET;
41
    }
42
43
    /**
44 204
     * Returns whether strategy uses $set to update its data.
45
     */
46 204
    public static function usesSet(string $strategy) : bool
47
    {
48
        return in_array(
49
            $strategy,
50
            [
51
                ClassMetadata::STORAGE_STRATEGY_SET,
52 397
                ClassMetadata::STORAGE_STRATEGY_SET_ARRAY,
53
                ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET,
54 397
                ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY,
55
            ]
56
        );
57
    }
58
}
59