Skip to content

Commit def66c8

Browse files
authored
Merge pull request #3968 from sfadschm/use-nullable-types
Use nullable typehints for non-optional typed function arguments.
2 parents 3c88f75 + c35760d commit def66c8

File tree

9 files changed

+71
-70
lines changed

9 files changed

+71
-70
lines changed

system/CodeIgniter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public function useSafeOutput(bool $safe = true)
380380
* @return RequestInterface|ResponseInterface|mixed
381381
* @throws RedirectException
382382
*/
383-
protected function handleRequest(RouteCollectionInterface $routes = null, Cache $cacheConfig, bool $returnResponse = false)
383+
protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false)
384384
{
385385
$routeFilter = $this->tryToRouteIt($routes);
386386

system/Database/BaseBuilder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,15 +1319,15 @@ protected function _like($field, string $match = '', string $type = 'AND ', stri
13191319
/**
13201320
* Platform independent LIKE statement builder.
13211321
*
1322-
* @param string $prefix
1323-
* @param string $column
1324-
* @param string $not
1325-
* @param string $bind
1326-
* @param boolean $insensitiveSearch
1322+
* @param string|null $prefix
1323+
* @param string $column
1324+
* @param string|null $not
1325+
* @param string $bind
1326+
* @param boolean $insensitiveSearch
13271327
*
13281328
* @return string $like_statement
13291329
*/
1330-
protected function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string
1330+
protected function _like_statement(?string $prefix, string $column, ?string $not, string $bind, bool $insensitiveSearch = false): string
13311331
{
13321332
$likeStatement = "{$prefix} {$column} {$not} LIKE :{$bind}:";
13331333

@@ -1679,12 +1679,12 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape =
16791679
/**
16801680
* LIMIT
16811681
*
1682-
* @param integer $value LIMIT value
1683-
* @param integer $offset OFFSET value
1682+
* @param integer|null $value LIMIT value
1683+
* @param integer|null $offset OFFSET value
16841684
*
16851685
* @return $this
16861686
*/
1687-
public function limit(int $value = null, ?int $offset = 0)
1687+
public function limit(?int $value = null, ?int $offset = 0)
16881688
{
16891689
if (! is_null($value))
16901690
{

system/Database/Postgre/Builder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,15 @@ protected function _truncate(string $table): string
361361
*
362362
* @see https://www.postgresql.org/docs/9.2/static/functions-matching.html
363363
*
364-
* @param string $prefix
365-
* @param string $column
366-
* @param string $not
367-
* @param string $bind
368-
* @param boolean $insensitiveSearch
364+
* @param string|null $prefix
365+
* @param string $column
366+
* @param string|null $not
367+
* @param string $bind
368+
* @param boolean $insensitiveSearch
369369
*
370370
* @return string $like_statement
371371
*/
372-
public function _like_statement(string $prefix = null, string $column, string $not = null, string $bind, bool $insensitiveSearch = false): string
372+
public function _like_statement(?string $prefix, string $column, ?string $not, string $bind, bool $insensitiveSearch = false): string
373373
{
374374
$op = $insensitiveSearch === true ? 'ILIKE' : 'LIKE';
375375

system/Pager/Pager.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ public function simpleLinks(string $group = 'default', string $template = 'defau
115115
* Allows for a simple, manual, form of pagination where all of the data
116116
* is provided by the user. The URL is the current URI.
117117
*
118-
* @param integer $page
119-
* @param integer $perPage
120-
* @param integer $total
121-
* @param string $template The output template alias to render.
122-
* @param integer $segment (if page number is provided by URI segment)
118+
* @param integer $page
119+
* @param integer|null $perPage
120+
* @param integer $total
121+
* @param string $template The output template alias to render.
122+
* @param integer $segment (whether page number is provided by URI segment)
123+
* @param string|null $group optional group (i.e. if we'd like to define custom path)
123124
*
124-
* @param string $group optional group (i.e. if we'd like to define custom path)
125125
* @return string
126126
*/
127-
public function makeLinks(int $page, int $perPage = null, int $total, string $template = 'default_full', int $segment = 0, ?string $group = 'default'): string
127+
public function makeLinks(int $page, ?int $perPage, int $total, string $template = 'default_full', int $segment = 0, ?string $group = 'default'): string
128128
{
129129
$group = $group === '' ? 'default' : $group;
130130

@@ -163,15 +163,15 @@ protected function displayLinks(string $group, string $template): string
163163
* Stores a set of pagination data for later display. Most commonly used
164164
* by the model to automate the process.
165165
*
166-
* @param string $group
167-
* @param integer $page
168-
* @param integer $perPage
169-
* @param integer $total
170-
* @param integer $segment
166+
* @param string $group
167+
* @param integer $page
168+
* @param integer|null $perPage
169+
* @param integer $total
170+
* @param integer $segment
171171
*
172172
* @return $this
173173
*/
174-
public function store(string $group, int $page, int $perPage = null, int $total, int $segment = 0)
174+
public function store(string $group, int $page, ?int $perPage, int $total, int $segment = 0)
175175
{
176176
if ($segment)
177177
{

system/Test/DOMParser.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ public function seeCheckboxIsChecked(string $element): bool
218218
/**
219219
* Search the DOM using an XPath expression.
220220
*
221-
* @param string $search
222-
* @param string $element
223-
* @param array $paths
221+
* @param string|null $search
222+
* @param string $element
223+
* @param array $paths
224+
*
224225
* @return DOMNodeList
225226
*/
226-
protected function doXPath(string $search = null, string $element, array $paths = [])
227+
protected function doXPath(?string $search, string $element, array $paths = [])
227228
{
228229
// Otherwise, grab any elements that match
229230
// the selector

system/Validation/CreditCardRules.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ class CreditCardRules
172172
* 'cc_num' => 'valid_cc_number[visa]'
173173
* ];
174174
*
175-
* @param string $ccNumber
176-
* @param string $type
175+
* @param string|null $ccNumber
176+
* @param string $type
177177
*
178178
* @return boolean
179179
*/
180-
public function valid_cc_number(string $ccNumber = null, string $type): bool
180+
public function valid_cc_number(?string $ccNumber, string $type): bool
181181
{
182182
$type = strtolower($type);
183183
$info = null;

system/Validation/FileRules.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public function __construct(RequestInterface $request = null)
4949
/**
5050
* Verifies that $name is the name of a valid uploaded file.
5151
*
52-
* @param string $blank
53-
* @param string $name
52+
* @param string|null $blank
53+
* @param string $name
5454
*
5555
* @return boolean
5656
*/
57-
public function uploaded(string $blank = null, string $name): bool
57+
public function uploaded(?string $blank, string $name): bool
5858
{
5959
if (! ($files = $this->request->getFileMultiple($name)))
6060
{
@@ -100,7 +100,7 @@ public function uploaded(string $blank = null, string $name): bool
100100
*
101101
* @return boolean
102102
*/
103-
public function max_size(string $blank = null, string $params): bool
103+
public function max_size(?string $blank, string $params): bool
104104
{
105105
// Grab the file name off the top of the $params
106106
// after we split it.
@@ -149,7 +149,7 @@ public function max_size(string $blank = null, string $params): bool
149149
*
150150
* @return boolean
151151
*/
152-
public function is_image(string $blank = null, string $params): bool
152+
public function is_image(?string $blank, string $params): bool
153153
{
154154
// Grab the file name off the top of the $params
155155
// after we split it.
@@ -196,7 +196,7 @@ public function is_image(string $blank = null, string $params): bool
196196
*
197197
* @return boolean
198198
*/
199-
public function mime_in(string $blank = null, string $params): bool
199+
public function mime_in(?string $blank, string $params): bool
200200
{
201201
// Grab the file name off the top of the $params
202202
// after we split it.
@@ -239,7 +239,7 @@ public function mime_in(string $blank = null, string $params): bool
239239
*
240240
* @return boolean
241241
*/
242-
public function ext_in(string $blank = null, string $params): bool
242+
public function ext_in(?string $blank, string $params): bool
243243
{
244244
// Grab the file name off the top of the $params
245245
// after we split it.
@@ -283,7 +283,7 @@ public function ext_in(string $blank = null, string $params): bool
283283
*
284284
* @return boolean
285285
*/
286-
public function max_dims(string $blank = null, string $params): bool
286+
public function max_dims(?string $blank, string $params): bool
287287
{
288288
// Grab the file name off the top of the $params
289289
// after we split it.

system/Validation/FormatRules.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ class FormatRules
2121
/**
2222
* Alpha
2323
*
24-
* @param string $str
24+
* @param string|null $str
2525
*
2626
* @return boolean
2727
*/
28-
public function alpha(string $str = null): bool
28+
public function alpha(?string $str = null): bool
2929
{
3030
return ctype_alpha($str);
3131
}
3232

3333
/**
3434
* Alpha with spaces.
3535
*
36-
* @param string $value Value.
36+
* @param string|null $value Value.
3737
*
3838
* @return boolean True if alpha with spaces, else false.
3939
*/
40-
public function alpha_space(string $value = null): bool
40+
public function alpha_space(?string $value = null): bool
4141
{
4242
if ($value === null)
4343
{
@@ -50,11 +50,11 @@ public function alpha_space(string $value = null): bool
5050
/**
5151
* Alphanumeric with underscores and dashes
5252
*
53-
* @param string $str
53+
* @param string|null $str
5454
*
5555
* @return boolean
5656
*/
57-
public function alpha_dash(string $str = null): bool
57+
public function alpha_dash(?string $str = null): bool
5858
{
5959
return (bool) preg_match('/^[a-z0-9_-]+$/i', $str);
6060
}
@@ -78,23 +78,23 @@ public function alpha_numeric_punct($str)
7878
/**
7979
* Alphanumeric
8080
*
81-
* @param string $str
81+
* @param string|null $str
8282
*
8383
* @return boolean
8484
*/
85-
public function alpha_numeric(string $str = null): bool
85+
public function alpha_numeric(?string $str = null): bool
8686
{
8787
return ctype_alnum($str);
8888
}
8989

9090
/**
9191
* Alphanumeric w/ spaces
9292
*
93-
* @param string $str
93+
* @param string|null $str
9494
*
9595
* @return boolean
9696
*/
97-
public function alpha_numeric_space(string $str = null): bool
97+
public function alpha_numeric_space(?string $str = null): bool
9898
{
9999
return (bool) preg_match('/^[A-Z0-9 ]+$/i', $str);
100100
}
@@ -117,82 +117,82 @@ public function string($str = null): bool
117117
/**
118118
* Decimal number
119119
*
120-
* @param string $str
120+
* @param string|null $str
121121
*
122122
* @return boolean
123123
*/
124-
public function decimal(string $str = null): bool
124+
public function decimal(?string $str = null): bool
125125
{
126126
return (bool) preg_match('/^[-+]?[0-9]{0,}\.?[0-9]+$/', $str);
127127
}
128128

129129
/**
130130
* String of hexidecimal characters
131131
*
132-
* @param string $str
132+
* @param string|null $str
133133
*
134134
* @return boolean
135135
*/
136-
public function hex(string $str = null): bool
136+
public function hex(?string $str = null): bool
137137
{
138138
return ctype_xdigit($str);
139139
}
140140

141141
/**
142142
* Integer
143143
*
144-
* @param string $str
144+
* @param string|null $str
145145
*
146146
* @return boolean
147147
*/
148-
public function integer(string $str = null): bool
148+
public function integer(?string $str = null): bool
149149
{
150150
return (bool) preg_match('/^[\-+]?[0-9]+$/', $str);
151151
}
152152

153153
/**
154154
* Is a Natural number (0,1,2,3, etc.)
155155
*
156-
* @param string $str
156+
* @param string|null $str
157157
* @return boolean
158158
*/
159-
public function is_natural(string $str = null): bool
159+
public function is_natural(?string $str = null): bool
160160
{
161161
return ctype_digit($str);
162162
}
163163

164164
/**
165165
* Is a Natural number, but not a zero (1,2,3, etc.)
166166
*
167-
* @param string $str
167+
* @param string|null $str
168168
* @return boolean
169169
*/
170-
public function is_natural_no_zero(string $str = null): bool
170+
public function is_natural_no_zero(?string $str = null): bool
171171
{
172172
return ($str !== '0' && ctype_digit($str));
173173
}
174174

175175
/**
176176
* Numeric
177177
*
178-
* @param string $str
178+
* @param string|null $str
179179
*
180180
* @return boolean
181181
*/
182-
public function numeric(string $str = null): bool
182+
public function numeric(?string $str = null): bool
183183
{
184184
return (bool) preg_match('/^[\-+]?[0-9]*\.?[0-9]+$/', $str);
185185
}
186186

187187
/**
188188
* Compares value against a regular expression pattern.
189189
*
190-
* @param string $str
191-
* @param string $pattern
190+
* @param string|null $str
191+
* @param string $pattern
192192
*
193193
* @return boolean
194194
*/
195-
public function regex_match(string $str = null, string $pattern): bool
195+
public function regex_match(?string $str, string $pattern): bool
196196
{
197197
if (strpos($pattern, '/') !== 0)
198198
{

tests/system/Validation/FormatRulesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testRegexMatchFalse()
7272
/**
7373
* @dataProvider urlProvider
7474
*/
75-
public function testValidURL(string $url = null, bool $expected)
75+
public function testValidURL(?string $url, bool $expected)
7676
{
7777
$data = [
7878
'foo' => $url,

0 commit comments

Comments
 (0)