Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNN1 committed Aug 17, 2023
1 parent 1ecb3ce commit 87d964d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ public function addComponent(string $name, string $class): void {
public function addSuggestions(string $component_name): string {
$alternatives = [];

foreach ($this->allComponents() as $name => $class) {
foreach (array_keys($this->allComponents()) as $name) {
$lev = levenshtein($component_name, $name);
if ($lev <= strlen($component_name) / 3 || str_contains($name, $component_name)) {
$alternatives[$name] = $lev;
}
}

if (count($alternatives) === 0) {
if ($alternatives === []) {
return '';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Form/Checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function render(string $name, string $label = '', int|string $value = 0,
$this->options['checkbox_id'] = $this->options['checkbox_id'] !== '' ? $this->options['checkbox_id'] : $name;

if ($name !== '') {
$name .= $this->options['radio'] === false && !str_ends_with($name, '[]') && count((array) $this->options['items']) > 0 ? '[]' : '';
$name .= $this->options['radio'] === false && !str_ends_with($name, '[]') && (array) $this->options['items'] !== [] ? '[]' : '';
$this->options['checkbox_attributes']['name'] = $name;
}

Expand All @@ -61,7 +61,7 @@ public function render(string $name, string $label = '', int|string $value = 0,
$this->options['checkbox_attributes']['disabled'] = null;
}

if (count((array) $this->options['items']) === 0) {
if ((array) $this->options['items'] === []) {
$value = $value === '' ? 0 : $value;
$this->options['items'] = [
$value => $label,
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function render(string $id, array $content, array $options = []): Compone

$fwoptions = $this->uikit->getFrameworkOption('modal.button');

if (count((array) $this->options['button']) > 0) {
if ((array) $this->options['button'] !== []) {
if (isset($fwoptions['attributes'])) {
foreach ($fwoptions['attributes'] as $attr => $value) {
$fwoptions['attributes'][$attr] = strtr($value, ['{id}' => $id]);
Expand Down
10 changes: 4 additions & 6 deletions src/Twig/TwigUiKitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getFunctions(): array {

$is_safe = ['is_safe' => ['html']];

foreach ($this->uikit->allComponents() as $name => $class) {
foreach (array_keys($this->uikit->allComponents()) as $name) {
if (is_callable([$this->uikit, $name])) {
$functions[] = new TwigFunction($name, fn (...$arguments) => $this->uikit->$name(...$arguments), $is_safe);
}
Expand All @@ -44,11 +44,9 @@ public function getFunctions(): array {

$tpl_func = (array) $this->uikit->getFrameworkOption('tpl_funcs');

if (count($tpl_func) > 0) {
foreach ($tpl_func as $function_name => $callback) {
if (is_callable($callback)) {
$functions[] = new TwigFunction($function_name, $callback, $is_safe);
}
foreach ($tpl_func as $function_name => $callback) {
if (is_callable($callback)) {
$functions[] = new TwigFunction($function_name, $callback, $is_safe);
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/UiKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ public static function getInstance(Config|array $config = []): UiKit {
public function getFrameworkOption(string $key): mixed {
$config = (array) require realpath($this->config->getFrameworkPath($this->config->getFramework())).'/config.php';

if (count($this->fw_options)) {
foreach ($this->fw_options as $option => $value) {
Misc::arraySet($config, $option, $value);
}
foreach ($this->fw_options as $option => $value) {
Misc::arraySet($config, $option, $value);
}

return Misc::arrayGet($config, $key);
Expand All @@ -122,12 +120,10 @@ public function checkFramework(array|string|null $framework = null): bool {
}

if (is_array($framework)) {
$fw = in_array($this->config->getFramework(), $framework, true);
} else {
$fw = $this->config->getFramework() === $framework;
return in_array($this->config->getFramework(), $framework, true);
}

return $fw;
return $this->config->getFramework() === $framework;
}

/**
Expand Down

0 comments on commit 87d964d

Please sign in to comment.