Skip to content

Commit 1b3fba3

Browse files
author
Wazabii
committed
Data types
1 parent 7737094 commit 1b3fba3

File tree

6 files changed

+62
-33
lines changed

6 files changed

+62
-33
lines changed

Format/Arr.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ public function arrayKeys()
4848
}
4949

5050

51-
public function shift(?Str &$shiftedValue = null): Str
51+
public function shift(?Str &$shiftedValue = null): self
5252
{
5353
//$inst = clone $this;
5454
$shiftedValue = array_shift($this->value);
5555
return $this;
5656
}
5757

58-
public function pop(?Str &$poppedValue = null): Str
58+
public function pop(?Str &$poppedValue = null): self
5959
{
6060
//$inst = clone $this;
6161
$poppedValue = array_pop($this->value);

Format/DateTime.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use DateTime as MainDateTime;
1414
use DateTimeZone;
1515

16+
/**
17+
* @psalm-seal-methods
18+
*/
1619
class DateTime extends MainDateTime implements FormatInterface
1720
{
1821
// Default lang key
@@ -44,6 +47,25 @@ public function __construct(string $datetime = "now", ?DateTimeZone $timezone =
4447
$this->translations = static::LANG;
4548
}
4649

50+
/**
51+
* Get Value
52+
* @return string
53+
*/
54+
public function __toString(): string
55+
{
56+
return $this->format("Y/m/d H:i");
57+
}
58+
59+
/**
60+
* @param array $data
61+
* @return void
62+
*/
63+
public function __unserialize(array $data): void
64+
{
65+
$dateTime = new DateTime();
66+
$dateTime->setTimestamp($data['timestamp']); // Replace with your logic to unserialize the data
67+
}
68+
4769
/**
4870
* Init
4971
* @param string $value
@@ -74,15 +96,6 @@ public function withValue(string $value): self
7496
return self::value($value);
7597
}
7698

77-
/**
78-
* Get Value
79-
* @return string
80-
*/
81-
public function __toString(): string
82-
{
83-
return $this->format("Y/m/d H:i");
84-
}
85-
8699
/**
87100
* Gte formated date value
88101
* @param string $format

Format/Local.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ public static function value(array|string $data)
5656
return $inst;
5757
}
5858

59-
public static function setDir(string $prefix): void
59+
/**
60+
* Set directory
61+
* @param string $dir
62+
*/
63+
public static function setDir(string $dir): void
6064
{
61-
static::$dir = $prefix;
65+
static::$dir = $dir;
6266
}
6367

6468
public static function setLang(string $prefix): void
@@ -83,7 +87,7 @@ public function getValue(string $key): ?string
8387
return ($this->value[$key][$this::$prefix] ?? null);
8488
}
8589

86-
public function get(string|array $key, ?string $fallback = null, ?array $sprint = null): string
90+
public function get(string|array $key, ?string $fallback = null, ?array $sprint = null): ?string
8791
{
8892
if (is_null($this::$prefix)) {
8993
throw new Exception("Lang prefix is null.", 1);

Format/Num.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public static function numFormatter()
3636

3737
/**
3838
* Convert to float number
39-
* @return float
39+
* @return self
4040
*/
41-
public function float()
41+
public function float(): self
4242
{
4343
$this->value = (float)$this->value;
4444
return $this;
@@ -61,7 +61,8 @@ public function int(): self
6161
*/
6262
public function round(int $dec = 0): self
6363
{
64-
$this->value = round($this->float()->get(), $dec);
64+
$this->float();
65+
$this->value = round($this->value, $dec);
6566
return $this;
6667
}
6768

@@ -71,17 +72,19 @@ public function round(int $dec = 0): self
7172
*/
7273
public function floor(): self
7374
{
74-
$this->value = floor($this->float()->get());
75+
$this->float();
76+
$this->value = floor($this->value);
7577
return $this;
7678
}
7779

7880
/**
7981
* Ceil float
80-
* @return int
82+
* @return self
8183
*/
8284
public function ceil(): self
8385
{
84-
$this->value = ceil($this->float()->get());
86+
$this->float();
87+
$this->value = ceil($this->value);
8588
return $this;
8689
}
8790

@@ -91,7 +94,8 @@ public function ceil(): self
9194
*/
9295
public function toKb(): self
9396
{
94-
$this->value = round(($this->float()->get() / 1024), 2);
97+
$this->float();
98+
$this->value = round(($this->value / 1024), 2);
9599
return $this;
96100
}
97101

@@ -101,10 +105,13 @@ public function toKb(): self
101105
*/
102106
public function toFilesize(): self
103107
{
108+
$this->float();
104109
$precision = 2;
105-
$base = log($this->float()->get()) / log(1024);
110+
$base = log($this->value) / log(1024);
106111
$suffixes = array('', ' kb', ' mb', ' g', ' t');
107-
$this->value = round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
112+
$baseFloor = (int)floor($base);
113+
$suffix = (isset($suffixes[$baseFloor])) ? $suffixes[$baseFloor] : "";
114+
$this->value = round(pow(1024, $base - $baseFloor), $precision) . $suffix;
108115
return $this;
109116
}
110117

Format/Str.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function strVal(): string
3939
* Excerpt/shorten down text/string
4040
* @param integer $length total length
4141
* @param string $ending When break text add a ending (...)
42-
* @return string
42+
* @return self
4343
*/
4444
public function excerpt($length = 40, $ending = "..."): self
4545
{
@@ -55,7 +55,7 @@ public function excerpt($length = 40, $ending = "..."): self
5555

5656
/**
5757
* Convert new line to html <br>
58-
* @return [type] [description]
58+
* @return self
5959
*/
6060
public function nl2br(): self
6161
{
@@ -221,7 +221,7 @@ public function trimSpaces(): self
221221
*/
222222
public function formatSlug(): self
223223
{
224-
$this->clearBreaks("-")->trim()->replaceSpecialChar()->trimSpaces()->replaceSpaces("-")->tolower();
224+
$this->clearBreaks()->trim()->replaceSpecialChar()->trimSpaces()->replaceSpaces("-")->tolower();
225225
$this->value = preg_replace("/[^a-z0-9\s-]/", "", $this->value);
226226
return $this;
227227
}

Traverse.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,24 @@ public function getRaw()
8282

8383
/**
8484
* Callable factory
85-
* @return Callable
85+
* @psalm-suppress InvalidFunctionCall Psalm do not understand that $call is callable
86+
* @return mixed
8687
*/
87-
public function fetchFactory()
88+
/*
89+
public function fetchFactory(): mixed
8890
{
89-
return function ($arr, $row, $key, $index) {
91+
return function ($arr, $row, $_unusedKey, $index) {
9092
$data = array_values($this->raw);
91-
if (isset($data[$index])) {
92-
return $data[$index]($arr, $row);
93+
$call = (isset($data[$index])) ? $data[$index] : null;
94+
95+
if (is_callable($call)) {
96+
return $call($arr, $row);
9397
}
9498
return false;
9599
};
96100
}
97-
101+
*/
102+
98103
/**
99104
* Access incremental array
100105
* @param callable|null $callback Access array row in the callbacks argumnet 1
@@ -142,7 +147,7 @@ public function fetch(?callable $callback = null)
142147
*/
143148
public function equalTo(string $isVal): bool
144149
{
145-
return (bool)($this->row === $isVal);
150+
return ($this->row === $isVal);
146151
}
147152

148153
/**

0 commit comments

Comments
 (0)