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 | /** |
||
6 | * balloon |
||
7 | * |
||
8 | * @copyright Copryright (c) 2012-2019 gyselroth GmbH (https://gyselroth.com) |
||
9 | * @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
||
10 | */ |
||
11 | |||
12 | namespace Balloon\Migration\Delta; |
||
13 | |||
14 | use MongoDB\Database; |
||
15 | |||
16 | View Code Duplication | class SetStorageReferenceToNull implements DeltaInterface |
|
0 ignored issues
–
show
|
|||
17 | { |
||
18 | /** |
||
19 | * Database. |
||
20 | * |
||
21 | * @var Database |
||
22 | */ |
||
23 | protected $db; |
||
24 | |||
25 | /** |
||
26 | * Construct. |
||
27 | */ |
||
28 | public function __construct(Database $db) |
||
29 | { |
||
30 | $this->db = $db; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Start. |
||
35 | */ |
||
36 | public function start(): bool |
||
37 | { |
||
38 | $cursor = $this->db->storage->find([ |
||
39 | 'storage_reference' => ['$exists' => false], |
||
40 | ]); |
||
41 | |||
42 | foreach ($cursor as $object) { |
||
43 | $this->db->storage->updateOne( |
||
44 | ['_id' => $object['_id']], |
||
45 | [ |
||
46 | '$set' => ['storage_reference' => null], |
||
47 | ] |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | return true; |
||
52 | } |
||
53 | } |
||
54 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.