Skip to content

Commit

Permalink
feat(static): use StaticClass
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Jun 11, 2024
1 parent 9a07015 commit ddad143
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Basic/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace h4kuna\DataType\Basic;

use h4kuna\DataType;
use Nette\StaticClass;

final class Arrays
{
use StaticClass;

/**
* Better array_combine where values array does not need same size.
Expand Down
3 changes: 3 additions & 0 deletions src/Basic/BitwiseOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace h4kuna\DataType\Basic;

use Nette\StaticClass;

final class BitwiseOperations
{
use StaticClass;

public static function check(int $number, int $flag): bool
{
Expand Down
2 changes: 2 additions & 0 deletions src/Basic/Bools.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace h4kuna\DataType\Basic;

use h4kuna\DataType\Exceptions\InvalidTypeException;
use Nette\StaticClass;

final class Bools
{
use StaticClass;

public static function from(mixed $value): bool
{
Expand Down
2 changes: 2 additions & 0 deletions src/Basic/Floats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use h4kuna\DataType;
use h4kuna\DataType\Exceptions\InvalidTypeException;
use Nette\StaticClass;
use Nette\Utils;

final class Floats
{
use StaticClass;

public static function from(
mixed $value,
Expand Down
2 changes: 2 additions & 0 deletions src/Basic/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use h4kuna\DataType;
use h4kuna\DataType\Exceptions\InvalidTypeException;
use Nette\StaticClass;

final class Integer
{
use StaticClass;

public static function from(mixed $value): int
{
Expand Down
2 changes: 2 additions & 0 deletions src/Basic/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace h4kuna\DataType\Basic;

use h4kuna\DataType;
use Nette\StaticClass;

/**
* Transform set from string to array and vice versa
Expand All @@ -18,6 +19,7 @@
*/
final class Set
{
use StaticClass;

/**
* @return array<string, true>
Expand Down
3 changes: 3 additions & 0 deletions src/Basic/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use h4kuna\DataType\Exceptions\InvalidStateException;
use h4kuna\DataType\Exceptions\InvalidTypeException;
use h4kuna\DataType\Location;
use Nette\StaticClass;

final class Strings
{
use StaticClass;

public static function from(mixed $value): string
{
if (is_int($value) || is_float($value) || is_null($value)) {
Expand Down
14 changes: 5 additions & 9 deletions src/Collection/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace h4kuna\DataType\Collection;

use h4kuna\DataType\Date\Time;

/**
* @phpstan-type Any mixed
* @phpstan-type InfoType array{time: float, message: Any}
Expand Down Expand Up @@ -29,7 +31,7 @@ public function __construct(private int $ttl = self::DISABLE_GARBAGE)
*/
public function tick($message = ''): void
{
$this->stack[] = ['message' => $message, 'time' => self::microtime()];
$this->stack[] = ['message' => $message, 'time' => Time::micro()];
}


Expand All @@ -52,7 +54,7 @@ public function isFull(): bool
if ($this->ttl === self::DISABLE_GARBAGE) {
return false;
} elseif ($this->ttl > 0) {
return $this->isFullByTime(self::microtime() - $this->ttl);
return $this->isFullByTime(Time::micro() - $this->ttl);
}

return $this->isFullByCount($this->ttl * -1);
Expand All @@ -77,7 +79,7 @@ private function garbage(): void
if ($this->ttl === self::DISABLE_GARBAGE) {
return;
} elseif ($this->ttl > 0) {
$this->garbageByTime(self::microtime() - $this->ttl);
$this->garbageByTime(Time::micro() - $this->ttl);
return;
}

Expand Down Expand Up @@ -111,12 +113,6 @@ private function garbageByCount(int $maxCount): void
}


private static function microtime(): float
{
return microtime(true);
}


private function isFullByTime(float $ttl): bool
{
$key = array_key_first($this->stack);
Expand Down
2 changes: 2 additions & 0 deletions src/Date/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use h4kuna\DataType;
use h4kuna\DataType\Exceptions\InvalidArgumentsException;
use h4kuna\Memoize\MemoryStorageStatic;
use Nette\StaticClass;
use Nette\Utils\Strings;

final class Calendar
{
use StaticClass;
use MemoryStorageStatic;

public static string $namesFile = __DIR__ . '/names.php';
Expand Down
3 changes: 3 additions & 0 deletions src/Date/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use DateTime;
use DateTimeImmutable;
use Nette\StaticClass;

final class Convert
{
use StaticClass;

public static function timestampToImmutable(int $timestamp): DateTimeImmutable
{
return (new DateTimeImmutable())->setTimestamp($timestamp);
Expand Down
2 changes: 2 additions & 0 deletions src/Date/Easter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use DateTimeImmutable;
use h4kuna\Memoize\MemoryStorageStatic;
use Nette\StaticClass;

final class Easter
{
use StaticClass;
use MemoryStorageStatic;

public static ?bool $useNative = null;
Expand Down
3 changes: 3 additions & 0 deletions src/Date/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use DateTimeImmutable;
use h4kuna\DataType\Basic\Arrays;
use h4kuna\DataType\Exceptions\InvalidArgumentsException;
use Nette\StaticClass;
use Nette\Utils\Strings as NetteStrings;
use h4kuna\DataType\Basic\Strings;
use Nette\Utils\Validators;

final class Parser
{
use StaticClass;

/** @var array<string> */
public static array $formats = ['d.m. H:i', 'm-d H:i', 'd.m.Y H:i', 'Y-m-d H:i', 'd.m.Y H:i:s', 'Y-m-d H:i:s'];

Expand Down
2 changes: 1 addition & 1 deletion src/Iterators/TextIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function setCsv(string $delimiter = ',', string $enclosure = '"', string
*/
private static function text2Array(string $text): array
{
return explode("\n", Strings::normalizeNewLines($text));
return explode("\n", Strings::unixNewLines($text));
}


Expand Down
2 changes: 2 additions & 0 deletions src/Location/Gps.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use h4kuna\DataType;
use h4kuna\DataType\Exceptions\InvalidArgumentsException;
use Nette\StaticClass;
use Nette\Utils\Strings;

final class Gps
{
use StaticClass;

private function __construct()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Number/Math.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use DateTimeInterface;
use h4kuna\DataType;
use h4kuna\DataType\Exceptions\InvalidArgumentsException;
use Nette\StaticClass;

final class Math
{
use StaticClass;

/**
* Allow number in interval and correct it.
Expand Down
4 changes: 4 additions & 0 deletions src/Number/RomeNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace h4kuna\DataType\Number;

use Nette\StaticClass;

/**
* @example
* echo RomeNumber::getRome(1968); // MCMLXVIII
Expand All @@ -10,6 +12,8 @@
*/
class RomeNumber
{
use StaticClass;

private const NUMBERS = [
'M' => 1000,
'CM' => 900,
Expand Down

0 comments on commit ddad143

Please sign in to comment.