forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create DecimalSize (phpmyadmin#19044)
* Remove duplicated comment Signed-off-by: Kamil Tekiela <[email protected]> * Simplify getDecimalSize Signed-off-by: Kamil Tekiela <[email protected]> * Create DecimalSize Signed-off-by: Kamil Tekiela <[email protected]> * Refactor detectSize() Signed-off-by: Kamil Tekiela <[email protected]> * Remove unhelpful docbloc for detectType Signed-off-by: Kamil Tekiela <[email protected]> * Break too long line Signed-off-by: Kamil Tekiela <[email protected]> * Remove dead constants Signed-off-by: Kamil Tekiela <[email protected]> --------- Signed-off-by: Kamil Tekiela <[email protected]>
- Loading branch information
1 parent
2e52bdd
commit 93cef12
Showing
5 changed files
with
100 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Import; | ||
|
||
use Stringable; | ||
|
||
use function mb_strlen; | ||
use function mb_strpos; | ||
|
||
final class DecimalSize implements Stringable | ||
{ | ||
private function __construct(public readonly int $precision, public readonly int $scale) | ||
{ | ||
} | ||
|
||
public static function fromCell(string $cell): self | ||
{ | ||
$precision = mb_strlen($cell) - 1; | ||
|
||
return new self( | ||
$precision, | ||
$precision - (int) mb_strpos($cell, '.'), | ||
); | ||
} | ||
|
||
public static function fromPrecisionAndScale(int $precision, int $scale): self | ||
{ | ||
return new self($precision, $scale); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->precision . ',' . $this->scale; | ||
} | ||
} |
Oops, something went wrong.