Skip to content

Commit c128a80

Browse files
committed
fix: prevent meaningless ratio calculation for zero height in EmbedCode
1 parent c14275a commit c128a80

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/EmbedCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(string $html, ?int $width = null, ?int $height = nul
1919
$this->width = $width;
2020
$this->height = $height;
2121

22-
if ($width !== null && $width !== 0 && $height !== null) {
22+
if ($width !== null && $width !== 0 && $height !== null && $height !== 0) {
2323
$this->ratio = round(($height / $width) * 100, 3);
2424
}
2525
}

tests/EmbedCodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function testRatioCalculationWithNullHeight()
3838

3939
public function testRatioCalculationWithZeroHeight()
4040
{
41-
// height=0 case (ratio becomes 0.0)
41+
// height=0 case (prevents meaningless ratio calculation)
4242
$code = new EmbedCode('<iframe></iframe>', 400, 0);
43-
$this->assertEquals(0.0, $code->ratio);
43+
$this->assertNull($code->ratio);
4444
}
4545

4646
public function testRatioCalculationWithBothZero()

0 commit comments

Comments
 (0)