Skip to content

Commit

Permalink
added property typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 7, 2021
1 parent d19bacd commit 85b4aa0
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 149 deletions.
7 changes: 3 additions & 4 deletions examples/custom-control.php
Expand Up @@ -18,12 +18,11 @@

class DateInput extends Nette\Forms\Controls\BaseControl
{
/** @var string */
private $day = '';
private string $day = '';

private $month = '';
private string $month = '';

private $year = '';
private string $year = '';


public function __construct($label = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/FormsDI/FormsExtension.php
Expand Up @@ -21,7 +21,7 @@ public function __construct()
{
$this->config = new class {
/** @var string[] */
public $messages = [];
public array $messages = [];
};
}

Expand Down
11 changes: 4 additions & 7 deletions src/Forms/Container.php
Expand Up @@ -32,17 +32,14 @@ class Container extends Nette\ComponentModel\Container implements \ArrayAccess
*/
public $onValidate = [];

/** @var ControlGroup|null */
protected $currentGroup;
protected ?ControlGroup $currentGroup = null;

/** @var callable[] extension methods */
private static $extMethods = [];
private static array $extMethods = [];

/** @var bool */
private $validated;
private bool $validated = false;

/** @var ?string */
private $mappedType;
private ?string $mappedType = null;


/********************* data exchange ****************d*g**/
Expand Down
6 changes: 2 additions & 4 deletions src/Forms/ControlGroup.php
Expand Up @@ -19,11 +19,9 @@ class ControlGroup
{
use Nette\SmartObject;

/** @var \SplObjectStorage */
protected $controls;
protected \SplObjectStorage $controls;

/** @var array user options */
private $options = [];
private array $options = [];


public function __construct()
Expand Down
33 changes: 13 additions & 20 deletions src/Forms/Controls/BaseControl.php
Expand Up @@ -38,41 +38,34 @@
*/
abstract class BaseControl extends Nette\ComponentModel\Component implements Control
{
/** @var string */
public static $idMask = 'frm-%s';
public static string $idMask = 'frm-%s';

/** @var mixed current control value */
protected $value;
/** current control value */
protected mixed $value;

/** @var Html control element template */
protected $control;
/** control element template */
protected Html $control;

/** @var Html label element template */
protected $label;
/** label element template */
protected Html $label;

/** @var bool|bool[] */
protected $disabled = false;

/** @var callable[][] extension methods */
private static $extMethods = [];

/** @var string|object textual caption or label */
private $caption;
private string|object|null $caption;

/** @var array */
private $errors = [];
private array $errors = [];

/** @var bool|null */
private $omitted;
private ?bool $omitted = null;

/** @var Rules */
private $rules;
private Rules $rules;

/** @var Nette\Localization\Translator|bool|null */
private $translator = true; // means autodetect
private Nette\Localization\Translator|bool|null $translator = true; // means autodetect

/** @var array user options */
private $options = [];
private array $options = [];


/**
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Controls/Checkbox.php
Expand Up @@ -18,8 +18,8 @@
*/
class Checkbox extends BaseControl
{
/** @var Html wrapper element template */
private $container;
/** wrapper element template */
private Html $container;


/**
Expand Down
12 changes: 6 additions & 6 deletions src/Forms/Controls/CheckboxList.php
Expand Up @@ -22,14 +22,14 @@
*/
class CheckboxList extends MultiChoiceControl
{
/** @var Html separator element template */
protected $separator;
/** separator element template */
protected Html $separator;

/** @var Html container element template */
protected $container;
/** container element template */
protected Html $container;

/** @var Html item label template */
protected $itemLabel;
/** item label template */
protected Html $itemLabel;


/**
Expand Down
6 changes: 2 additions & 4 deletions src/Forms/Controls/ChoiceControl.php
Expand Up @@ -20,11 +20,9 @@
*/
abstract class ChoiceControl extends BaseControl
{
/** @var bool */
private $checkDefaultValue = true;
private bool $checkDefaultValue = true;

/** @var array */
private $items = [];
private array $items = [];


public function __construct($label = null, array $items = null)
Expand Down
3 changes: 1 addition & 2 deletions src/Forms/Controls/CsrfProtection.php
Expand Up @@ -20,8 +20,7 @@ class CsrfProtection extends HiddenField
{
public const PROTECTION = 'Nette\Forms\Controls\CsrfProtection::validateCsrf';

/** @var Nette\Http\Session|null */
public $session;
public ?Nette\Http\Session $session = null;


/**
Expand Down
7 changes: 3 additions & 4 deletions src/Forms/Controls/HiddenField.php
Expand Up @@ -17,18 +17,17 @@
*/
class HiddenField extends BaseControl
{
/** @var bool */
private $persistValue;
private bool $persistValue = false;

/** @var bool */
private $nullable = false;
private bool $nullable = false;


public function __construct($persistentValue = null)
{
parent::__construct();
$this->control->type = 'hidden';
$this->setOption('type', 'hidden');
$this->value = '';
if ($persistentValue !== null) {
$this->unmonitor(Nette\Forms\Form::class);
$this->persistValue = true;
Expand Down
6 changes: 2 additions & 4 deletions src/Forms/Controls/MultiChoiceControl.php
Expand Up @@ -20,11 +20,9 @@
*/
abstract class MultiChoiceControl extends BaseControl
{
/** @var bool */
private $checkDefaultValue = true;
private bool $checkDefaultValue = true;

/** @var array */
private $items = [];
private array $items = [];


public function __construct($label = null, array $items = null)
Expand Down
7 changes: 3 additions & 4 deletions src/Forms/Controls/MultiSelectBox.php
Expand Up @@ -17,11 +17,10 @@
*/
class MultiSelectBox extends MultiChoiceControl
{
/** @var array of option / optgroup */
private $options = [];
/** of option / optgroup */
private array $options = [];

/** @var array */
private $optionAttributes = [];
private array $optionAttributes = [];


public function __construct($label = null, array $items = null)
Expand Down
15 changes: 7 additions & 8 deletions src/Forms/Controls/RadioList.php
Expand Up @@ -22,17 +22,16 @@
*/
class RadioList extends ChoiceControl
{
/** @var bool */
public $generateId = false;
public bool $generateId = false;

/** @var Html separator element template */
protected $separator;
/** separator element template */
protected Html $separator;

/** @var Html container element template */
protected $container;
/** container element template */
protected Html $container;

/** @var Html item label template */
protected $itemLabel;
/** item label template */
protected Html $itemLabel;


/**
Expand Down
10 changes: 4 additions & 6 deletions src/Forms/Controls/SelectBox.php
Expand Up @@ -20,14 +20,12 @@ class SelectBox extends ChoiceControl
/** validation rule */
public const VALID = ':selectBoxValid';

/** @var array of option / optgroup */
private $options = [];
/** of option / optgroup */
private array $options = [];

/** @var string|object|false */
private $prompt = false;
private string|object|false $prompt = false;

/** @var array */
private $optionAttributes = [];
private array $optionAttributes = [];


public function __construct($label = null, array $items = null)
Expand Down
3 changes: 1 addition & 2 deletions src/Forms/Controls/SubmitButton.php
Expand Up @@ -28,8 +28,7 @@ class SubmitButton extends Button implements Nette\Forms\SubmitterControl
/** @var array<callable(self): void> Occurs when the button is clicked and form is not validated */
public $onInvalidClick = [];

/** @var array|null */
private $validationScope;
private ?array $validationScope = null;


/**
Expand Down
10 changes: 4 additions & 6 deletions src/Forms/Controls/TextBase.php
Expand Up @@ -19,14 +19,12 @@
*/
abstract class TextBase extends BaseControl
{
/** @var string */
protected $emptyValue = '';
protected string $emptyValue = '';

/** @var mixed unfiltered submitted value */
protected $rawValue = '';
/** unfiltered submitted value */
protected mixed $rawValue = '';

/** @var bool */
private $nullable;
private bool $nullable = false;


/**
Expand Down

0 comments on commit 85b4aa0

Please sign in to comment.