From 0a860b32595f1c75f40509320eca3261bc376318 Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Sun, 3 Nov 2024 22:37:38 +0500 Subject: [PATCH] add types --- .../Pages/EditPaymentOrder.php | 1 + app/Helpers/helpers.php | 27 ++++++++---- .../PaymentOrder/Models/PaymentOrder.php | 22 ++++++++++ .../Repositories/TurkmenNumberFormatter.php | 41 ++++++++++++++----- phpstan.neon | 3 +- routes/web.php | 6 --- 6 files changed, 74 insertions(+), 26 deletions(-) diff --git a/app/Filament/Resources/PaymentOrder/PaymentOrderResource/Pages/EditPaymentOrder.php b/app/Filament/Resources/PaymentOrder/PaymentOrderResource/Pages/EditPaymentOrder.php index b05c167..e02f2d2 100644 --- a/app/Filament/Resources/PaymentOrder/PaymentOrderResource/Pages/EditPaymentOrder.php +++ b/app/Filament/Resources/PaymentOrder/PaymentOrderResource/Pages/EditPaymentOrder.php @@ -21,6 +21,7 @@ class EditPaymentOrder extends EditRecord Actions\DeleteAction::make(), Action::make('sendEmail') ->action(function (array $data) { + /** @var \App\Modules\PaymentOrder\Models\PaymentOrder $paymentOrder */ $paymentOrder = $this->getRecord(); Carbon::setLocale('tk'); diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 6ea4040..0cc6830 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -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 + * @return array */ 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 $modules */ + $modules = temp_cache('modules'); + + return $modules; } /** @var array */ @@ -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; } - diff --git a/app/Modules/PaymentOrder/Models/PaymentOrder.php b/app/Modules/PaymentOrder/Models/PaymentOrder.php index 5d2a84d..1bdab57 100644 --- a/app/Modules/PaymentOrder/Models/PaymentOrder.php +++ b/app/Modules/PaymentOrder/Models/PaymentOrder.php @@ -4,4 +4,26 @@ namespace App\Modules\PaymentOrder\Models; use Illuminate\Database\Eloquent\Model; +/** + * @property int $id + * @property ?string $number + * @property ?string $money_amount + * @property ?string $payment_reason_number + * @property ?string $payment_reason_description + * @property ?string $bank_code + * @property ?string $t_name + * @property ?string $t_ssb + * @property ?string $t_bab + * @property ?string $t_bank + * @property ?string $t_hb_1 + * @property ?string $t_hb_2 + * @property ?string $a_name + * @property ?string $a_ssb + * @property ?string $a_bab + * @property ?string $a_bank + * @property ?string $a_hb_1 + * @property ?string $a_hb_2 + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $deleted_at + */ class PaymentOrder extends Model {} diff --git a/app/Modules/TurkmenNumberFormatter/Repositories/TurkmenNumberFormatter.php b/app/Modules/TurkmenNumberFormatter/Repositories/TurkmenNumberFormatter.php index e4ea183..44c4740 100644 --- a/app/Modules/TurkmenNumberFormatter/Repositories/TurkmenNumberFormatter.php +++ b/app/Modules/TurkmenNumberFormatter/Repositories/TurkmenNumberFormatter.php @@ -4,14 +4,33 @@ namespace App\Modules\TurkmenNumberFormatter\Repositories; class TurkmenNumberFormatter { - // Define number mappings - private static $units = ['', 'bir', 'iki', 'üç', 'dört', 'bäş', 'alty', 'ýedi', 'sekiz', 'dokuz']; + /** + * Units + * + * @var array + */ + private static array $units = ['', 'bir', 'iki', 'üç', 'dört', 'bäş', 'alty', 'ýedi', 'sekiz', 'dokuz']; - private static $tens = ['', 'on', 'ýigrimi', 'otuz', 'kyrk', 'elli', 'altmyş', 'ýetmiş', 'segsen', 'togsan']; + /** + * Tens + * + * @var array + */ + private static array $tens = ['', 'on', 'ýigrimi', 'otuz', 'kyrk', 'elli', 'altmyş', 'ýetmiş', 'segsen', 'togsan']; - private static $hundreds = ['', 'ýüz', 'iki ýüz', 'üç ýüz', 'dört ýüz', 'bäş ýüz', 'alty ýüz', 'ýedi ýüz', 'sekiz ýüz', 'dokuz ýüz']; + /** + * Hundreds + * + * @var array + */ + private static array $hundreds = ['', 'ýüz', 'iki ýüz', 'üç ýüz', 'dört ýüz', 'bäş ýüz', 'alty ýüz', 'ýedi ýüz', 'sekiz ýüz', 'dokuz ýüz']; - private static $largeNumbers = ['', 'müň', 'million', 'milliard', 'trillion']; + /** + * Large mumbers + * + * @var array + */ + private static array $largeNumbers = ['', 'müň', 'million', 'milliard', 'trillion']; /** * Main method to format a given amount in Turkmen. @@ -19,16 +38,16 @@ class TurkmenNumberFormatter * @param float $amount The amount to format. * @return string The amount in written Turkmen format. */ - public static function format($amount) + public static function format(float $amount): string { // Split the amount into whole and fractional parts [$whole, $fraction] = explode('.', number_format($amount, 2, '.', '')); // Convert the whole part - $wholeWords = self::convertWholePart($whole); + $wholeWords = self::convertWholePart(intval($whole)); // Convert the fractional part - $fractionWords = self::convertFractionalPart($fraction); + $fractionWords = self::convertFractionalPart(intval($fraction)); return trim($wholeWords.' '.$fractionWords); } @@ -39,7 +58,7 @@ class TurkmenNumberFormatter * @param int $whole The whole part of the number. * @return string The converted whole part in Turkmen. */ - private static function convertWholePart($whole) + private static function convertWholePart(int $whole): string { $words = ''; $level = 0; @@ -63,7 +82,7 @@ class TurkmenNumberFormatter * @param int $fraction The fractional part of the number. * @return string The converted fractional part in Turkmen. */ - private static function convertFractionalPart($fraction) + private static function convertFractionalPart(int $fraction): string { if ($fraction <= 0) { return ''; @@ -85,7 +104,7 @@ class TurkmenNumberFormatter * @param int $num The number to convert. * @return string The converted number in Turkmen. */ - private static function convertToWords($num) + private static function convertToWords(int $num): string { $words = ''; diff --git a/phpstan.neon b/phpstan.neon index ae30d68..42ae794 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,8 @@ parameters: paths: - app/ - level: 6 + level: 9 ignoreErrors: - '#Unsafe usage of new static#' + - '#Static method Illuminate\\Log\\Logger::info\(\) invoked with 3 parameters, 1-2 required#' diff --git a/routes/web.php b/routes/web.php index 86a06c5..b3d9bbc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1 @@