diff --git a/src/Ini/EntryManager.php b/src/Ini/EntryManager.php index 3d65352..4110aa1 100644 --- a/src/Ini/EntryManager.php +++ b/src/Ini/EntryManager.php @@ -34,7 +34,7 @@ protected function setEntry( mixed $value = null, EntryState $state = EntryState::UNCOMMENT, ValueFormat $format = ValueFormat::NONE, - ): self { + ): static { if ($value !== null) { $prop->setValue($value, $format); } diff --git a/src/Options/DisableOptions.php b/src/Options/DisableOptions.php index b9cb9e4..013aabd 100644 --- a/src/Options/DisableOptions.php +++ b/src/Options/DisableOptions.php @@ -30,33 +30,35 @@ public function setFunctions( ?array $value = null, EntryState $state = EntryState::UNCOMMENT, ): self { - $value = \array_unique(\array_filter($value)); - if ($this->strict) { - foreach ($value as $i => $fn) { - if (!\function_exists($fn)) { - Logger::warning(Lang::get('err_id_resolve', 'Function', $fn)); - unset($value[$i]); - } - } - } - - return $this->setEntry($this->functions, $value, $state, ValueFormat::ARR_CSV); + return $this->setAbstract(true, $value, $state); } public function setClasses( ?array $value = null, EntryState $state = EntryState::UNCOMMENT, ): self { + return $this->setAbstract(false, $value, $state); + } + + private function setAbstract(bool $isFn, ?array $value, EntryState $state): self + { + $prop = $isFn ? $this->functions : $this->classes; + if (empty($value)) { + $prop->setState($state); + return $this; + } + $value = \array_unique(\array_filter($value)); if ($this->strict) { - foreach ($value as $i => $class) { - if (!\class_exists($class)) { - Logger::warning(Lang::get('err_id_resolve', 'Class', $class)); + $mode = $isFn ? 'Function' : 'Class'; + $validator = $isFn ? \function_exists(...) : \class_exists(...); + foreach ($value as $i => $name) { + if (!$validator($name)) { + Logger::warning(Lang::get('err_id_resolve', $mode, $name)); unset($value[$i]); } } } - - return $this->setEntry($this->classes, $value, $state, ValueFormat::ARR_CSV); + return $this->setEntry($prop, $value, $state, ValueFormat::ARR_CSV); } }