Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -27,7 +27,6 @@ use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\MessageBag;
use Throwable;
/**
* Trait FormSupport
@@ -35,12 +34,7 @@ use Throwable;
trait FormSupport
{
/**
* @param string $name
* @param array|null $list
* @param mixed $selected
* @param array|null $options
*
* @return string
* @param mixed $selected
*/
public function select(string $name, array $list = null, $selected = null, array $options = null): string
{
@@ -50,9 +44,10 @@ trait FormSupport
$classes = $this->getHolderClasses($name);
$selected = $this->fillFieldValue($name, $selected);
unset($options['autocomplete'], $options['placeholder']);
try {
$html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
$html = 'Could not render select.';
}
@@ -60,12 +55,6 @@ trait FormSupport
return $html;
}
/**
* @param string $name
* @param array|null $options
*
* @return string
*/
protected function label(string $name, array $options = null): string
{
$options ??= [];
@@ -74,37 +63,28 @@ trait FormSupport
}
$name = str_replace('[]', '', $name);
return (string)trans('form.' . $name);
return (string)trans('form.'.$name);
}
/**
* @param string $name
* @param mixed $label
* @param array|null $options
*
* @return array
* @param mixed $label
*/
protected function expandOptionArray(string $name, $label, array $options = null): array
{
$options ??= [];
$name = str_replace('[]', '', $name);
$options['class'] = 'form-control';
$options['id'] = 'ffInput_' . $name;
$options['id'] = 'ffInput_'.$name;
$options['autocomplete'] = 'off';
$options['placeholder'] = ucfirst($label);
return $options;
}
/**
* @param string $name
*
* @return string
*/
protected function getHolderClasses(string $name): string
{
// Get errors from session:
/** @var MessageBag|null $errors */
/** @var null|MessageBag $errors */
$errors = session('errors');
$classes = 'form-group';
@@ -116,8 +96,7 @@ trait FormSupport
}
/**
* @param string $name
* @param mixed|null $value
* @param null|mixed $value
*
* @return mixed
*/
@@ -139,21 +118,16 @@ trait FormSupport
return $value;
}
/**
* @return AccountRepositoryInterface
*/
protected function getAccountRepository(): AccountRepositoryInterface
{
return app(AccountRepositoryInterface::class);
}
/**
* @return Carbon
*/
protected function getDate(): Carbon
{
/** @var Carbon $date */
$date = null;
try {
$date = today(config('app.timezone'));
} catch (InvalidDateException $e) { // @phpstan-ignore-line