Completed
Pull Request — master (#4)
by
unknown
02:46
created

MagentoDataCollector::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @project Magento Bridge for Symfony 2.
5
 *
6
 * @author  Sébastien MALOT <[email protected]>
7
 * @license MIT
8
 * @url     <https://github.com/smalot/magento-bundle>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Smalot\MagentoBundle\DataCollector;
15
16
use Smalot\MagentoBundle\Logger\LoggerInterface;
17
use Smalot\MagentoBundle\Logger\MagentoLogger;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\Response;
20
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
21
22
/**
23
 * Class MagentoDataCollector
24
 *
25
 * @package Smalot\MagentoBundle\Collector
26
 */
27
class MagentoDataCollector extends DataCollector {
28
29
    /**
30
     * @var MagentoLogger
31
     */
32
    protected $logger;
33
34
    /**
35
     * @param LoggerInterface $logger
36
     */
37
    public function __construct(LoggerInterface $logger) {
38
        $this->logger = $logger;
0 ignored issues
show
Documentation Bug introduced by
$logger is of type object<Smalot\MagentoBun...Logger\LoggerInterface>, but the property $logger was declared to be of type object<Smalot\MagentoBundle\Logger\MagentoLogger>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
39
    }
40
41
    /**
42
     * @param Request    $request
43
     * @param Response   $response
44
     * @param \Exception $exception
45
     */
46
    public function collect(Request $request, Response $response, \Exception $exception = null) {
47
        if ($this->logger) {
48
            $this->data = array('magento' => $this->logger->getCalls());
49
        } else {
50
            $this->data = array('magento' => array());
51
        }
52
    }
53
54
    public function reset() {
55
        $this->data = array();
56
    }
57
58
    /**
59
     * Return total duration in seconds.
60
     *
61
     * @return float
62
     */
63
    public function getTime() {
64
        $time = 0.0;
65
66
        foreach ($this->data['magento'] as $log) {
67
            $time += $log['time'];
68
        }
69
70
        return $time;
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getCalls() {
77
        $calls = array();
78
79
        foreach ($this->data['magento'] as $call) {
80
            $calls[$call['connection']][] = $call;
81
        }
82
83
        return $calls;
84
    }
85
86
    /**
87
     * @return int
88
     */
89
    public function getCallCount() {
90
        return count($this->data['magento']);
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function getInvalidEntityCount() {
97
        return 0;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getName() {
104
        return 'magento';
105
    }
106
107
}
108