Skip to content

Commit 1867dfb

Browse files
committed
Simplify
1 parent d44b9ed commit 1867dfb

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/collector/project/SourceFile.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,18 @@ public function getSource() {
3838
return $this->src;
3939
}
4040

41-
$code = file_get_contents($this->getPathname());
42-
43-
$info = new \finfo();
44-
$encoding = $info->file( (string)$this, FILEINFO_MIME_ENCODING);
45-
if (strtolower($encoding) != 'utf-8' && $code != '') {
46-
try {
47-
$code = iconv($encoding, 'UTF-8//TRANSLIT', $code);
48-
} catch (\ErrorException $e) {
49-
throw new SourceFileException('Encoding error - conversion to UTF-8 failed', SourceFileException::BadEncoding, $e);
50-
}
41+
$source = file_get_contents($this->getPathname());
42+
if ($source == '') {
43+
$this->src = '';
44+
return '';
5145
}
5246

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

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

7165
return $this->src;

0 commit comments

Comments
 (0)