@@ -55,19 +55,20 @@ abstract class AbstractMetricCheck
5555 protected $ logger ;
5656
5757 /**
58- * @var bool
58+ * @var boolean
5959 */
6060 protected $ verbose ;
6161
6262 /**
6363 * Constructor, called from the beforeTest event
6464 *
6565 * @param PageReadinessExtension $extension
66- * @param TestInterface $test
67- * @param integer $resetFailureThreshold
66+ * @param TestInterface $test
67+ * @param integer $resetFailureThreshold
6868 * @throws \Exception
6969 */
70- public function __construct ($ extension , $ test , $ resetFailureThreshold ){
70+ public function __construct ($ extension , $ test , $ resetFailureThreshold )
71+ {
7172 $ this ->extension = $ extension ;
7273 $ this ->test = $ test ;
7374 $ this ->logger = LoggingUtil::getInstance ()->getLogger (get_class ($ this ));
@@ -78,8 +79,7 @@ public function __construct($extension, $test, $resetFailureThreshold){
7879 $ reflector = new \ReflectionMethod ($ this , 'clearFailureOnPage ' );
7980 if ($ reflector ->getDeclaringClass ()->getName () === get_class ($ this )) {
8081 $ this ->resetFailureThreshold = $ resetFailureThreshold ;
81- }
82- else {
82+ } else {
8383 $ this ->resetFailureThreshold = -1 ;
8484 }
8585
@@ -90,25 +90,26 @@ public function __construct($extension, $test, $resetFailureThreshold){
9090 * Does the given value pass the readiness metric
9191 *
9292 * @param mixed $value
93- * @return bool
93+ * @return boolean
9494 */
95- protected abstract function doesMetricPass ($ value );
95+ abstract protected function doesMetricPass ($ value );
9696
9797 /**
9898 * Retrieve the active value for the metric to check from the page
9999 *
100100 * @return mixed
101101 * @throws UnexpectedAlertOpenException
102102 */
103- protected abstract function fetchValueFromPage ();
103+ abstract protected function fetchValueFromPage ();
104104
105105 /**
106106 * Override this method to reset the actual state of the page to make the metric pass
107107 * This method is called when too many identical failures were encountered in a row
108108 *
109109 * @return void
110110 */
111- protected function clearFailureOnPage () {
111+ protected function clearFailureOnPage ()
112+ {
112113 return ;
113114 }
114115
@@ -117,7 +118,8 @@ protected function clearFailureOnPage() {
117118 *
118119 * @return string
119120 */
120- public function getName () {
121+ public function getName ()
122+ {
121123 $ clazz = get_class ($ this );
122124 $ namespaceBreak = strrpos ($ clazz , '\\' );
123125 if ($ namespaceBreak !== false ) {
@@ -133,10 +135,11 @@ public function getName() {
133135 * to catch cases where a slow request of one metric can trigger calls for other metrics that were previously
134136 * thought ready
135137 *
136- * @return bool
138+ * @return boolean
137139 * @throws UnexpectedAlertOpenException
138140 */
139- public function runCheck () {
141+ public function runCheck ()
142+ {
140143 if ($ this ->doesMetricPass ($ this ->getCurrentValue (true ))) {
141144 $ this ->setTracker ($ this ->getCurrentValue ());
142145 return true ;
@@ -154,11 +157,11 @@ public function runCheck() {
154157 * @param Step $step
155158 * @return void
156159 */
157- public function finalize ($ step ) {
160+ public function finalize ($ step )
161+ {
158162 try {
159163 $ currentValue = $ this ->getCurrentValue ();
160- }
161- catch (UnexpectedAlertOpenException $ exception ) {
164+ } catch (UnexpectedAlertOpenException $ exception ) {
162165 $ this ->debugLog (
163166 'An alert is open, bypassing javascript-based metric check ' ,
164167 ['action ' => $ step ->getAction ()]
@@ -168,13 +171,11 @@ public function finalize($step) {
168171
169172 if ($ this ->doesMetricPass ($ currentValue )) {
170173 $ this ->setTracker ($ currentValue );
171- }
172- else {
174+ } else {
173175 // If failure happened on the same value as before, increment the fail count, otherwise set at 1
174176 if ($ currentValue !== $ this ->getStoredValue ()) {
175177 $ failCount = 1 ;
176- }
177- else {
178+ } else {
178179 $ failCount = $ this ->getFailureCount () + 1 ;
179180 }
180181 $ this ->setTracker ($ currentValue , $ failCount );
@@ -197,32 +198,35 @@ public function finalize($step) {
197198 * @return WebDriver
198199 * @throws ModuleRequireException
199200 */
200- protected function getDriver () {
201+ protected function getDriver ()
202+ {
201203 return $ this ->extension ->getDriver ();
202204 }
203205
204206 /**
205207 * Helper function to execute javascript code, see WebDriver::executeJs for more information
206208 *
207209 * @param string $script
208- * @param array $arguments
210+ * @param array $arguments
209211 * @return mixed
210212 * @throws UnexpectedAlertOpenException
211213 * @throws ModuleRequireException
212214 */
213- protected function executeJs ($ script , $ arguments = []) {
215+ protected function executeJs ($ script , $ arguments = [])
216+ {
214217 return $ this ->getDriver ()->executeJS ($ script , $ arguments );
215218 }
216219
217220 /**
218221 * Gets the current state of the given variable
219222 * Fetches an updated value if not known or $refresh is true
220223 *
221- * @param bool $refresh
224+ * @param boolean $refresh
222225 * @return mixed
223226 * @throws UnexpectedAlertOpenException
224227 */
225- private function getCurrentValue ($ refresh = false ) {
228+ private function getCurrentValue ($ refresh = false )
229+ {
226230 if ($ refresh ) {
227231 unset($ this ->currentValue );
228232 }
@@ -237,17 +241,19 @@ private function getCurrentValue($refresh = false) {
237241 *
238242 * @return mixed
239243 */
240- public function getStoredValue () {
244+ public function getStoredValue ()
245+ {
241246 return $ this ->test ->getMetadata ()->getCurrent ($ this ->getName ());
242247 }
243248
244249 /**
245250 * The current count of sequential identical failures
246251 * Used to detect potentially stuck metrics
247252 *
248- * @return int
253+ * @return integer
249254 */
250- public function getFailureCount () {
255+ public function getFailureCount ()
256+ {
251257 return $ this ->test ->getMetadata ()->getCurrent ($ this ->getName () . '.failCount ' );
252258 }
253259
@@ -257,33 +263,37 @@ public function getFailureCount() {
257263 *
258264 * @return void
259265 */
260- private function resetMetric () {
266+ private function resetMetric ()
267+ {
261268 $ this ->clearFailureOnPage ();
262269 $ this ->setTracker ();
263270 }
264271
265272 /**
266273 * Tracks the most recent value and the number of identical failures in a row
267274 *
268- * @param mixed $value
269- * @param int $failCount
275+ * @param mixed $value
276+ * @param integer $failCount
270277 * @return void
271278 */
272- public function setTracker ($ value = null , $ failCount = 0 ) {
279+ public function setTracker ($ value = null , $ failCount = 0 )
280+ {
273281 $ this ->test ->getMetadata ()->setCurrent ([
274282 $ this ->getName () => $ value ,
275283 $ this ->getName () . '.failCount ' => $ failCount
276284 ]);
277- unset ($ this ->currentValue );
285+ unset($ this ->currentValue );
278286 }
279287
280288 /**
281289 * Log the given message to logger->error including context information
282290 *
283291 * @param string $message
284- * @param array $context
292+ * @param array $context
293+ * @return void
285294 */
286- protected function errorLog ($ message , $ context = []) {
295+ protected function errorLog ($ message , $ context = [])
296+ {
287297 $ context = array_merge ($ this ->getLogContext (), $ context );
288298 $ this ->logger ->error ($ message , $ context );
289299 }
@@ -292,9 +302,11 @@ protected function errorLog($message, $context = []) {
292302 * Log the given message to logger->info including context information
293303 *
294304 * @param string $message
295- * @param array $context
305+ * @param array $context
306+ * @return void
296307 */
297- protected function infoLog ($ message , $ context = []) {
308+ protected function infoLog ($ message , $ context = [])
309+ {
298310 $ context = array_merge ($ this ->getLogContext (), $ context );
299311 $ this ->logger ->info ($ message , $ context );
300312 }
@@ -303,9 +315,11 @@ protected function infoLog($message, $context = []) {
303315 * If verbose, log the given message to logger->debug including context information
304316 *
305317 * @param string $message
306- * @param array $context
318+ * @param array $context
319+ * @return void
307320 */
308- protected function debugLog ($ message , $ context = []) {
321+ protected function debugLog ($ message , $ context = [])
322+ {
309323 if ($ this ->verbose ) {
310324 $ context = array_merge ($ this ->getLogContext (), $ context );
311325 $ this ->logger ->debug ($ message , $ context );
@@ -318,7 +332,8 @@ protected function debugLog($message, $context = []) {
318332 *
319333 * @return array
320334 */
321- private function getLogContext () {
335+ private function getLogContext ()
336+ {
322337 $ testMeta = $ this ->test ->getMetadata ();
323338 return [
324339 'test ' => $ testMeta ->getName (),
0 commit comments