/** * @param Vampire $vampire */ public function addVampire(Vampire $vampire) { $position = FilePosition::createPosition($vampire->getFile(), $vampire->getLine()); $logDate = strtotime($vampire->getInvocationDate()); if (!isset($this->vampires[$position]) || $logDate > $this->maxDatePerPosition[$position]) { $this->vampires[$position] = $vampire; $this->maxDatePerPosition[$position] = $logDate; } }
/** * @param Vampire $vampire * @param TombstoneIndex $tombstoneIndex * * @return Tombstone|null */ public function matchVampireToTombstone(Vampire $vampire, TombstoneIndex $tombstoneIndex) { if ($matchingTombstone = $tombstoneIndex->getInFileAndLine($vampire->getFile(), $vampire->getLine())) { if ($vampire->inscriptionEquals($matchingTombstone)) { return $matchingTombstone; } } return null; }
/** * @param Vampire $vampire * * @return string */ public static function vampireToLog(Vampire $vampire) { return json_encode(array('v' => self::CURRENT_VERSION, 'd' => $vampire->getTombstoneDate(), 'a' => $vampire->getAuthor(), 'l' => $vampire->getLabel(), 'f' => $vampire->getFile(), 'n' => $vampire->getLine(), 'm' => $vampire->getMethod(), 'id' => $vampire->getInvocationDate(), 'im' => $vampire->getInvoker())); }
/** * Formats a Vampire for the log * * @param Vampire $vampire * * @return string */ public function format(Vampire $vampire) { return json_encode(array('tombstoneDate' => $vampire->getTombstoneDate(), 'author' => $vampire->getAuthor(), 'label' => $vampire->getLabel(), 'file' => $vampire->getFile(), 'line' => $vampire->getLine(), 'method' => $vampire->getMethod(), 'invocationDate' => $vampire->getInvocationDate(), 'invoker' => $vampire->getInvoker())) . "\n"; }
/** * Formats a Vampire for the log * * @param Vampire $vampire * * @return string */ public function format(Vampire $vampire) { $template = '%s - Vampire detected: tombstone("%s", "%s"%s), in file %s:%s, in function %s, invoked by %s' . "\n"; return sprintf($template, $vampire->getInvocationDate(), $vampire->getTombstoneDate(), $vampire->getAuthor(), $vampire->getLabel() ? ', "' . $vampire->getLabel() . '"' : '', $vampire->getFile(), $vampire->getLine(), $vampire->getMethod(), $vampire->getInvoker()); }