Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Feb 5, 2025
1 parent c1513a3 commit 8f75187
Show file tree
Hide file tree
Showing 31 changed files with 1,464 additions and 752 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}
},
"require": {
"php": ">=8.0"
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
Expand Down
1,844 changes: 1,192 additions & 652 deletions composer.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/CustomForm/CachedGenerator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace CustomForm;

use Generator;
Expand All @@ -9,19 +11,18 @@ class CachedGenerator implements IteratorAggregate
{
protected array $cache = [];

public function __construct(protected $generator = null)
{
}
public function __construct(protected $generator = null) {}

public function getIterator(): Generator
{
foreach ($this->cache as $item)
foreach ($this->cache as $item) {
yield $item;
}

while ($this->generator->valid())
{
while ($this->generator->valid()) {
$this->cache[] = $current = $this->generator->current();
$this->generator->next();

yield $current;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/CustomForm/CustomForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function ListForms(): void

loadLanguage('CustomForm');
loadTemplate('CustomForm');
loadCSSFile('customform.css', array('minimize' => true));
loadCSSFile('customform.css', ['minimize' => true]);

$request = $this->smcFunc['db_query']('', '
SELECT id_form, title
Expand Down Expand Up @@ -306,7 +306,7 @@ private function prepareContext(array $post_errors, array $form_data, array $fie

loadTemplate('CustomFormUserland', null, false);
loadTemplate('CustomForm');
loadCSSFile('customform.css', array('minimize' => true));
loadCSSFile('customform.css', ['minimize' => true]);
$template_function = 'template_' . $form_data['template_function'];
$template = function_exists($template_function)
? $form_data['template_function']
Expand Down
2 changes: 1 addition & 1 deletion src/CustomForm/FieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public function getValue(): string;
public function validate(): bool;

public function isRequired(): bool;
}
}
5 changes: 3 additions & 2 deletions src/CustomForm/Fields/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public function setHtml(): void

public function validate(): bool
{
if (!$this->exists && $this->required)
if (!$this->exists && $this->required) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

return $this->err == [];
}
Expand All @@ -47,4 +48,4 @@ public function getValue(): string
{
return (!$this->exists && $this->default) || $this->value ? 'yes' : 'no';
}
}
}
2 changes: 1 addition & 1 deletion src/CustomForm/Fields/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public function getValue(): string
{
return $this->value;
}
}
}
5 changes: 3 additions & 2 deletions src/CustomForm/Fields/Masks/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class Email implements MaskInterface

public function validate(): bool
{
if (!preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $this->value))
if (!preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $this->value)) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

return $this->err == false;
}
}
}
5 changes: 3 additions & 2 deletions src/CustomForm/Fields/Masks/Floating.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class Floating implements MaskInterface

public function validate(): bool
{
if (!preg_match('/^\s*([0-9]+(\.[0-9]+)?)\s*$/', $this->value))
if (!preg_match('/^\s*([0-9]+(\.[0-9]+)?)\s*$/', $this->value)) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

return $this->err == false;
}
}
}
5 changes: 3 additions & 2 deletions src/CustomForm/Fields/Masks/Nohtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class Nohtml implements MaskInterface

public function validate(): bool
{
if (strip_tags($this->value) != $this->value)
if (strip_tags($this->value) != $this->value) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

return $this->err == false;
}
}
}
5 changes: 3 additions & 2 deletions src/CustomForm/Fields/Masks/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class Number implements MaskInterface

public function validate(): bool
{
if (!preg_match('/^\s*([0-9]+)\s*$/', $this->value))
if (!preg_match('/^\s*([0-9]+)\s*$/', $this->value)) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

return $this->err == false;
}
}
}
10 changes: 6 additions & 4 deletions src/CustomForm/Fields/Masks/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ class Regex implements MaskInterface

