->->children from php generated html
- $sourceElements = $sourceDom->getElementsByTagname('code')->item(0)
- ->childNodes->item(0)->childNodes;
+ $sourceElements = $sourceDom->getElementsByTagName('code')->item(0)
+ ->childNodes->item(0)->childNodes;
//create target dom
$targetDom = new DOMDocument();
@@ -212,10 +218,13 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument
// iterate through all elements
foreach ($sourceElements as $sourceElement) {
- if (!$sourceElement instanceof DOMElement) {
+ if ($sourceElement instanceof DOMText) {
$span = $targetDom->createElement('span');
- $span->nodeValue = htmlspecialchars($sourceElement->wholeText);
+ $span->nodeValue = \htmlspecialchars($sourceElement->wholeText, ENT_COMPAT);
$liElement->appendChild($span);
+ }
+
+ if (!$sourceElement instanceof DOMElement) {
continue;
}
@@ -223,6 +232,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument
// create new li and new line
$liElement = $targetDom->createElement('li');
$targetNode->appendChild($liElement);
+
continue;
}
@@ -240,7 +250,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument
} else {
// append content to current li element
$span = $targetDom->createElement('span');
- $span->nodeValue = htmlspecialchars($sourceChildElement->textContent);
+ $span->nodeValue = \htmlspecialchars($sourceChildElement->textContent, ENT_COMPAT);
$span->setAttribute('class', $elementClass);
$liElement->appendChild($span);
}
@@ -259,7 +269,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument
*/
protected function mapPhpColors(string $style): string
{
- $color = substr($style, 7);
+ $color = \substr($style, 7);
return $this->phpHighlightColorMap[$color];
}
@@ -278,18 +288,13 @@ protected function mapPhpColors(string $style): string
protected function highlightCode(string $file): DOMDocument
{
$sourceCode = $this->ioHelper->loadFile($file);
- $extension = pathinfo($file, PATHINFO_EXTENSION);
+ $extension = \pathinfo($file, PATHINFO_EXTENSION);
- if (\in_array($extension, $this->phpSuffixes)) {
+ if (\in_array($extension, $this->phpSuffixes, true)) {
return $this->highlightPhpCode($sourceCode);
}
- $sourceCode = preg_replace(
- '/^.*$/m',
- '$0 ',
- htmlentities($sourceCode)
- );
- $sourceCode = preg_replace('/ /', ' ', $sourceCode);
+ $sourceCode = \preg_replace(['/^.*$/m', '/ /'], ['$0 ', ' '], \htmlentities($sourceCode, ENT_COMPAT));
$sourceCode = ''.$sourceCode.'
';
$sourceCode = $this->stripInvalidXml($sourceCode);
@@ -323,42 +328,49 @@ private function formatSourceCode(string $filename, array $outputIssues): string
}
$lineNumber = 0;
- $linePlaces = floor(log($lines->length, 10)) + 1;
+ $linePlaces = \floor(\log($lines->length, 10)) + 1;
- /** @var DOMElement:: $line */
foreach ($lines as $line) {
+ /**
+ * @var DOMElement $line
+ */
+ $line = $line;
++$lineNumber;
$line->setAttribute('id', 'line_'.$lineNumber);
$lineClasses = [
- ($lineNumber % 2) ? 'odd' : 'even',
+ ($lineNumber % 2 === 0) ? 'odd' : 'even',
];
if (isset($outputIssues[$lineNumber])) {
$lineClasses[] = 'hasIssues';
$message = '|';
+
foreach ($outputIssues[$lineNumber] as $issue) {
- $message .= sprintf(
+ $message .= \sprintf(
'
%s
%s
',
- $issue->foundBy,
- $issue->foundBy,
- $issue->description
+ $issue->getFoundBy(),
+ $issue->getFoundBy(),
+ $issue->getDescription()
);
}
- $line->setAttribute('title', utf8_encode($message));
+
+ $line->setAttribute('title', $message);
}
// Add line number
$nuSpan = $sourceDom->createElement('span');
$nuSpan->setAttribute('class', 'lineNumber');
+
for ($i = 0; $i < $linePlaces - \strlen((string) $lineNumber); ++$i) {
$nuSpan->appendChild($sourceDom->createEntityReference('nbsp'));
}
+
$nuSpan->appendChild($sourceDom->createTextNode((string) $lineNumber));
$nuSpan->appendChild($sourceDom->createEntityReference('nbsp'));
$line->insertBefore($nuSpan, $line->firstChild);
@@ -368,25 +380,32 @@ private function formatSourceCode(string $filename, array $outputIssues): string
$anchor->setAttribute('name', 'line_'.$lineNumber);
$line->appendChild($anchor);
+ $lineErrorCount = (isset($outputIssues[$lineNumber])
+ ? \count($outputIssues[$lineNumber])
+ : 0);
+
// set li css class depending on line errors
- switch ($tmp = (isset($outputIssues[$lineNumber])
- ? \count($outputIssues[$lineNumber])
- : 0)) {
+ switch ($lineErrorCount) {
case 0:
break;
case 1:
- $lineClasses[] = $outputIssues[$lineNumber][0]->foundBy;
+ $lineClasses[] = $outputIssues[$lineNumber][0]->getFoundBy();
+
break;
- case 1 < $tmp:
+ case 1 < $lineErrorCount:
$lineClasses[] = 'moreErrors';
+
break;
+
// This can't happen, count always returns >= 0
// @codeCoverageIgnoreStart
default:
break;
+
// @codeCoverageIgnoreEnd
}
- $line->setAttribute('class', implode(' ', $lineClasses));
+
+ $line->setAttribute('class', \implode(' ', $lineClasses));
}
return $sourceDom->saveHTML();
@@ -403,8 +422,9 @@ private function formatSourceCode(string $filename, array $outputIssues): string
private function formatIssues(array $issueList): array
{
$outputIssues = [];
+
foreach ($issueList as $issue) {
- for ($i = $issue->lineStart; $i <= $issue->lineEnd; ++$i) {
+ for ($i = $issue->getLineStart(); $i <= $issue->getLineEnd(); ++$i) {
$outputIssues[$i][] = $issue;
}
}
@@ -430,8 +450,10 @@ private function stripInvalidXml(string $value): string
}
$length = \strlen($value);
+
for ($i = 0; $i < $length; ++$i) {
- $current = \ord($value{$i});
+ $current = \ord($value[$i]);
+
if ((0x9 === $current)
|| (0xA === $current)
|| (0xD === $current)
diff --git a/templates/index.tpl b/templates/index.tpl
index 7cf59e0..ec719b8 100644
--- a/templates/index.tpl
+++ b/templates/index.tpl
@@ -52,7 +52,7 @@ $occuringErrorTypes = array (
foreach ($fileList as $file) {
/** @var $file PHPCodeBrowser\File */
foreach ($file->getIssues() as $issue) {
- $occuringErrorTypes[$issue->foundBy] = true;
+ $occuringErrorTypes[$issue->getFoundBy()] = true;
}
}
@@ -85,7 +85,7 @@ foreach ($fileList as $filename => $f) {
$counts = array_fill_keys($occuringErrorTypes, 0);
foreach ($f->getIssues() as $issue) {
- $counts[$issue->foundBy] += 1;
+ $counts[$issue->getFoundBy()] += 1;
}
echo " " . PHP_EOL;
diff --git a/templates/review.tpl b/templates/review.tpl
index 4c98bdb..c51b4c8 100644
--- a/templates/review.tpl
+++ b/templates/review.tpl
@@ -57,24 +57,24 @@
-
+
-
- lineStart; ?>
+
+ getLineStart(); ?>
- lineEnd; ?>', {duration: 1.5}); return false">
- lineEnd;?>
+ getLineEnd(); ?>', {duration: 1.5}); return false">
+ getLineEnd();?>
- lineEnd; ?>', {duration: 1.5}); return false">
- description;?>
+ getLineEnd(); ?>', {duration: 1.5}); return false">
+ getDescription();?>
- foundBy;?>
+ getFoundBy();?>
- severity;?>
+ getSeverity();?>