Completed
Push — master ( 4783ce...1821eb )
by Dennis
03:38
created

benchWarmParentItemAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/**
4
 * (c) Dennis Meckel
5
 *
6
 * For the full copyright and license information,
7
 * please view the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Rayne\wz2008\Graph\Benchmark\Graph;
11
12
use Rayne\wz2008\Graph\Benchmark\ParentItemAccessCase;
13
use Rayne\wz2008\Graph\Factory\WzClassificationFactory;
14
use SimpleXMLElement;
15
16
class SimpleXmlParentItemAccessBench extends ParentItemAccessCase
17
{
18
    /**
19
     * @var null|SimpleXMLElement
20
     */
21
    private $child;
22
23
    /**
24
     * @var SimpleXMLElement
25
     */
26
    private $xml;
27
28
    /**
29
     *
30
     */
31
    public function __construct()
32
    {
33
        $this->xml = simplexml_load_file($this->getAssetFile(WzClassificationFactory::SUPPLIED_CLASSIFICATION_FILE));
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function benchColdParentItemAccess(array $params)
40
    {
41
        $child = $this->xml->xpath('//Item[@id="' . $params['child'] . '"][1]')[0];
42
        $parentLevel = $child['idLevel'] - 1;
43
        $parent = $child->xpath('preceding-sibling::Item[@idLevel="' . $parentLevel . '"][1]')[0];
1 ignored issue
show
Bug introduced by
The method xpath cannot be called on $child (of type array<string,integer|dou...vel":"integer|double"}>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
44
45
        $this->assertSame($params['parent'], (string)$parent['id']);
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function beforeWarmParentItemAccess(array $params)
52
    {
53
        $this->child = $this->xml->xpath('//Item[@id="' . $params['child'] . '"][1]')[0];
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function benchWarmParentItemAccess(array $params)
60
    {
61
        $child = $this->child;
62
        $parentLevel = $child['idLevel'] - 1;
63
        $parent = $child->xpath('preceding-sibling::Item[@idLevel="' . $parentLevel . '"][1]')[0];
64
65
        $this->assertSame($params['parent'], (string)$parent['id']);
66
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71
    public function afterWarmParentItemAccess(array $params)
72
    {
73
        $this->child = null;
74
    }
75
}
76