/** * With lots of various rules we created 4 various rulesets for operators. If one * of the tokens or content is found we use the given regex on the joined array. * * @param Testable $testable The testable object * @return void */ public function apply($testable, array $config = array()) { $tokens = $testable->tokens(); foreach ($this->inspector as $inspector) { if (isset($inspector['tokens'])) { $byToken = $testable->findAll($inspector['tokens']); } else { $byToken = array(); } if (isset($inspector['content'])) { $byContent = $testable->findAllContent($inspector['content']); } else { $byContent = array(); } foreach (array_merge($byToken, $byContent) as $id) { $token = $tokens[$id]; $isPHP = $testable->isPHP($token['line']); if ($isPHP && empty($token['isString'])) { $pattern = String::insert($inspector['regex'], array('content' => preg_quote($token['content'], "/"))); $firstId = $id - $inspector['relativeTokens']['before']; $firstId = $firstId < 0 ? 0 : $firstId; $length = $inspector['relativeTokens']['length']; $inspectTokens = array_slice($tokens, $firstId, $length); $html = null; foreach ($inspectTokens as $htmlToken) { $html .= $htmlToken['content']; } if (preg_match($pattern, $html) === 0) { $this->addViolation(array('message' => String::insert($inspector['message'], $token), 'line' => $token['line'])); } } } } }