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

@@ -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');

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;
}

View File

@@ -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 {}

View File

@@ -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<int, string>
*/
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<int, string>
*/
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<int, string>
*/
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<int, string>
*/
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 = '';

View File

@@ -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#'

View File

@@ -1,7 +1 @@
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});