/** * addFile(): defined by Report interface. * * @see Report::addFile() * @param File $file * @return void */ public function addFile(File $file) { $this->writer->startElement('file'); $this->writer->writeAttribute('name', $file->getFilename()); foreach ($file->getViolations() as $violation) { $this->writer->startElement('error'); $this->writer->writeAttribute('line', $violation->getLine()); if ($violation->getColumn() > 0) { $this->writer->writeAttribute('column', $violation->getColumn()); } $this->writer->writeAttribute('severity', $violation->getSeverity()); $this->writer->writeAttribute('message', $violation->getMessage()); $this->writer->writeAttribute('source', $violation->getSource()); $this->writer->endElement(); } $this->writer->endElement(); }
/** * visitToken(): defined by TokenRuleInterface. * * @see TokenRuleInterface::visitToken() * @param File $file * @return void */ public function visitToken(File $file) { if (!$file->seekTokenType(T_STRING, false, '{')) { return; } $token = $file->current(); $psr0Compliant = true; if ($token->getNamespace() !== null) { $fqcn = $token->getNamespace() . '\\' . $token->getLexeme(); $path = str_replace('\\', '/', $token->getNamespace()) . '/' . str_replace('_', '/', $token->getLexeme()); } else { $fqcn = $token->getLexeme(); $path = str_replace('_', '/', $token->getLexeme()); if ($this->requireVendorNamespace) { $psr0Compliant = false; } } if ($psr0Compliant) { $expectedPathParts = array_diff(explode('/', $path), array('')); $expectedFilename = array_pop($expectedPathParts) . '.php'; $pathParts = explode('/', str_replace('\\', '/', realpath($file->getFilename()))); $filename = array_pop($pathParts); if ($filename !== $expectedFilename) { // Class name should match filename. $psr0Compliant = false; } elseif (count($expectedPathParts) === 0) { // Vendor level namespace required. $psr0Compliant = false; } else { // Path should match namespace structure. $pathParts = array_slice($pathParts, -count($expectedPathParts)); if ($pathParts !== $expectedPathParts) { $psr0Compliant = false; } } } if (!$psr0Compliant) { $this->addViolation($file, $token->getLine(), $token->getColumn(), sprintf('Class name "%s" is not PSR0 compliant', $fqcn)); } }
/** * addFile(): defined by Report interface. * * @see Report::addFile() * @param File $file * @return void */ public function addFile(File $file) { $violations = $file->getViolations(); if ($violations) { if ($this->firstFile) { $this->firstFile = false; } else { echo PHP_EOL; } echo $file->getFilename() . ':' . PHP_EOL; echo str_repeat('-', 80) . PHP_EOL; foreach ($violations as $violation) { echo $violation->getLine() . ':'; if ($violation->getColumn() > 0) { echo $violation->getColumn() . ':'; } echo $violation->getSeverityName() . ': '; echo $violation->getMessage() . PHP_EOL; } flush(); } }