Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions structarmed.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

use Boundwize\StructArmed\Rule\Rules\Function_\MustHaveReturnTypeFunctionRule;
use Boundwize\StructArmed\Preset\Presets\CodeQualityPreset;
use CodeIgniter\Cache\ResponseCache;
use CodeIgniter\HTTP\CLIRequest;
Expand Down Expand Up @@ -52,6 +52,10 @@
])
->cacheDirectory(is_dir('/tmp') ? '/tmp/structarmed' : null)
->withPresets(Preset::PSR4(), Preset::CODEQUALITY())

->layer('Helpers', __DIR__ . '/system/Helpers')
->rule('helpers.functions_must_have_return_type', new MustHaveReturnTypeFunctionRule('Helpers'))

// Resolve CodeIgniter layers from class names because several layers share directories.
->layerPattern('API', '/^CodeIgniter\\\\API\\\\.*$/')
->layerPattern('Cache', '/^CodeIgniter\\\\Cache\\\\.*$/')
Expand Down Expand Up @@ -110,7 +114,7 @@
'Security' => ['Cookie', 'HTTP', 'I18n', 'Session'],
'Session' => ['Cookie', 'Database', 'HTTP', 'I18n'],
'Throttle' => ['Cache', 'I18n'],
'Validation' => ['Database', 'HTTP'],
'Validation' => ['Database', 'HTTP', 'Helpers'],
'View' => ['Cache'],
])
->skipPathsForRuleset(['*test*'])
Expand Down
8 changes: 2 additions & 6 deletions system/Helpers/array_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
* wildcard searches, like foo.*.bar
*
* @param array<array-key, mixed> $array
*
* @return mixed
*/
function dot_array_search(string $index, array $array)
function dot_array_search(string $index, array $array): mixed
{
return ArrayHelper::dotSearch($index, $array);
}
Expand All @@ -36,10 +34,8 @@ function dot_array_search(string $index, array $array)
*
* @param int|string $key
* @param array<array-key, mixed> $array
*
* @return mixed
*/
function array_deep_search($key, array $array)
function array_deep_search($key, array $array): mixed
{
if (isset($array[$key])) {
return $array[$key];
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/cookie_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function set_cookie(
*
* @see \CodeIgniter\HTTP\IncomingRequest::getCookie()
*/
function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
function get_cookie($index, bool $xssClean = false, ?string $prefix = ''): array|string|null
{
if ($prefix === '') {
$cookie = config(CookieConfig::class);
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/filesystem_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function get_dir_file_info(string $sourceDir, bool $topLevelOnly = true, bool $r
* fileperms?: int
* }|null
*/
function get_file_info(string $file, $returnedValues = ['name', 'server_path', 'size', 'date'])
function get_file_info(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']): ?array
{
if (! is_file($file)) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function form_close(string $extra = ''): string
*
* @return list<string>|string
*/
function set_value(string $field, $default = '', bool $htmlEscape = true)
function set_value(string $field, $default = '', bool $htmlEscape = true): array|string
{
$request = service('request');

Expand Down Expand Up @@ -695,7 +695,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st
*
* @return array<string, string>
*/
function validation_errors()
function validation_errors(): array
{
$errors = session('_ci_validation_errors');

Expand Down
4 changes: 1 addition & 3 deletions system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,8 @@ function embed(string $src, string $type = 'unknown', string $attributes = '', b
if (! function_exists('_has_protocol')) {
/**
* Test the protocol of a URI.
*
* @return false|int
*/
function _has_protocol(string $url)
function _has_protocol(string $url): false|int
{
return preg_match('#^([a-z]+:)?//#i', $url);
}
Expand Down
12 changes: 3 additions & 9 deletions system/Helpers/kint_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ function dd(...$vars): void
* dd function
*
* @param mixed ...$vars
*
* @return int
*/
function dd(...$vars)
function dd(...$vars): int
{
return 0;
}
Expand All @@ -55,10 +53,8 @@ function dd(...$vars)
* d function
*
* @param mixed ...$vars
*
* @return int
*/
function d(...$vars)
function d(...$vars): int
{
return 0;
}
Expand All @@ -77,10 +73,8 @@ function trace(): void
} else {
/**
* Generic trace function in case that Kint is not loaded.
*
* @return int
*/
function trace()
function trace(): int
{
return 0;
}
Expand Down
8 changes: 2 additions & 6 deletions system/Helpers/number_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
*
* @param float|int|string $num Will be cast as int
* @param non-empty-string|null $locale [optional]
*
* @return bool|string
*/
function number_to_size($num, int $precision = 1, ?string $locale = null)
function number_to_size($num, int $precision = 1, ?string $locale = null): bool|string
{
try {
// Strip any formatting & ensure numeric input
Expand Down Expand Up @@ -76,10 +74,8 @@ function number_to_size($num, int $precision = 1, ?string $locale = null)
* @param int|string $num Will be cast as int
* @param int $precision [optional] The optional number of decimal digits to round to.
* @param non-empty-string|null $locale [optional]
*
* @return bool|string
*/
function number_to_amount($num, int $precision = 0, ?string $locale = null)
function number_to_amount($num, int $precision = 0, ?string $locale = null): bool|string
{
// Strip any formatting & ensure numeric input
try {
Expand Down
6 changes: 2 additions & 4 deletions system/Helpers/test_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @return array<string, mixed>|object
*/
function fake($model, ?array $overrides = null, $persist = true)
function fake($model, ?array $overrides = null, $persist = true): array|object
{
$fabricator = new Fabricator($model);

Expand All @@ -49,10 +49,8 @@ function fake($model, ?array $overrides = null, $persist = true)
* Used within our test suite to mock certain system tools.
*
* @param string $className Fully qualified class name
*
* @return object
*/
function mock(string $className)
function mock(string $className): object
{
$mockClass = $className::$mockClass;
$mockService = $className::$mockServiceName ?? '';
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/text_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function ellipsize(string $str, int $maxLength, $position = 1, string $ellipsis
*
* @return array<array-key, mixed>|string string or array
*/
function strip_slashes($str)
function strip_slashes($str): array|string
{
if (! is_array($str)) {
return stripslashes($str);
Expand Down
6 changes: 2 additions & 4 deletions system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function base_url($relativePath = '', ?string $scheme = null): string
* @return string|URI When returning string, the query and fragment parts are removed.
* When returning URI, the query and fragment parts are preserved.
*/
function current_url(bool $returnObject = false, ?IncomingRequest $request = null)
function current_url(bool $returnObject = false, ?IncomingRequest $request = null): string|URI
{
$request ??= service('request');
/** @var CLIRequest|IncomingRequest $request */
Expand All @@ -87,10 +87,8 @@ function current_url(bool $returnObject = false, ?IncomingRequest $request = nul
* we first check in a saved session variable, if it exists, and use that.
* If that's not available, however, we'll use a sanitized url from $_SERVER['HTTP_REFERER']
* which can be set by the user so is untrusted and not set by certain browsers/servers.
*
* @return string|URI
*/
function previous_url(bool $returnObject = false)
function previous_url(bool $returnObject = false): string|URI
{
// Grab from the session first, if we have it,
// since it's more reliable and safer.
Expand Down
Loading