Skip to content

Commit dbc45c0

Browse files
committed
[skip ci] Add strict and nullable type hints to form classes
Updated method signatures in form-related classes and traits to use strict and nullable type hints for parameters and return types. This improves type safety and code clarity, aligning with modern PHP standards.
1 parent 1258777 commit dbc45c0

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

Ajax/semantic/html/collections/form/HtmlForm.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ public function addField($field) {
145145
*
146146
* @param string $identifier
147147
* @param string $content
148-
* @param string $header
149-
* @param string $icon
150-
* @param string $type
148+
* @param string|null $header
149+
* @param string|null $icon
150+
* @param string|null $type
151151
* @return HtmlMessage
152152
*/
153-
public function addMessage($identifier, $content, $header=NULL, $icon=NULL, $type=NULL) {
153+
public function addMessage(string $identifier, string $content, ?string $header=NULL, ?string $icon=NULL, ?string $type=NULL): HtmlFormField|HtmlMessage {
154154
$message=new HtmlMessage($identifier, $content);
155155
if (isset($header))
156156
$message->addHeader($header);

Ajax/semantic/html/collections/form/HtmlFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HtmlFormField extends HtmlSemDoubleElement {
1919

2020
protected $_validation;
2121

22-
public function __construct($identifier, $field, $label = NULL) {
22+
public function __construct($identifier, $field, ?string $label = NULL) {
2323
parent::__construct($identifier, "div", "field");
2424
$this->content = array();
2525
$this->_states = [

Ajax/semantic/html/collections/form/HtmlFormFields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getItem($index){
6969
return parent::getItem($index);
7070
}
7171

72-
public function compile(JsUtils $js=NULL, &$view=NULL) {
72+
public function compile(?JsUtils $js=NULL, mixed &$view=NULL) {
7373
if ($this->_equalWidth) {
7474
$count=$this->count();
7575
$this->addToProperty("class", Wide::getConstants()["W".$count]." fields");

Ajax/semantic/html/collections/form/traits/FormTrait.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function addExtraCompoValidation(Form $compo,FieldValidation $validati
3535
$compo->addFieldValidation($validation);
3636
}
3737

38-
protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){
38+
protected function _runValidationParams(Form &$compo, ?JsUtils $js=NULL){
3939
$form=$this->getForm();
4040
$params=$form->getValidationParams();
4141
if(isset($params["_ajaxSubmit"])){
@@ -48,7 +48,7 @@ protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){
4848
$form->addEventsOnRun($js);
4949
}
5050

51-
protected function _compileAjaxSubmit($ajaxSubmit,JsUtils $js=null){
51+
protected function _compileAjaxSubmit($ajaxSubmit, ?JsUtils $js=null){
5252
$compilation="";
5353
if(\is_array($ajaxSubmit)){
5454
foreach ($ajaxSubmit as $ajaxSubmitItem){
@@ -90,10 +90,10 @@ public function jsState($state) {
9090
* @param string|BaseHtml $identifierOrElement
9191
* @param string $url
9292
* @param string $responseElement
93-
* @param array $parameters
93+
* @param array|null $parameters
9494
* @return HtmlForm
9595
*/
96-
public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){
96+
public function submitOn(string $event, BaseHtml|string $identifierOrElement, string $url, string $responseElement, ?array $parameters=NULL): HtmlForm {
9797
$form=$this->getForm();
9898
if($identifierOrElement instanceof BaseHtml)
9999
$elem=$identifierOrElement;
@@ -105,11 +105,11 @@ public function submitOn($event,$identifierOrElement,$url,$responseElement,$para
105105
return $form;
106106
}
107107

108-
public function submitOnClick($identifier,$url,$responseElement,$parameters=NULL){
108+
public function submitOnClick(string $identifier,string $url,string $responseElement,?array $parameters=NULL){
109109
return $this->submitOn("click", $identifier, $url, $responseElement,$parameters);
110110
}
111111

112-
public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){
112+
public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,?array $parameters=NULL){
113113
$bt=$this->getForm()->addButton($identifier, $value,$cssStyle);
114114
return $this->_buttonAsSubmit($bt, "click",$url,$responseElement,$parameters);
115115
}
@@ -133,7 +133,7 @@ public function setSubmitParams($url,$responseElement=NULL,$parameters=NULL){
133133
return $this;
134134
}
135135

136-
public function addReset($identifier,$value,$cssStyle=NULL){
136+
public function addReset(string $identifier,string $value,?string $cssStyle=NULL){
137137
$bt=$this->getForm()->addButton($identifier, $value,$cssStyle);
138138
$bt->setProperty("type", "reset");
139139
return $bt;
@@ -144,7 +144,7 @@ public function addReset($identifier,$value,$cssStyle=NULL){
144144
* @param string $jsCode
145145
* @return \Ajax\semantic\html\collections\form\HtmlForm
146146
*/
147-
public function onValid($jsCode){
147+
public function onValid(string $jsCode){
148148
$form=$this->getForm();
149149
$form->addValidationParam("onValid", "%function(){".$jsCode."}%");
150150
return $form;
@@ -155,7 +155,7 @@ public function onValid($jsCode){
155155
* @param string $jsCode can use event and fields parameters
156156
* @return HtmlForm
157157
*/
158-
public function onSuccess($jsCode){
158+
public function onSuccess(string $jsCode): HtmlForm {
159159
$form=$this->getForm();
160160
$form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%");
161161
return $form;
@@ -169,13 +169,13 @@ public function addExtraFieldRules($fieldname,$rules){
169169
}
170170
}
171171

172-
public function addExtraFieldRule($fieldname,$type,$prompt=NULL,$value=NULL){
172+
public function addExtraFieldRule(string $fieldname,string $type,$prompt=NULL,$value=NULL){
173173
$form=$this->getForm();
174174
$fv=$form->getExtraFieldValidation($fieldname);
175175
$fv->addRule($type,$prompt,$value);
176176
}
177177

178-
public function setOptional($fieldname,$optional=true){
178+
public function setOptional(string $fieldname,bool $optional=true){
179179
$form=$this->getForm();
180180
$fv=$form->getExtraFieldValidation($fieldname);
181181
$fv->setOptional($optional);

Ajax/semantic/html/content/HtmlAbsractItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function asLink($href=NULL,$part=NULL){
9999
*
100100
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
101101
*/
102-
public function compile(JsUtils $js=NULL, &$view=NULL) {
102+
public function compile(?JsUtils $js=NULL, mixed &$view=NULL) {
103103
if(\is_array($this->content) && JArray::isAssociative($this->content))
104104
$this->content=JArray::sortAssociative($this->content, [ "right-content","icon","image","content" ]);
105105
return parent::compile($js, $view);

Ajax/semantic/html/elements/HtmlStep.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function defineActiveStep(){
7373
return $this;
7474
}
7575

76-
public function compile(JsUtils $js=NULL, &$view=NULL) {
76+
public function compile(?JsUtils $js=NULL, mixed &$view=NULL) {
7777
if(isset($this->_activeStep) && \is_numeric($this->_activeStep))
7878
$this->defineActiveStep();
7979
return parent::compile($js,$view);
@@ -84,7 +84,7 @@ public function setActiveStep($_activeStep) {
8484
return $this;
8585
}
8686

87-
public function setAttached($side="",HtmlDoubleElement $toElement=NULL){
87+
public function setAttached($side="",?HtmlDoubleElement $toElement=NULL){
8888
if(isset($toElement)){
8989
$toElement->addToPropertyCtrl("class", "attached",array("attached"));
9090
}

0 commit comments

Comments
 (0)