File tree Expand file tree Collapse file tree 5 files changed +29
-20
lines changed
Reflection/BetterReflection/SourceLocator Expand file tree Collapse file tree 5 files changed +29
-20
lines changed Original file line number Diff line number Diff line change 10
10
use PHPStan \Command \Output ;
11
11
use PHPStan \Dependency \ExportedNodeFetcher ;
12
12
use PHPStan \Dependency \RootExportedNode ;
13
+ use PHPStan \File \CouldNotReadFileException ;
13
14
use PHPStan \File \FileFinder ;
14
- use PHPStan \File \FileReader ;
15
15
use PHPStan \File \FileWriter ;
16
16
use PHPStan \Internal \ComposerHelper ;
17
17
use PHPStan \PhpDoc \StubFilesProvider ;
33
33
use function is_file ;
34
34
use function is_string ;
35
35
use function ksort ;
36
- use function sha1 ;
36
+ use function sha1_file ;
37
37
use function sort ;
38
38
use function sprintf ;
39
- use function str_replace ;
40
39
use function time ;
41
40
use function unlink ;
42
41
use function var_export ;
@@ -789,10 +788,10 @@ private function getFileHash(string $path): string
789
788
return $ this ->fileHashes [$ path ];
790
789
}
791
790
792
- $ contents = FileReader:: read ($ path );
793
- $ contents = str_replace ( "\r\n" , "\n" , $ contents );
794
-
795
- $ hash = sha1 ( $ contents );
791
+ $ hash = sha1_file ($ path );
792
+ if ( $ hash === false ) {
793
+ throw new CouldNotReadFileException ( $ path );
794
+ }
796
795
$ this ->fileHashes [$ path ] = $ hash ;
797
796
798
797
return $ hash ;
Original file line number Diff line number Diff line change 5
5
use Nette \DI \Config \Loader ;
6
6
use Nette \DI \Container as OriginalNetteContainer ;
7
7
use Nette \DI \ContainerLoader ;
8
- use PHPStan \File \FileReader ;
8
+ use PHPStan \File \CouldNotReadFileException ;
9
9
use function array_keys ;
10
10
use function error_reporting ;
11
11
use function restore_error_handler ;
12
12
use function set_error_handler ;
13
- use function sha1 ;
13
+ use function sha1_file ;
14
14
use const E_USER_DEPRECATED ;
15
15
use const PHP_RELEASE_VERSION ;
16
16
use const PHP_VERSION_ID ;
@@ -92,7 +92,13 @@ private function getAllConfigFilesHashes(): array
92
92
{
93
93
$ hashes = [];
94
94
foreach ($ this ->allConfigFiles as $ file ) {
95
- $ hashes [$ file ] = sha1 (FileReader::read ($ file ));
95
+ $ hash = sha1_file ($ file );
96
+
97
+ if ($ hash === false ) {
98
+ throw new CouldNotReadFileException ($ file );
99
+ }
100
+
101
+ $ hashes [$ file ] = $ hash ;
96
102
}
97
103
98
104
return $ hashes ;
Original file line number Diff line number Diff line change 6
6
use function array_key_exists ;
7
7
use function array_keys ;
8
8
use function count ;
9
- use function sha1 ;
9
+ use function sha1_file ;
10
10
11
11
class FileMonitor
12
12
{
@@ -81,7 +81,13 @@ public function getChanges(): FileMonitorResult
81
81
82
82
private function getFileHash (string $ filePath ): string
83
83
{
84
- return sha1 (FileReader::read ($ filePath ));
84
+ $ hash = sha1_file ($ filePath );
85
+
86
+ if ($ hash === false ) {
87
+ throw new CouldNotReadFileException ($ filePath );
88
+ }
89
+
90
+ return $ hash ;
85
91
}
86
92
87
93
}
Original file line number Diff line number Diff line change 3
3
namespace PHPStan \Reflection \BetterReflection \SourceLocator ;
4
4
5
5
use PHPStan \Cache \Cache ;
6
- use PHPStan \File \CouldNotReadFileException ;
7
6
use PHPStan \File \FileFinder ;
8
- use PHPStan \File \FileReader ;
9
7
use PHPStan \Php \PhpVersion ;
10
8
use PHPStan \Reflection \ConstantNameHelper ;
11
9
use function array_key_exists ;
15
13
use function php_strip_whitespace ;
16
14
use function preg_match_all ;
17
15
use function preg_replace ;
18
- use function sha1 ;
16
+ use function sha1_file ;
19
17
use function sprintf ;
20
18
use function strtolower ;
21
19
@@ -42,12 +40,11 @@ public function createByDirectory(string $directory): NewOptimizedDirectorySourc
42
40
$ files = $ this ->fileFinder ->findFiles ([$ directory ])->getFiles ();
43
41
$ fileHashes = [];
44
42
foreach ($ files as $ file ) {
45
- try {
46
- $ contents = FileReader::read ($ file );
47
- } catch (CouldNotReadFileException ) {
43
+ $ hash = sha1_file ($ file );
44
+ if ($ hash === false ) {
48
45
continue ;
49
46
}
50
- $ fileHashes [$ file ] = sha1 ( $ contents ) ;
47
+ $ fileHashes [$ file ] = $ hash ;
51
48
}
52
49
53
50
$ cacheKey = sprintf ('odsl-%s ' , $ directory );
Original file line number Diff line number Diff line change @@ -135,7 +135,8 @@ function (): string {
135
135
136
136
private function export (string $ value ): string
137
137
{
138
- if (Strings::match ($ value , '([\000-\037]) ' ) !== null ) {
138
+ $ escapedValue = addcslashes ($ value , "\0.. \37" );
139
+ if ($ escapedValue !== $ value ) {
139
140
return '" ' . addcslashes ($ value , "\0.. \37\\\"" ) . '" ' ;
140
141
}
141
142
You can’t perform that action at this time.
0 commit comments