Esempio n. 1
0
 /**
  * @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
  * @param TombstoneIndex $tombstoneIndex
  *
  * @return Tombstone|null
  */
 public function matchVampireToTombstone(Vampire $vampire, TombstoneIndex $tombstoneIndex)
 {
     if ($matchingTombstones = $tombstoneIndex->getInMethod($vampire->getMethod())) {
         foreach ($matchingTombstones as $matchingTombstone) {
             if ($vampire->inscriptionEquals($matchingTombstone)) {
                 return $matchingTombstone;
             }
         }
     }
     return null;
 }
Esempio n. 4
0
 /**
  * @param string $date
  * @param string $author
  * @param string|null $label
  * @param array $trace
  */
 public function tombstone($date, $author, $label, array $trace)
 {
     $trace = $this->traceRelativePath($trace);
     $vampire = Vampire::createFromCall($date, $author, $label, $trace);
     foreach ($this->handlers as $handler) {
         $handler->log($vampire);
     }
 }
Esempio n. 5
0
 /**
  * @test
  */
 public function createFromCall_dataGiven_returnCorrectlyConstructedVampire()
 {
     $stackTrace = TraceFixture::getTraceFixture();
     $vampire = Vampire::createFromCall('2015-08-19', 'author', 'label', $stackTrace);
     $this->assertInstanceOf('Scheb\\Tombstone\\Vampire', $vampire);
     $this->assertInstanceOf('Scheb\\Tombstone\\Tombstone', $vampire->getTombstone());
     $this->assertEquals('2015-08-19', $vampire->getTombstoneDate());
     $this->assertEquals('author', $vampire->getAuthor());
     $this->assertEquals('label', $vampire->getLabel());
     $this->assertEquals('/path/to/file1.php', $vampire->getFile());
     $this->assertEquals(11, $vampire->getLine());
     $this->assertEquals('containingMethodName', $vampire->getMethod());
     $this->assertEquals('invokerMethodName', $vampire->getInvoker());
     $invocationDate = strtotime($vampire->getInvocationDate());
     $this->assertEquals(time(), $invocationDate, null, 5);
 }
Esempio n. 6
0
 /**
  * @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()));
 }
Esempio n. 7
0
 /**
  * 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";
 }
Esempio n. 8
0
 /**
  * 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());
 }
Esempio n. 9
0
 public function format(Vampire $vampire)
 {
     return $vampire->getLabel();
 }
Esempio n. 10
0
 /**
  * @param Vampire $vampire
  *
  * @return string
  */
 private function getLogFile(Vampire $vampire)
 {
     $date = date('Ymd');
     $hash = $vampire->getTombstone()->getHash();
     return $this->logDir . '/' . sprintf(self::LOG_FILE_NAME, $hash, $date);
 }