Skip to content

Commit 26b1f15

Browse files
committed
Clean up constructor methods and improve image size retrieval error handling
1 parent eeb8cdd commit 26b1f15

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/LaravelShortcodePlus.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
final class LaravelShortcodePlus
2424
{
25-
public function __construct(protected string $content = '') {}
25+
public function __construct(protected string $content = '')
26+
{
27+
}
2628

2729
public static function source(string $source): LaravelShortcodePlus
2830
{

src/LaravelShortcodePlusServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function configurePackage(Package $package): void
4343
->hasMigration('create_laravel-shortcode-plus_table');
4444
}
4545

46-
public function packageRegistered() {}
46+
public function packageRegistered()
47+
{
48+
}
4749

4850
public function packageBooted(): void
4951
{

src/Shortcodes/PhotoShortcode.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public function register($shortcode): string
9595
*/
9696
public static function getImageHeight(string $path, int $width = 0): float|int
9797
{
98-
9998
$localPath = storage_path('app/public/'.$path);
10099

101100
// Check if file exists
@@ -106,6 +105,12 @@ public static function getImageHeight(string $path, int $width = 0): float|int
106105
// Get image sizes
107106
$sizes = [];
108107
$imageSizes = @getimagesize($localPath);
108+
109+
// Check if getimagesize was successful
110+
if ($imageSizes === false) {
111+
return 0;
112+
}
113+
109114
$sizes['width'] = $imageSizes[0];
110115
$sizes['height'] = $imageSizes[1];
111116

0 commit comments

Comments
 (0)