1 | <?php |
||
17 | class PhpQuickProfiler |
||
18 | { |
||
19 | |||
20 | /** @var double */ |
||
21 | protected $startTime; |
||
22 | |||
23 | /** @var Console */ |
||
24 | protected $console; |
||
25 | |||
26 | /** @var Display */ |
||
27 | protected $display; |
||
28 | |||
29 | /** @var array */ |
||
30 | protected $profiledQueries = array(); |
||
31 | |||
32 | /** |
||
33 | * @param double $startTime |
||
34 | */ |
||
35 | public function __construct($startTime = null) |
||
42 | |||
43 | /** |
||
44 | * @param Console $console |
||
45 | */ |
||
46 | public function setConsole(Console $console) |
||
50 | |||
51 | /** |
||
52 | * @param Display $display |
||
53 | */ |
||
54 | public function setDisplay(Display $display) |
||
58 | |||
59 | /** |
||
60 | * Get data about files loaded for the application to current point |
||
61 | * |
||
62 | * @returns array |
||
63 | */ |
||
64 | public function gatherFileData() |
||
76 | |||
77 | /** |
||
78 | * Get data about memory usage of the application |
||
79 | * |
||
80 | * @returns array |
||
81 | */ |
||
82 | public function gatherMemoryData() |
||
91 | |||
92 | /** |
||
93 | * @param array $profiled_queries |
||
|
|||
94 | */ |
||
95 | public function setProfiledQueries(array $profiledQueries) |
||
99 | |||
100 | /** |
||
101 | * Get data about sql usage of the application |
||
102 | * |
||
103 | * @param object $dbConnection |
||
104 | * @returns array |
||
105 | */ |
||
106 | public function gatherQueryData($dbConnection = null) |
||
107 | { |
||
108 | if (is_null($dbConnection)) { |
||
109 | return array(); |
||
110 | } |
||
111 | |||
112 | if (empty($this->profiledQueries) && property_exists($dbConnection, 'queries')) { |
||
113 | $this->setProfiledQueries($dbConnection->queries); |
||
114 | } |
||
115 | |||
116 | $data = array(); |
||
117 | foreach ($this->profiledQueries as $query) { |
||
118 | array_push($data, array( |
||
119 | 'sql' => $query['sql'], |
||
120 | 'explain' => $this->explainQuery($dbConnection, $query['sql'], $query['parameters']), |
||
121 | 'time' => $query['time'] |
||
122 | )); |
||
123 | } |
||
124 | return $data; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Attempts to explain a query |
||
129 | * |
||
130 | * @param object $dbConnection |
||
131 | * @param string $query |
||
132 | * @param array $parameters |
||
133 | * @throws Exception |
||
134 | * @return array |
||
135 | */ |
||
136 | protected function explainQuery($dbConnection, $query, $parameters = array()) |
||
151 | |||
152 | /** |
||
153 | * Attempts to figure out what kind of explain query format the db wants |
||
154 | * |
||
155 | * @param string $query |
||
156 | * @param string $driver |
||
157 | * @throws Exception |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function getExplainQuery($query, $driver) |
||
169 | |||
170 | /** |
||
171 | * Get data about speed of the application |
||
172 | * |
||
173 | * @returns array |
||
174 | */ |
||
175 | public function gatherSpeedData() |
||
185 | |||
186 | /** |
||
187 | * Triggers end display of the profiling data |
||
188 | * |
||
189 | * @param object $dbConnection |
||
190 | * @throws Exception |
||
191 | */ |
||
192 | public function display($dbConnection = null) |
||
209 | } |
||
210 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.