Completed
Push — master ( fdc04a...f73088 )
by Alexandr
03:23
created

LoadTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 7
dl 0
loc 56
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testLoad10k() 0 51 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: mounter
5
 * Date: 8/18/16
6
 * Time: 2:17 PM
7
 */
8
9
namespace Youshido\Tests\Performance;
10
11
12
use Youshido\GraphQL\Execution\Processor;
13
use Youshido\GraphQL\Schema\Schema;
14
use Youshido\GraphQL\Type\ListType\ListType;
15
use Youshido\GraphQL\Type\Object\ObjectType;
16
use Youshido\GraphQL\Type\Scalar\IdType;
17
use Youshido\GraphQL\Type\Scalar\StringType;
18
19
class LoadTest extends \PHPUnit_Framework_TestCase
20
{
21
22
    public function testLoad10k()
23
    {
24
        $time = microtime(true);
0 ignored issues
show
Unused Code introduced by
$time is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
        $postType = new ObjectType([
26
            'name'   => 'Post',
27
            'fields' => [
28
                'id'      => new IdType(),
29
                'title'   => new StringType(),
30
                'authors' => [
31
                    'type' => new ListType(new ObjectType([
32
                        'name'   => 'Author',
33
                        'fields' => [
34
                            'name' => new StringType()
35
                        ]
36
                    ]))
37
                ],
38
            ]
39
        ]);
40
41
        $data = [];
42
        for ($i = 1; $i <= 10000; ++$i) {
43
            $authors = [];
44
            while (count($authors) < rand(1, 4)) {
45
                $authors[] = [
46
                    'name' => 'Author ' . substr(md5(time()), 0, 4)
47
                ];
48
            }
49
            $data[] = [
50
                'id'      => $i,
51
                'title'   => 'Title of ' . $i,
52
                'authors' => $authors,
53
            ];
54
        }
55
56
        $p = new Processor(new Schema([
0 ignored issues
show
Unused Code introduced by
$p is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
            'query' => new ObjectType([
58
                'name' => 'RootQuery',
59
                'fields' => [
60
                    'posts' => [
61
                        'type' => new ListType($postType),
62
                        'resolve' => function() use ($data) {
63
                            return $data;
64
                        }
65
                    ]
66
                ],
67
            ]),
68
        ]));
69
//        $p->processPayload('{ posts { id, title, authors { name } } }');
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
//        var_dump(microtime(true) - $time);die();
71
//        $p->getResponseData();
72
    }
73
74
}