Skip to content

Commit 05a9cd7

Browse files
committed
refactor: Enable MustHaveReturnTypeFunctionRule StructArmed rule on system/Helpers
1 parent c32a6e5 commit 05a9cd7

11 files changed

Lines changed: 23 additions & 39 deletions

structarmed.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* For the full copyright and license information, please view
1111
* the LICENSE file that was distributed with this source code.
1212
*/
13-
13+
use Boundwize\StructArmed\Rule\Rules\Function_\MustHaveReturnTypeFunctionRule;
1414
use Boundwize\StructArmed\Preset\Presets\CodeQualityPreset;
1515
use CodeIgniter\Cache\ResponseCache;
1616
use CodeIgniter\HTTP\CLIRequest;
@@ -52,6 +52,10 @@
5252
])
5353
->cacheDirectory(is_dir('/tmp') ? '/tmp/structarmed' : null)
5454
->withPresets(Preset::PSR4(), Preset::CODEQUALITY())
55+
56+
->layer('Helpers', __DIR__ . '/system/Helpers')
57+
->rule('helpers.functions_must_have_return_type', new MustHaveReturnTypeFunctionRule('Helpers'))
58+
5559
// Resolve CodeIgniter layers from class names because several layers share directories.
5660
->layerPattern('API', '/^CodeIgniter\\\\API\\\\.*$/')
5761
->layerPattern('Cache', '/^CodeIgniter\\\\Cache\\\\.*$/')
@@ -110,7 +114,7 @@
110114
'Security' => ['Cookie', 'HTTP', 'I18n', 'Session'],
111115
'Session' => ['Cookie', 'Database', 'HTTP', 'I18n'],
112116
'Throttle' => ['Cache', 'I18n'],
113-
'Validation' => ['Database', 'HTTP'],
117+
'Validation' => ['Database', 'HTTP', 'Helpers'],
114118
'View' => ['Cache'],
115119
])
116120
->skipPathsForRuleset(['*test*'])

system/Helpers/array_helper.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
* wildcard searches, like foo.*.bar
2222
*
2323
* @param array<array-key, mixed> $array
24-
*
25-
* @return mixed
2624
*/
27-
function dot_array_search(string $index, array $array)
25+
function dot_array_search(string $index, array $array): mixed
2826
{
2927
return ArrayHelper::dotSearch($index, $array);
3028
}
@@ -36,10 +34,8 @@ function dot_array_search(string $index, array $array)
3634
*
3735
* @param int|string $key
3836
* @param array<array-key, mixed> $array
39-
*
40-
* @return mixed
4137
*/
42-
function array_deep_search($key, array $array)
38+
function array_deep_search($key, array $array): mixed
4339
{
4440
if (isset($array[$key])) {
4541
return $array[$key];

system/Helpers/cookie_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function set_cookie(
7979
*
8080
* @see \CodeIgniter\HTTP\IncomingRequest::getCookie()
8181
*/
82-
function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
82+
function get_cookie($index, bool $xssClean = false, ?string $prefix = ''): array|string|null
8383
{
8484
if ($prefix === '') {
8585
$cookie = config(CookieConfig::class);

system/Helpers/filesystem_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ function get_dir_file_info(string $sourceDir, bool $topLevelOnly = true, bool $r
326326
* fileperms?: int
327327
* }|null
328328
*/
329-
function get_file_info(string $file, $returnedValues = ['name', 'server_path', 'size', 'date'])
329+
function get_file_info(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']): ?array
330330
{
331331
if (! is_file($file)) {
332332
return null;

system/Helpers/form_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ function form_close(string $extra = ''): string
558558
*
559559
* @return list<string>|string
560560
*/
561-
function set_value(string $field, $default = '', bool $htmlEscape = true)
561+
function set_value(string $field, $default = '', bool $htmlEscape = true): array|string
562562
{
563563
$request = service('request');
564564

@@ -695,7 +695,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st
695695
*
696696
* @return array<string, string>
697697
*/
698-
function validation_errors()
698+
function validation_errors(): array
699699
{
700700
$errors = session('_ci_validation_errors');
701701

system/Helpers/html_helper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,8 @@ function embed(string $src, string $type = 'unknown', string $attributes = '', b
540540
if (! function_exists('_has_protocol')) {
541541
/**
542542
* Test the protocol of a URI.
543-
*
544-
* @return false|int
545543
*/
546-
function _has_protocol(string $url)
544+
function _has_protocol(string $url): false|int
547545
{
548546
return preg_match('#^([a-z]+:)?//#i', $url);
549547
}

system/Helpers/kint_helper.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ function dd(...$vars): void
3939
* dd function
4040
*
4141
* @param mixed ...$vars
42-
*
43-
* @return int
4442
*/
45-
function dd(...$vars)
43+
function dd(...$vars): int
4644
{
4745
return 0;
4846
}
@@ -55,10 +53,8 @@ function dd(...$vars)
5553
* d function
5654
*
5755
* @param mixed ...$vars
58-
*
59-
* @return int
6056
*/
61-
function d(...$vars)
57+
function d(...$vars): int
6258
{
6359
return 0;
6460
}
@@ -77,10 +73,8 @@ function trace(): void
7773
} else {
7874
/**
7975
* Generic trace function in case that Kint is not loaded.
80-
*
81-
* @return int
8276
*/
83-
function trace()
77+
function trace(): int
8478
{
8579
return 0;
8680
}

system/Helpers/number_helper.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
*
2222
* @param float|int|string $num Will be cast as int
2323
* @param non-empty-string|null $locale [optional]
24-
*
25-
* @return bool|string
2624
*/
27-
function number_to_size($num, int $precision = 1, ?string $locale = null)
25+
function number_to_size($num, int $precision = 1, ?string $locale = null): bool|string
2826
{
2927
try {
3028
// Strip any formatting & ensure numeric input
@@ -76,10 +74,8 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
7674
* @param int|string $num Will be cast as int
7775
* @param int $precision [optional] The optional number of decimal digits to round to.
7876
* @param non-empty-string|null $locale [optional]
79-
*
80-
* @return bool|string
8177
*/
82-
function number_to_amount($num, int $precision = 0, ?string $locale = null)
78+
function number_to_amount($num, int $precision = 0, ?string $locale = null): bool|string
8379
{
8480
// Strip any formatting & ensure numeric input
8581
try {

system/Helpers/test_helper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @return array<string, mixed>|object
3030
*/
31-
function fake($model, ?array $overrides = null, $persist = true)
31+
function fake($model, ?array $overrides = null, $persist = true): array|object
3232
{
3333
$fabricator = new Fabricator($model);
3434

@@ -49,10 +49,8 @@ function fake($model, ?array $overrides = null, $persist = true)
4949
* Used within our test suite to mock certain system tools.
5050
*
5151
* @param string $className Fully qualified class name
52-
*
53-
* @return object
5452
*/
55-
function mock(string $className)
53+
function mock(string $className): object
5654
{
5755
$mockClass = $className::$mockClass;
5856
$mockService = $className::$mockServiceName ?? '';

system/Helpers/text_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ function ellipsize(string $str, int $maxLength, $position = 1, string $ellipsis
458458
*
459459
* @return array<array-key, mixed>|string string or array
460460
*/
461-
function strip_slashes($str)
461+
function strip_slashes($str): array|string
462462
{
463463
if (! is_array($str)) {
464464
return stripslashes($str);

0 commit comments

Comments
 (0)