Ban foreach(arrayWithStringKeys as k => v)

this is not as good as phpstan/phpstan-src#769 (e.g. array_key_first()/array_key_last() aren't covered by this, nor is array_rand()) but it does eliminate the most infuriating cases where this usually crops up.
This commit is contained in:
Dylan K. Taylor
2021-11-15 22:52:05 +00:00
parent f2d5455c5e
commit 269231c228
24 changed files with 150 additions and 33 deletions

View File

@ -425,7 +425,7 @@ class Config{
public function set($k, $v = true) : void{
$this->config[$k] = $v;
$this->changed = true;
foreach($this->nestedCache as $nestedKey => $nvalue){
foreach(Utils::stringifyKeys($this->nestedCache) as $nestedKey => $nvalue){
if(substr($nestedKey, 0, strlen($k) + 1) === ($k . ".")){
unset($this->nestedCache[$nestedKey]);
}
@ -487,7 +487,7 @@ class Config{
*/
private function fillDefaults(array $default, &$data) : int{
$changed = 0;
foreach($default as $k => $v){
foreach(Utils::stringifyKeys($default) as $k => $v){
if(is_array($v)){
if(!isset($data[$k]) or !is_array($data[$k])){
$data[$k] = [];
@ -536,7 +536,7 @@ class Config{
*/
public static function writeProperties(array $config) : string{
$content = "#Properties Config file\r\n#" . date("D M j H:i:s T Y") . "\r\n";
foreach($config as $k => $v){
foreach(Utils::stringifyKeys($config) as $k => $v){
if(is_bool($v)){
$v = $v ? "on" : "off";
}