Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Jan 2, 2015
1 parent d44b9ed commit 1867dfb
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/collector/project/SourceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,18 @@ public function getSource() {
return $this->src;
}

$code = file_get_contents($this->getPathname());

$info = new \finfo();
$encoding = $info->file( (string)$this, FILEINFO_MIME_ENCODING);
if (strtolower($encoding) != 'utf-8' && $code != '') {
try {
$code = iconv($encoding, 'UTF-8//TRANSLIT', $code);
} catch (\ErrorException $e) {
throw new SourceFileException('Encoding error - conversion to UTF-8 failed', SourceFileException::BadEncoding, $e);
}
$source = file_get_contents($this->getPathname());
if ($source == '') {
$this->src = '';
return '';
}

// This is a workaround to filter out leftover invalid UTF-8 byte sets
// even if the source looks like it's UTF-8 already
mb_substitute_character('none');
$cleanCode = mb_convert_encoding($code, 'UTF-8', 'UTF-8');
if ($cleanCode != $code) {
throw new SourceFileException('Encoding error - invalid UTF-8 bytes found', SourceFileException::InvalidDataBytes);
$info = new \finfo();
$encoding = $info->file((string)$this, FILEINFO_MIME_ENCODING);
try {
$source = iconv($encoding, 'UTF-8//TRANSLIT', $source);
} catch (\ErrorException $e) {
throw new SourceFileException('Encoding error - conversion to UTF-8 failed', SourceFileException::BadEncoding, $e);
}

// Replace xml relevant control characters by surrogates
Expand All @@ -65,7 +59,7 @@ function(array $matches) {
$unicodeChar = '\u' . (2400 + ord($matches[0]));
return json_decode('"'.$unicodeChar.'"');
},
$cleanCode
$source
);

return $this->src;
Expand Down

0 comments on commit 1867dfb

Please sign in to comment.