Version20140822185742::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Example\Migrations\TestAntiMattr\MongoDB;
4
5
use AntiMattr\MongoDB\Migrations\AbstractMigration;
6
use MongoDB\Database;
7
8
class Version20140822185742 extends AbstractMigration
9
{
10
    /**
11
     * @return string
12
     */
13
    public function getDescription()
14
    {
15
        return 'First Version prepares Index';
16
    }
17
18
    public function up(Database $db)
19
    {
20
        $testA = $db->selectCollection('test_a');
21
        $this->analyze($testA);
22
23
        $testA->createIndex(['actor' => -1]);
24
    }
25
26
    public function down(Database $db)
27
    {
28
        // this down() migration is auto-generated, please modify it to your needs
29
    }
30
31
    /**
32
     * This preUp is not required
33
     * I use it to demonstrate the analyzer.
34
     */
35
    public function preUp(Database $db)
36
    {
37
        $testA = $db->selectCollection('test_a');
38
39
        $testDocuments = [];
40
41
        for ($i = 0; $i < 100; ++$i) {
42
            $testDocument = [];
43
            $testDocument['iteration'] = $i;
44
            $testDocument['actor'] = $this->generateRandomString();
0 ignored issues
show
Bug introduced by
The method generateRandomString() does not exist on Example\Migrations\TestA...B\Version20140822185742. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
            /** @scrutinizer ignore-call */ 
45
            $testDocument['actor'] = $this->generateRandomString();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            $testDocument['object'] = $this->generateRandomString();
46
            $testDocument['target'] = $this->generateRandomString();
47
            $testDocument['verb'] = $this->generateRandomString();
48
            $testDocuments[] = $testDocument;
49
        }
50
51
        $testA->insertMany($testDocuments);
52
    }
53
54
    /**
55
     * This postUp is not required
56
     * I use it to demonstrate the analyzer.
57
     */
58
    public function postUp(Database $db)
59
    {
60
        $testA = $db->selectCollection('test_a');
61
        $testA->drop();
62
    }
63
64
    private function generateRandomString()
65
    {
66
        $length = rand(10, 50);
67
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
68
        $randomString = '';
69
        for ($i = 0; $i < $length; ++$i) {
70
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
71
        }
72
73
        return $randomString;
74
    }
75
}
76