Completed
Push — master ( 0ea243...da58d4 )
by Henry
10:25 queued 33s
created

includes/View/LoginForm.php (1 issue)

call_checks.maybe_mismatching_type_passed_with_def

Bug Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\View;
3
4
use Redaxscript\Html;
5
use Redaxscript\Model;
6
use Redaxscript\Module;
7
8
/**
9
 * children class to create the login form
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category View
15
 * @author Henry Ruhs
16
 */
17
18
class LoginForm extends ViewAbstract
19
{
20
	/**
21
	 * render the view
22
	 *
23
	 * @since 3.0.0
24
	 *
25
	 * @return string
26
	 */
27
28 1
	public function render() : string
29
	{
30 1
		$output = Module\Hook::trigger('loginFormStart');
31 1
		$outputLegend = null;
32 1
		$settingModel = new Model\Setting();
33 1
		$parameterRoute = $this->_registry->get('parameterRoute');
34
35
		/* html element */
36
37 1
		$element = new Html\Element();
38
		$titleElement = $element
39 1
			->copy()
40 1
			->init('h2',
41
			[
42 1
				'class' => 'rs-title-content'
43
			])
44 1
			->text($this->_language->get('login'));
45 1
		if ($settingModel->get('recovery'))
46
		{
47
			$linkElement = $element
48 1
				->copy()
49 1
				->init('a',
50
				[
51 1
					'href' => $parameterRoute . 'login/recover'
52
				]);
53 1
			$outputLegend = $linkElement->text($this->_language->get('recovery_question') . $this->_language->get('question_mark'));
54
		}
55 1
		$formElement = new Html\Form($this->_registry, $this->_language);
56 1
		$formElement->init(
57
		[
58 1
			'form' =>
59
			[
60
				'class' => 'rs-js-validate rs-form-default rs-form-login'
61
			],
62
			'button' =>
63
			[
64
				'submit' =>
65
				[
66
					'name' => self::class
67
				]
68
			]
69
		],
70
		[
71 1
			'captcha' => $settingModel->get('captcha')
72
		]);
73
74
		/* create the form */
75
76
		$formElement
77 1
			->legend($outputLegend)
0 ignored issues
show
It seems like $outputLegend defined by $linkElement->text($this...->get('question_mark')) on line 53 can also be of type object<Redaxscript\Html\Element>; however, Redaxscript\Html\Form::legend() does only seem to accept null|string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
78 1
			->append('<ul><li>')
79 1
			->label('* ' . $this->_language->get('user'),
80
			[
81 1
				'for' => 'user'
82
			])
83 1
			->text(
84
			[
85 1
				'autofocus' => 'autofocus',
86
				'id' => 'user',
87
				'name' => 'user',
88
				'pattern' => '[a-zA-Z0-9]{1,30}',
89
				'required' => 'required'
90
			])
91 1
			->append('</li><li>')
92 1
			->label('* ' . $this->_language->get('password'),
93
			[
94 1
				'for' => 'password'
95
			])
96 1
			->password(
97
			[
98 1
				'id' => 'password',
99
				'name' => 'password',
100
				'pattern' => '[a-zA-Z0-9]{1,30}',
101
				'required' => 'required'
102
			])
103 1
			->append('</li>');
104 1
		if ($settingModel->get('captcha') > 0)
105
		{
106
			$formElement
107 1
				->append('<li>')
108 1
				->captcha('task')
109 1
				->append('</li>');
110
		}
111 1
		$formElement->append('</ul>');
112 1
		if ($settingModel->get('captcha') > 0)
113
		{
114 1
			$formElement->captcha('solution');
115
		}
116
		$formElement
117 1
			->token()
118 1
			->submit();
119
120
		/* collect output */
121
122 1
		$output .= $titleElement . $formElement;
123 1
		$output .= Module\Hook::trigger('loginFormEnd');
124 1
		return $output;
125
	}
126
}
127