LoadTest::testLoad10k()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 9.0036
c 0
b 0
f 0
cc 3
nc 3
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        return true;
70
        $p->processPayload('{ posts { id, title, authors { name } } }');
0 ignored issues
show
Unused Code introduced by
$p->processPayload('{ po...authors { name } } }'); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
71
        $res = $p->getResponseData();
72
        echo "Count: " . count($res['data']['posts']) . "\n";
73
        var_dump($res['data']['posts'][0]);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($res['data']['posts'][0]); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
74
        printf("Test Time: %04f\n", microtime(true) - $time);
75
    }
76
77
}