44
55use Contributte \FormWizard \Session \WizardSessionSection ;
66use Contributte \FormWizard \Steps \StepCounter ;
7+ use Closure ;
78use InvalidArgumentException ;
89use LogicException ;
910use Nette \Application \UI \Component ;
@@ -107,7 +108,7 @@ public function isSuccess(): bool
107108
108109 protected function getSection (): WizardSessionSection
109110 {
110- if (! $ this ->section ) {
111+ if ($ this ->section === null ) {
111112 $ section = $ this ->session ->getSection ('wizard ' . $ this ->getName ())
112113 ->setExpiration ($ this ->expiration );
113114
@@ -119,7 +120,8 @@ protected function getSection(): WizardSessionSection
119120
120121 public function getStepCounter (): StepCounter
121122 {
122- if (!$ this ->stepCounter ) {
123+ $ counter = 1 ;
124+ if ($ this ->stepCounter === null ) {
123125 for ($ counter = 1 ; $ counter < 1000 ; $ counter ++) {
124126 if (!method_exists ($ this , 'createStep ' . $ counter ) && !$ this ->getComponent ('step ' . $ counter , false )) {
125127 $ counter --;
@@ -182,7 +184,7 @@ public function getTotalSteps(): int
182184 }
183185
184186 /**
185- * @return mixed[] |ArrayHash<string|int, mixed>
187+ * @return array< mixed> |ArrayHash<mixed>
186188 */
187189 public function getValues (bool $ asArray = false )
188190 {
@@ -222,7 +224,7 @@ public function setStep(int $step): IWizard
222224
223225 protected function createForm (): Form
224226 {
225- return $ this ->factory ? $ this ->factory ->create () : new Form ();
227+ return $ this ->factory !== null ? $ this ->factory ->create () : new Form ();
226228 }
227229
228230 public function submitStep (SubmitButton $ button ): void
@@ -236,7 +238,7 @@ public function submitStep(SubmitButton $button): void
236238 $ submitName = $ button ->getName ();
237239 $ step = $ this ->extractStepFromName ($ form ->getName ());
238240
239- if (! $ step || $ step !== $ this ->getCurrentStep ()) {
241+ if ($ step === null || $ step !== $ this ->getCurrentStep ()) {
240242 return ;
241243 }
242244
@@ -299,7 +301,7 @@ public function create(?string $step = null): Form
299301 */
300302 protected function extractStepFromName ($ name ): ?int
301303 {
302- if ($ name === null || ! preg_match ('#^step(\d+)$# ' , $ name , $ matches )) {
304+ if ($ name === null || preg_match ('#^step(\d+)$# ' , $ name , $ matches ) === false ) {
303305 return null ;
304306 }
305307
@@ -326,11 +328,15 @@ public function addComponent(IComponent $component, ?string $name, ?string $inse
326328
327329 protected function createComponent (string $ name ): ?IComponent
328330 {
329- if (preg_match ('#^step\d+$# ' , $ name )) {
331+ if (preg_match ('#^step\d+$# ' , $ name ) > 0 ) {
330332 $ ucname = ucfirst ($ name );
331333 $ method = 'create ' . $ ucname ;
332334 if ($ ucname !== $ name && method_exists ($ this , $ method ) && (new ReflectionMethod ($ this , $ method ))->getName () === $ method ) {
333- $ component = $ this ->$ method ($ name );
335+ $ callable = [$ this , $ method ];
336+ assert (is_callable ($ callable ));
337+ $ callableMethod = Closure::fromCallable ($ callable );
338+ $ component = $ callableMethod ($ name );
339+
334340 if (!$ component instanceof IComponent && $ this ->getComponent ($ name ) === null ) {
335341 throw new UnexpectedValueException (
336342 sprintf ('Method %s::%s() did not return or create the desired component. ' , static ::class, $ method )
@@ -350,7 +356,7 @@ private function applyCallbacksToButtons(Forms\Form $form): void
350356 {
351357 /** @var SubmitButton $control */
352358 foreach ($ form ->getComponents (false , SubmitButton::class) as $ control ) {
353- if (!in_array ($ control ->getName (), [self ::FINISH_SUBMIT_NAME , self ::NEXT_SUBMIT_NAME , self ::PREV_SUBMIT_NAME ])) {
359+ if (!in_array ($ control ->getName (), [self ::FINISH_SUBMIT_NAME , self ::NEXT_SUBMIT_NAME , self ::PREV_SUBMIT_NAME ], true )) {
354360 continue ;
355361 }
356362
@@ -367,7 +373,7 @@ private function applyCallbacksToButtons(Forms\Form $form): void
367373 */
368374 public function getPresenter (): ?Presenter
369375 {
370- if (! $ this ->presenter ) {
376+ if ($ this ->presenter === null ) {
371377 $ this ->presenter = parent ::getPresenter ();
372378 }
373379
0 commit comments