These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 const E_USER_DEPRECATED; |
||
9 | use function in_array; |
||
10 | use function sprintf; |
||
11 | use function trigger_error; |
||
12 | |||
13 | /** |
||
14 | * Utility class used to unify checks on how collection strategies should behave. |
||
15 | * |
||
16 | * @internal |
||
17 | * |
||
18 | * @final |
||
19 | */ |
||
20 | class CollectionHelper |
||
21 | { |
||
22 | public const DEFAULT_STRATEGY = ClassMetadata::STORAGE_STRATEGY_PUSH_ALL; |
||
23 | |||
24 | public function __construct() |
||
25 | { |
||
26 | if (self::class === static::class) { |
||
27 | return; |
||
28 | } |
||
29 | |||
30 | @trigger_error(sprintf('The class "%s" extends "%s" which will be final in MongoDB ODM 2.0.', static::class, self::class), E_USER_DEPRECATED); |
||
0 ignored issues
–
show
|
|||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Returns whether update query must be included in query updating owning document. |
||
35 | */ |
||
36 | 267 | public static function isAtomic(string $strategy) : bool |
|
37 | { |
||
38 | 267 | return $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET || $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * Returns whether Collection hold associative array. |
||
43 | */ |
||
44 | 204 | public static function isHash(string $strategy) : bool |
|
45 | { |
||
46 | 204 | return $strategy === ClassMetadata::STORAGE_STRATEGY_SET || $strategy === ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Returns whether Collection hold array indexed by consecutive numbers. |
||
51 | */ |
||
52 | 397 | public static function isList(?string $strategy) : bool |
|
53 | { |
||
54 | 397 | return $strategy !== ClassMetadata::STORAGE_STRATEGY_SET && $strategy !== ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * Returns whether strategy uses $set to update its data. |
||
59 | */ |
||
60 | 1020 | public static function usesSet(string $strategy) : bool |
|
61 | { |
||
62 | return in_array( |
||
63 | 1020 | $strategy, |
|
64 | [ |
||
65 | ClassMetadata::STORAGE_STRATEGY_SET, |
||
66 | ClassMetadata::STORAGE_STRATEGY_SET_ARRAY, |
||
67 | ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET, |
||
68 | ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY, |
||
69 | ] |
||
70 | ); |
||
71 | } |
||
72 | } |
||
73 |
If you suppress an error, we recommend checking for the error condition explicitly: