Version20140822185743::generateRandomString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 10
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 Version20140822185743 extends AbstractMigration
9
{
10
    /**
11
     * @return string
12
     */
13
    public function getDescription()
14
    {
15
        return 'Second Version executes console script';
16
    }
17
18
    public function up(Database $db)
19
    {
20
        $testA = $db->selectCollection('test_a');
21
        $this->analyze($testA);
22
23
        // This will remove all records with actor property starting with character a-m
24
        $result = $this->executeScript($db, 'test_script.js');
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
25
    }
26
27
    public function down(Database $db)
28
    {
29
        // this down() migration is auto-generated, please modify it to your needs
30
    }
31
32
    /**
33
     * This preUp is not required
34
     * I use it to demonstrate the analyzer.
35
     */
36
    public function preUp(Database $db)
37
    {
38
        $testA = $db->selectCollection('test_a');
39
40
        $testDocuments = [];
41
42
        for ($i = 0; $i < 100; ++$i) {
43
            $testDocument = [];
44
            $testDocument['iteration'] = $i;
45
            $testDocument['actor'] = $this->generateRandomString();
0 ignored issues
show
Bug introduced by
The method generateRandomString() does not exist on Example\Migrations\TestA...B\Version20140822185743. ( Ignorable by Annotation )

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

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