Skip to content

Commit

Permalink
Abstract DisableOptions methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Piagrammist committed Sep 30, 2024
1 parent 2e0d27f commit cdcfef9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Ini/EntryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
34 changes: 18 additions & 16 deletions src/Options/DisableOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit cdcfef9

Please sign in to comment.