This repository has been archived on 2025-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
atol-online/src/Helpers.php
AnthonyAxenov a5c88cd7d3 Функции проверки наследования классов вернул из Helpers в BasicTestCase и отрефакторил
- `isSameClass()`
- `checkImplementsInterfaces()`
- `checkUsesTraits()` + переписана под наследование
2021-12-06 14:15:47 +08:00

56 lines
1.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
namespace AtolOnline;
/**
* Класс с функциями-хелперами
*/
final class Helpers
{
/**
* Конвертирует копейки в рубли, оставляя только 2 знака после запятой
*
* @param float|null $kopeks Копейки
* @return float Рубли
*/
public static function toRub(?float $kopeks): float
{
return round(abs((float)$kopeks) / 100, 2);
}
/**
* Конвертирует рубли в копейки, учитывая только 2 знака после запятой
*
* @param float|null $rubles Рубли
* @return int Копейки
*/
public static function toKop(?float $rubles): int
{
return (int)round(abs((float)$rubles) * 100, 2);
}
/**
* Генерирует случайную строку указанной длины
*
* @param int $length Длина, по умолчанию 8
* @param bool $with_digits Включать ли цифры
* @return string
*/
public static function randomStr(int $length = 8, bool $with_digits = true): string
{
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' . ($with_digits ? '0123456789' : '');
$result = '';
for ($i = 0; $i < abs($length); $i++) {
$result .= $alphabet[mt_rand(0, strlen($alphabet) - 1)];
}
return $result;
}
}