Skip to content

Commit

Permalink
Create DecimalSize (phpmyadmin#19044)
Browse files Browse the repository at this point in the history
* 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
kamil-tekiela authored Mar 12, 2024
1 parent 2e52bdd commit 93cef12
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 288 deletions.
32 changes: 11 additions & 21 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8550,6 +8550,16 @@ parameters:
count: 1
path: src/Import/Ajax.php

-
message: "#^Cannot access property \\$precision on int\\|PhpMyAdmin\\\\Import\\\\DecimalSize\\.$#"
count: 5
path: src/Import/Import.php

-
message: "#^Cannot access property \\$scale on int\\|PhpMyAdmin\\\\Import\\\\DecimalSize\\.$#"
count: 5
path: src/Import/Import.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 6
Expand All @@ -8575,11 +8585,6 @@ parameters:
count: 1
path: src/Import/Import.php

-
message: "#^Method PhpMyAdmin\\\\Import\\\\Import\\:\\:detectSize\\(\\) should return int\\|string but returns mixed\\.$#"
count: 3
path: src/Import/Import.php

-
message: "#^Method PhpMyAdmin\\\\Import\\\\Import\\:\\:getNextChunk\\(\\) should return bool\\|string but returns mixed\\.$#"
count: 1
Expand Down Expand Up @@ -8611,25 +8616,10 @@ parameters:
path: src/Import/Import.php

-
message: "#^Only numeric types are allowed in \\+, int\\<0, max\\>\\|false given on the left side\\.$#"
message: "#^Parameter \\#1 \\$precision of static method PhpMyAdmin\\\\Import\\\\DecimalSize\\:\\:fromPrecisionAndScale\\(\\) expects int, int\\|PhpMyAdmin\\\\Import\\\\DecimalSize given\\.$#"
count: 1
path: src/Import/Import.php

-
message: "#^Only numeric types are allowed in \\-, int\\<0, max\\>\\|false given on the right side\\.$#"
count: 2
path: src/Import/Import.php

-
message: "#^Parameter \\#1 \\$lastCumulativeSize of method PhpMyAdmin\\\\Import\\\\Import\\:\\:getDecimalPrecision\\(\\) expects string, int\\|string given\\.$#"
count: 3
path: src/Import/Import.php

-
message: "#^Parameter \\#1 \\$lastCumulativeSize of method PhpMyAdmin\\\\Import\\\\Import\\:\\:getDecimalScale\\(\\) expects string, int\\|string given\\.$#"
count: 2
path: src/Import/Import.php

-
message: "#^Parameter \\#1 \\$separator of function explode expects non\\-empty\\-string, mixed given\\.$#"
count: 1
Expand Down
30 changes: 8 additions & 22 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6404,35 +6404,23 @@
<code><![CDATA[$active]]></code>
<code><![CDATA[$cellValue]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[string|int]]></code>
</MixedInferredReturnType>
<MixedOperand>
<code><![CDATA[$size[self::D]]]></code>
<code><![CDATA[ImportSettings::$maximumTime]]></code>
<code><![CDATA[max($size[self::D], $oldD)]]></code>
<code><![CDATA[max($size[self::M], $oldM)]]></code>
</MixedOperand>
<MixedReturnStatement>
<code><![CDATA[$size[self::FULL]]]></code>
<code><![CDATA[$size[self::FULL]]]></code>
<code><![CDATA[$size[self::M]]]></code>
</MixedReturnStatement>
<PossiblyFalseOperand>
<code><![CDATA[$decPos]]></code>
<code><![CDATA[strpos($lastCumulativeSize, ',')]]></code>
<code><![CDATA[strpos($lastCumulativeSize, ',')]]></code>
</PossiblyFalseOperand>
<PossiblyInvalidArgument>
<code><![CDATA[$lastCumulativeSize]]></code>
<code><![CDATA[$lastCumulativeSize]]></code>
<code><![CDATA[$lastCumulativeSize]]></code>
<code><![CDATA[$lastCumulativeSize]]></code>
<code><![CDATA[$lastCumulativeSize]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidCast>
<code><![CDATA[$sqlDelimiter]]></code>
</PossiblyInvalidCast>
<PossiblyInvalidPropertyFetch>
<code><![CDATA[$lastCumulativeSize->precision]]></code>
<code><![CDATA[$lastCumulativeSize->precision]]></code>
<code><![CDATA[$lastCumulativeSize->precision]]></code>
<code><![CDATA[$lastCumulativeSize->scale]]></code>
<code><![CDATA[$lastCumulativeSize->scale]]></code>
<code><![CDATA[$lastCumulativeSize->scale]]></code>
</PossiblyInvalidPropertyFetch>
<RedundantCondition>
<code><![CDATA[$GLOBALS['result'] == false]]></code>
</RedundantCondition>
Expand Down Expand Up @@ -13818,8 +13806,6 @@
<code><![CDATA[provDetectType]]></code>
<code><![CDATA[provGetColumnAlphaName]]></code>
<code><![CDATA[provGetColumnNumberFromName]]></code>
<code><![CDATA[provGetDecimalPrecision]]></code>
<code><![CDATA[provGetDecimalScale]]></code>
<code><![CDATA[provGetDecimalSize]]></code>
<code><![CDATA[providerContentWithByteOrderMarks]]></code>
</PossiblyUnusedMethod>
Expand Down
37 changes: 37 additions & 0 deletions src/Import/DecimalSize.php
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;
}
}
Loading

0 comments on commit 93cef12

Please sign in to comment.