Skip to content

Commit e6a17f3

Browse files
committed
[WIP] Start fixing implicit nullable parameters
These divide into a few cases: * The method is a combined getter/setter, and takes NULL (or no args) to trigger the getter behaviour. * The optional parameter is the last one and should only logically take an array. I have tightened the type and default to an empty array instead of null. * The optional parameter is before others : here a user might be calling with null because they need to specify later params. In these cases I have relaxed the typehint to take null|array (or whatever) as now to avoid having to change the calling code. There may be other instances of this in classes that are not loaded during the phpunit run.
1 parent a4ce81f commit e6a17f3

File tree

17 files changed

+53
-58
lines changed

17 files changed

+53
-58
lines changed

classes/Kohana/Core.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Kohana_Core {
183183
* @uses Kohana::cache
184184
* @uses Profiler
185185
*/
186-
public static function init(array $settings = NULL)
186+
public static function init(array $settings = [])
187187
{
188188
if (Kohana::$_init)
189189
{
@@ -578,10 +578,10 @@ public static function auto_load_lowercase($class, $directory = 'classes')
578578
*
579579
* Kohana::modules(array('modules/foo', MODPATH.'bar'));
580580
*
581-
* @param array $modules list of module paths
581+
* @param ?array $modules list of module paths, null to return the current value
582582
* @return array enabled modules
583583
*/
584-
public static function modules(array $modules = NULL)
584+
public static function modules(?array $modules = NULL)
585585
{
586586
if ($modules === NULL)
587587
{
@@ -767,10 +767,10 @@ public static function find_file($dir, $file, $ext = NULL, $array = FALSE)
767767
* $views = Kohana::list_files('views');
768768
*
769769
* @param string $directory directory name
770-
* @param array $paths list of paths to search
770+
* @param ?array $paths list of paths to search, null to use defaults
771771
* @return array
772772
*/
773-
public static function list_files($directory = NULL, array $paths = NULL)
773+
public static function list_files($directory = NULL, ?array $paths = NULL)
774774
{
775775
if ($directory !== NULL)
776776
{

classes/Kohana/Debug.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public static function source($file, $line_number, $padding = 5)
344344
* @param array $trace
345345
* @return string
346346
*/
347-
public static function trace(array $trace = NULL)
347+
public static function trace(?array $trace = NULL)
348348
{
349349
if ($trace === NULL)
350350
{

classes/Kohana/Form.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Kohana_Form {
3232
* @uses URL::site
3333
* @uses HTML::attributes
3434
*/
35-
public static function open($action = NULL, array $attributes = NULL)
35+
public static function open($action = NULL, array $attributes = [])
3636
{
3737
if ($action instanceof Request)
3838
{
@@ -90,7 +90,7 @@ public static function close()
9090
* @return string
9191
* @uses HTML::attributes
9292
*/
93-
public static function input($name, $value = NULL, array $attributes = NULL)
93+
public static function input($name, $value = NULL, ?array $attributes = [])
9494
{
9595
// Set the input name
9696
$attributes['name'] = $name;
@@ -118,7 +118,7 @@ public static function input($name, $value = NULL, array $attributes = NULL)
118118
* @return string
119119
* @uses Form::input
120120
*/
121-
public static function hidden($name, $value = NULL, array $attributes = NULL)
121+
public static function hidden($name, $value = NULL, array $attributes = [])
122122
{
123123
$attributes['type'] = 'hidden';
124124

@@ -136,7 +136,7 @@ public static function hidden($name, $value = NULL, array $attributes = NULL)
136136
* @return string
137137
* @uses Form::input
138138
*/
139-
public static function password($name, $value = NULL, array $attributes = NULL)
139+
public static function password($name, $value = NULL, array $attributes = [])
140140
{
141141
$attributes['type'] = 'password';
142142

@@ -153,7 +153,7 @@ public static function password($name, $value = NULL, array $attributes = NULL)
153153
* @return string
154154
* @uses Form::input
155155
*/
156-
public static function file($name, array $attributes = NULL)
156+
public static function file($name, array $attributes = [])
157157
{
158158
$attributes['type'] = 'file';
159159

@@ -172,7 +172,7 @@ public static function file($name, array $attributes = NULL)
172172
* @return string
173173
* @uses Form::input
174174
*/
175-
public static function checkbox($name, $value = NULL, $checked = FALSE, array $attributes = NULL)
175+
public static function checkbox($name, $value = NULL, $checked = FALSE, array $attributes = [])
176176
{
177177
$attributes['type'] = 'checkbox';
178178

@@ -198,7 +198,7 @@ public static function checkbox($name, $value = NULL, $checked = FALSE, array $a
198198
* @return string
199199
* @uses Form::input
200200
*/
201-
public static function radio($name, $value = NULL, $checked = FALSE, array $attributes = NULL)
201+
public static function radio($name, $value = NULL, $checked = FALSE, array $attributes = [])
202202
{
203203
$attributes['type'] = 'radio';
204204

@@ -224,7 +224,7 @@ public static function radio($name, $value = NULL, $checked = FALSE, array $attr
224224
* @uses HTML::attributes
225225
* @uses HTML::chars
226226
*/
227-
public static function textarea($name, $body = '', array $attributes = NULL, $double_encode = TRUE)
227+
public static function textarea($name, $body = '', ?array $attributes = [], $double_encode = TRUE)
228228
{
229229
// Set the input name
230230
$attributes['name'] = $name;
@@ -249,7 +249,7 @@ public static function textarea($name, $body = '', array $attributes = NULL, $do
249249
* @return string
250250
* @uses HTML::attributes
251251
*/
252-
public static function select($name, array $options = NULL, $selected = NULL, array $attributes = NULL)
252+
public static function select($name, ?array $options = NULL, $selected = NULL, array $attributes = [])
253253
{
254254
// Set the input name
255255
$attributes['name'] = $name;
@@ -351,7 +351,7 @@ public static function select($name, array $options = NULL, $selected = NULL, ar
351351
* @return string
352352
* @uses Form::input
353353
*/
354-
public static function submit($name, $value, array $attributes = NULL)
354+
public static function submit($name, $value, array $attributes = [])
355355
{
356356
$attributes['type'] = 'submit';
357357

@@ -370,7 +370,7 @@ public static function submit($name, $value, array $attributes = NULL)
370370
* @return string
371371
* @uses Form::input
372372
*/
373-
public static function image($name, $value, array $attributes = NULL, $index = FALSE)
373+
public static function image($name, $value, ?array $attributes = [], $index = FALSE)
374374
{
375375
if ( ! empty($attributes['src']))
376376
{
@@ -398,7 +398,7 @@ public static function image($name, $value, array $attributes = NULL, $index = F
398398
* @return string
399399
* @uses HTML::attributes
400400
*/
401-
public static function button($name, $body, array $attributes = NULL)
401+
public static function button($name, $body, array $attributes = [])
402402
{
403403
// Set the input name
404404
$attributes['name'] = $name;
@@ -417,7 +417,7 @@ public static function button($name, $body, array $attributes = NULL)
417417
* @return string
418418
* @uses HTML::attributes
419419
*/
420-
public static function label($input, $text = NULL, array $attributes = NULL)
420+
public static function label($input, $text = NULL, array $attributes = [])
421421
{
422422
if ($text === NULL)
423423
{

classes/Kohana/HTML.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static function entities($value, $double_encode = TRUE)
103103
* @uses URL::site
104104
* @uses HTML::attributes
105105
*/
106-
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = TRUE)
106+
public static function anchor($uri, $title = NULL, ?array $attributes = NULL, $protocol = NULL, $index = TRUE)
107107
{
108108
if ($title === NULL)
109109
{
@@ -154,7 +154,7 @@ public static function anchor($uri, $title = NULL, array $attributes = NULL, $pr
154154
* @uses URL::base
155155
* @uses HTML::attributes
156156
*/
157-
public static function file_anchor($file, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = FALSE)
157+
public static function file_anchor($file, $title = NULL, ?array $attributes = NULL, $protocol = NULL, $index = FALSE)
158158
{
159159
if ($title === NULL)
160160
{
@@ -180,7 +180,7 @@ public static function file_anchor($file, $title = NULL, array $attributes = NUL
180180
* @return string
181181
* @uses HTML::attributes
182182
*/
183-
public static function mailto($email, $title = NULL, array $attributes = NULL)
183+
public static function mailto($email, $title = NULL, array $attributes = [])
184184
{
185185
if ($title === NULL)
186186
{
@@ -204,7 +204,7 @@ public static function mailto($email, $title = NULL, array $attributes = NULL)
204204
* @uses URL::base
205205
* @uses HTML::attributes
206206
*/
207-
public static function style($file, array $attributes = NULL, $protocol = NULL, $index = FALSE)
207+
public static function style($file, ?array $attributes = NULL, $protocol = NULL, $index = FALSE)
208208
{
209209
if (\strpos($file, '://') === FALSE AND \strpos($file, '//') !== 0)
210210
{
@@ -237,7 +237,7 @@ public static function style($file, array $attributes = NULL, $protocol = NULL,
237237
* @uses URL::base
238238
* @uses HTML::attributes
239239
*/
240-
public static function script($file, array $attributes = NULL, $protocol = NULL, $index = FALSE)
240+
public static function script($file, ?array $attributes = NULL, $protocol = NULL, $index = FALSE)
241241
{
242242
if (\strpos($file, '://') === FALSE AND \strpos($file, '//') !== 0)
243243
{
@@ -267,7 +267,7 @@ public static function script($file, array $attributes = NULL, $protocol = NULL,
267267
* @uses URL::base
268268
* @uses HTML::attributes
269269
*/
270-
public static function image($file, array $attributes = NULL, $protocol = NULL, $index = FALSE)
270+
public static function image($file, ?array $attributes = NULL, $protocol = NULL, $index = FALSE)
271271
{
272272
if (\strpos($file, '://') === FALSE)
273273
{
@@ -290,7 +290,7 @@ public static function image($file, array $attributes = NULL, $protocol = NULL,
290290
* @param array $attributes attribute list
291291
* @return string
292292
*/
293-
public static function attributes(array $attributes = NULL)
293+
public static function attributes(array $attributes = [])
294294
{
295295
if (empty($attributes))
296296
return '';

classes/Kohana/HTTP/Exception.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class Kohana_HTTP_Exception extends Kohana_Exception {
1010
* @param array $variables translation variables
1111
* @return HTTP_Exception
1212
*/
13-
public static function factory($code, $message = "", array $variables = NULL, Throwable $previous = NULL)
13+
public static function factory($code, $message = "", ?array $variables = NULL, ?Throwable $previous = NULL)
1414
{
1515
$class = 'HTTP_Exception_'.$code;
1616

@@ -37,7 +37,7 @@ public static function factory($code, $message = "", array $variables = NULL, Th
3737
* @param array $variables translation variables
3838
* @return void
3939
*/
40-
public function __construct($message = "", array $variables = NULL, Throwable $previous = NULL)
40+
public function __construct($message = "", ?array $variables = NULL, ?Throwable $previous = NULL)
4141
{
4242
parent::__construct($message, $variables, $this->_code, $previous);
4343
}
@@ -48,7 +48,7 @@ public function __construct($message = "", array $variables = NULL, Throwable $p
4848
* @param Request $request Request object that triggered this exception.
4949
* @return HTTP_Exception
5050
*/
51-
public function request(Request $request = NULL)
51+
public function request(?Request $request = NULL)
5252
{
5353
if ($request === NULL)
5454
return $this->_request;

classes/Kohana/HTTP/Exception/Expected.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ abstract class Kohana_HTTP_Exception_Expected extends HTTP_Exception {
2828
* @param array $variables translation variables
2929
* @return void
3030
*/
31-
public function __construct($message = NULL, array $variables = NULL, Throwable $previous = NULL)
31+
public function __construct($message = NULL, ?array $variables = NULL, ?Throwable $previous = NULL)
3232
{
3333
parent::__construct($message, $variables, $previous);
3434

classes/Kohana/HTTP/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ public function preferred_language(array $languages, $explicit = FALSE)
858858
* @return mixed
859859
* @since 3.2.0
860860
*/
861-
public function send_headers(HTTP_Response $response = NULL, $replace = FALSE, $callback = NULL)
861+
public function send_headers(HTTP_Response $response, $replace = FALSE, $callback = NULL)
862862
{
863863
$protocol = $response->protocol();
864864
$status = $response->status();

classes/Kohana/I18n.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public static function load($lang)
152152
* @param string $lang source language
153153
* @return string
154154
*/
155-
function __($string, array $values = NULL, $lang = 'en-us')
155+
function __($string, ?array $values = null, $lang = 'en-us')
156156
{
157157
if ($lang !== I18n::$lang)
158158
{

classes/Kohana/Kohana/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Kohana_Kohana_Exception extends Exception {
4646
* @param Throwable $previous Previous exception
4747
* @return void
4848
*/
49-
public function __construct($message = "", array $variables = NULL, $code = 0, Throwable $previous = NULL)
49+
public function __construct($message = "", ?array $variables = null, $code = 0, ?Throwable $previous = NULL)
5050
{
5151
// Set the message
5252
$message = __($message, $variables);

classes/Kohana/Log.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function detach(Log_Writer $writer)
120120
* @param array $additional additional custom parameters to supply to the log writer
121121
* @return Log
122122
*/
123-
public function add($level, $message, array $values = NULL, array $additional = NULL)
123+
public function add($level, $message, ?array $values = [], array $additional = [])
124124
{
125125
if ($values)
126126
{
@@ -149,11 +149,6 @@ public function add($level, $message, array $values = NULL, array $additional =
149149
}
150150
}
151151

152-
if ($additional == NULL)
153-
{
154-
$additional = array();
155-
}
156-
157152
// Create a new message
158153
$this->_messages[] = array
159154
(

0 commit comments

Comments
 (0)