Skip to content

Commit 071c938

Browse files
authored
Merge pull request #139 from Kharhamel/readdir
remove readdir() from safe since the doc is false
2 parents 025069d + 14a14ae commit 071c938

File tree

7 files changed

+21
-31
lines changed

7 files changed

+21
-31
lines changed

generated/dir.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,34 +97,6 @@ function opendir(string $path, $context = null)
9797
}
9898

9999

100-
/**
101-
* Returns the name of the next entry in the directory. The
102-
* entries are returned in the order in which they are stored by
103-
* the filesystem.
104-
*
105-
* @param resource $dir_handle The directory handle resource previously opened
106-
* with opendir. If the directory handle is
107-
* not specified, the last link opened by opendir
108-
* is assumed.
109-
* @return string Returns the entry name on success.
110-
* @throws DirException
111-
*
112-
*/
113-
function readdir($dir_handle = null): string
114-
{
115-
error_clear_last();
116-
if ($dir_handle !== null) {
117-
$result = \readdir($dir_handle);
118-
} else {
119-
$result = \readdir();
120-
}
121-
if ($result === false) {
122-
throw DirException::createFromPhpError();
123-
}
124-
return $result;
125-
}
126-
127-
128100
/**
129101
* Resets the directory stream indicated by
130102
* dir_handle to the beginning of the

generated/functionsList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
'chroot',
8686
'getcwd',
8787
'opendir',
88-
'readdir',
8988
'rewinddir',
9089
'scandir',
9190
'eio_busy',

generator/config/ignoredFunctions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
'array_search',
1515
'forward_static_call',
1616
'forward_static_call_array',
17+
'readdir', //the documentation is false: the function return false at the end of the iteration
1718
];

generator/config/specialCasesFunctions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
'apcu_fetch',
1010
'preg_replace',
1111
'openssl_encrypt',
12+
'readdir',
1213
];

generator/src/FileCreator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ private function getFunctionsNameList(array $functions): array
8686
return $function->getFunctionName();
8787
}, $functions);
8888
$specialCases = require __DIR__.'/../config/specialCasesFunctions.php';
89-
return array_merge($functionNames, $specialCases);
89+
$functionNames = array_merge($functionNames, $specialCases);
90+
$excludeCases = require __DIR__.'/../config/ignoredFunctions.php';
91+
return array_diff($functionNames, $excludeCases);
9092
}
9193

9294

lib/special_cases.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ function preg_replace($pattern, $replacement, $subject, int $limit = -1, int &$c
161161
return $result;
162162
}
163163

164+
/**
165+
* @param resource|null $dir_handle
166+
* @return string|false
167+
* @deprecated
168+
* This function is only in safe because the php documentation is wrong
169+
*/
170+
function readdir($dir_handle = null)
171+
{
172+
if ($dir_handle !== null) {
173+
$result = \readdir($dir_handle);
174+
} else {
175+
$result = \readdir();
176+
}
177+
return $result;
178+
}
179+
164180
/**
165181
* Encrypts given data with given method and key, returns a raw
166182
* or base64 encoded string

rector-migrate.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ services:
8888
chroot: 'Safe\chroot'
8989
getcwd: 'Safe\getcwd'
9090
opendir: 'Safe\opendir'
91-
readdir: 'Safe\readdir'
9291
rewinddir: 'Safe\rewinddir'
9392
scandir: 'Safe\scandir'
9493
eio_busy: 'Safe\eio_busy'

0 commit comments

Comments
 (0)