for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Enjoys\Forms\Traits;
trait Options
{
/**
*
* @var array<string, mixed>
*/
protected array $options = [];
public function setOption(string $key, mixed $value, bool $useInternalMethods = true): static
$method = 'set' . ucfirst($key);
if ($useInternalMethods === true && method_exists($this, $method)) {
$this->$method($value);
return $this;
}
$this->options[$key] = $value;
public function getOption(string $key, mixed $defaults = null, bool $useInternalMethods = true): mixed
$method = 'get' . ucfirst($key);
return $this->$method($defaults);
if (isset($this->options[$key])) {
return $this->options[$key];
return $defaults;
* @param array<string, mixed> $options
* @psalm-suppress MixedAssignment
public function setOptions(array $options = [], bool $useInternalMethods = true): static
foreach ($options as $key => $value) {
$this->setOption($key, $value, $useInternalMethods);
* @return array<string, mixed>
public function getOptions(): array
return $this->options;