Completed
Pull Request — master (#1933)
by
unknown
02:29
created

NodeTest::testGetId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Elastica\Test;
4
5
use Elastica\Node;
6
use Elastica\Test\Base as BaseTest;
7
8
/**
9
 * @internal
10
 */
11
class NodeTest extends BaseTest
12
{
13
    /**
14
     * @group functional
15
     */
16 View Code Duplication
    public function testCreateNode(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
17
    {
18
        $client = $this->_getClient();
19
        $names = $client->getCluster()->getNodeNames();
20
        $name = \reset($names);
21
22
        $node = new Node($name, $client);
0 ignored issues
show
Security Bug introduced by
It seems like $name defined by \reset($names) on line 20 can also be of type false; however, Elastica\Node::__construct() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
23
        $this->assertSame($name, $node->getId());
24
    }
25
26
    /**
27
     * @group functional
28
     */
29 View Code Duplication
    public function testGetInfo(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
30
    {
31
        $client = $this->_getClient();
32
        $names = $client->getCluster()->getNodeNames();
33
        $name = \reset($names);
34
35
        $node = new Node($name, $client);
0 ignored issues
show
Security Bug introduced by
It seems like $name defined by \reset($names) on line 33 can also be of type false; however, Elastica\Node::__construct() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
36
37
        $info = $node->getInfo();
38
39
        $this->assertSame($node, $info->getNode());
40
    }
41
42
    /**
43
     * @group functional
44
     */
45 View Code Duplication
    public function testGetStats(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
46
    {
47
        $client = $this->_getClient();
48
        $names = $client->getCluster()->getNodeNames();
49
        $name = \reset($names);
50
51
        $node = new Node($name, $client);
0 ignored issues
show
Security Bug introduced by
It seems like $name defined by \reset($names) on line 49 can also be of type false; however, Elastica\Node::__construct() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
52
53
        $stats = $node->getStats();
54
55
        $this->assertSame($node, $stats->getNode());
56
    }
57
58
    /**
59
     * @group functional
60
     */
61 View Code Duplication
    public function testGetName(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
62
    {
63
        $client = $this->_getClient();
64
65
        $nodes = $client->getCluster()->getNodes();
66
        // At least 1 instance must exist
67
        $this->assertGreaterThan(0, $nodes);
68
69
        $data = $client->request('_nodes')->getData();
70
        $rawNodes = $data['nodes'];
71
72
        foreach ($nodes as $node) {
73
            $this->assertEquals($rawNodes[$node->getId()]['name'], $node->getName());
74
        }
75
    }
76
}
77