public function validate(): bool
{
if (!preg_match($this->field['regex'], $this->value))
if (!empty($this->field['err']))
if (!preg_match($this->field['regex'], $this->value)) {
if (!empty($this->field['err'])) {
$this->err = $this->field['err'];
else
} else {
$this->err = ['customform_invalid_value', $this->field['text']];
}
}

return $this->err == false;
}
}
}
10 changes: 5 additions & 5 deletions src/CustomForm/Fields/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ public function setHtml(): void
{
$this->input_html = '<fieldset>';

foreach ($this->type_vars as $v)
{
foreach ($this->type_vars as $v) {
$this->input_html .= sprintf(
'<label><input type="radio" name="%s[%d]" value="%4$s"%s> %s</label><br>',
'CustomFormField',
$this->field['id_field'],
(!$this->exists && $this->default == $v) || $this->value == $v
? ' checked="checked"'
: '',
$v
$v,
);

if ((!$this->exists && $this->default == $v) || $this->value == $v)
if ((!$this->exists && $this->default == $v) || $this->value == $v) {
$this->output_html = $v;
}
}

$this->input_html .= '</fieldset>';
}
}
}
13 changes: 7 additions & 6 deletions src/CustomForm/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ public function setHtml(): void
$this->field['id_field']
);

foreach ($this->type_vars as $v)
{
foreach ($this->type_vars as $v) {
$this->input_html .= sprintf(
'<option%s> %s</option>',
(!$this->exists && $this->default == $v) || $this->value == $v
? ' checked="checked"'
: '',
$v
$v,
);

if ((!$this->exists && $this->default == $v) || $this->value == $v)
if ((!$this->exists && $this->default == $v) || $this->value == $v) {
$this->output_html = $v;
}
}

$this->input_html .= '</select>';
Expand All @@ -48,8 +48,9 @@ public function validate(): bool
{
$found = isset(array_flip($this->type_vars)[$this->value]) || !empty($this->default);

if (!$found && $this->required)
if (!$found && $this->required) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

return $this->err == [];
}
Expand All @@ -60,4 +61,4 @@ public function getValue(): string
? $this->value
: $this->default;
}
}
}
12 changes: 7 additions & 5 deletions src/CustomForm/Fields/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ public function setHtml(): void
'<input type="text" name="%s[%d]" value="%s">',
'CustomFormField',
$this->field['id_field'],
$this->value
$this->value,
);
}

public function getValue(): string
{
global $smcFunc;

if (!empty($this->size))
if (!empty($this->size)) {
$this->value = $smcFunc['substr']($this->value, 0, $this->size);
}

//if (!in_array('parse_bbc', $this->type_vars))
// $this->value = '[nobbc]' . $this->value . '[/nobbc]';
Expand All @@ -45,12 +46,13 @@ public function getValue(): string

public function validate(): bool
{
if (!$this->exists && $this->required)
if (!$this->exists && $this->required) {
$this->err = ['customform_invalid_value', $this->field['text']];
}

//~ $class_name = 'CustomFormFieldMask_' . $this->field['mask'];
//~ if (!class_exists($class_name))
//~ fatal_error('Mask "' . $this->field['mask'] . '" not found for field "' . $this->field['name'] . '" at ID #' . $this->field['id_field'] . '.', false);
//~ fatal_error('Mask "' . $this->field['mask'] . '" not found for field "' . $this->field['name'] . '" at ID #' . $this->field['id'] . '.', false);

//~ $mask = new $class_name($this->value, $this->field);
//~ $mask->validate(): bool;
Expand All @@ -59,4 +61,4 @@ public function validate(): bool

return $this->err == [];
}
}
}
4 changes: 2 additions & 2 deletions src/CustomForm/Fields/Textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setHtml(): void
$this->field['id_field'],
!empty($rows) ? 'rows="' . $rows . '"' : '',
!empty($cols) ? 'cols="' . $cols . '"' : '',
$this->value
$this->value,
);
}
}
}
Loading

0 comments on commit 8f75187

Please sign in to comment.