add types

This commit is contained in:
2024-11-03 22:37:38 +05:00
parent 62ea6af082
commit 0a860b3259
6 changed files with 74 additions and 26 deletions

View File

@@ -2,6 +2,7 @@
use App\Modules\EmptyModule;
use App\Modules\ModuleContract;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
@@ -11,7 +12,7 @@ use Illuminate\Support\Str;
/**
* Application locales
*
* @return array<string, string>
* @return array<array-key, mixed>
*/
function appLocales(): array
{
@@ -25,7 +26,14 @@ function module(string $moduleName): ModuleContract
{
$moduleClass = 'App\\Modules\\'.$moduleName.'\\'.$moduleName.'Module';
return class_exists($moduleClass) ? (new $moduleClass) : emptyModule();
if (class_exists($moduleClass)) {
/** @var ModuleContract $module */
$module = new $moduleClass;
return $module;
}
return emptyModule();
}
/**
@@ -52,7 +60,10 @@ function modules_path(string $path = ''): string
function modules(bool $withDisabled = false): Collection
{
if (temp_cache()->has('modules')) {
return temp_cache('modules');
/** @var Collection<array-key, string> $modules */
$modules = temp_cache('modules');
return $modules;
}
/** @var array<int, string> */
@@ -87,14 +98,14 @@ function modules(bool $withDisabled = false): Collection
/**
* Temprory cache for single request
*
* @return ($key is '' ? CacheRepository : mixed)
*/
function temp_cache(string $key = ''): mixed
{
$tempCache = cache()->driver('array');
return ($key !== '')
? $tempCache->get($key)
: cache()->driver('array');
return ($key === '') ? $tempCache : $tempCache->get($key);
}
/**
@@ -116,8 +127,8 @@ function logDB(): void
*/
function getLatestNumber(string $tableName = 'incoming_letters', string $column = 'number'): int
{
/** @var null|object{max_number: string} $data */
$data = DB::table($tableName)->select(DB::raw("MAX(CAST(REGEXP_REPLACE({$column}, '[^0-9]', '') AS UNSIGNED)) AS max_number"))->first();
return intval($data->max_number) ?? 0;
return $data ? intval($data->max_number) : 0;
}