Skip to content

Commit

Permalink
Merge pull request #7765 from ping-yee/230802-phpstan-image
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner authored Aug 6, 2023
2 parents 04b70af + 7ecc708 commit 2cc7ebe
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 80 deletions.
80 changes: 0 additions & 80 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -1196,71 +1196,6 @@
'count' => 1,
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forEXIFUnsupported\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forFileNotSupported\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forImageProcessFailed\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidDirection\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidImageCreate\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidImageLibraryPath\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forInvalidPath\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forMissingAngle\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forMissingImage\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Exceptions\\\\ImageException\\:\\:forSaveFailed\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Exceptions/ImageException.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:_text\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:ensureResource\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:reproportion\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Handlers/BaseHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Property CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:\\$image \\(CodeIgniter\\\\Images\\\\Image\\) in empty\\(\\) is not falsy\\.$#',
'count' => 1,
Expand All @@ -1271,21 +1206,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Images/Handlers/ImageMagickHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\ImageMagickHandler\\:\\:_text\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Handlers/ImageMagickHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\ImageMagickHandler\\:\\:ensureResource\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Handlers/ImageMagickHandler.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Images\\\\Handlers\\\\ImageMagickHandler\\:\\:supportedFormatCheck\\(\\) has no return type specified\\.$#',
'count' => 1,
'path' => __DIR__ . '/system/Images/Handlers/ImageMagickHandler.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc type string\\|null of property CodeIgniter\\\\Images\\\\Handlers\\\\ImageMagickHandler\\:\\:\\$resource is not covariant with PHPDoc type resource\\|null of overridden property CodeIgniter\\\\Images\\\\Handlers\\\\BaseHandler\\:\\:\\$resource\\.$#',
'count' => 1,
Expand Down
50 changes: 50 additions & 0 deletions system/Images/Exceptions/ImageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,101 @@

class ImageException extends FrameworkException implements ExceptionInterface
{
/**
* Thrown when the image is not found.
*
* @return static
*/
public static function forMissingImage()
{
return new static(lang('Images.sourceImageRequired'));
}

/**
* Thrown when the file specific is not following the role.
*
* @return static
*/
public static function forFileNotSupported()
{
return new static(lang('Images.fileNotSupported'));
}

/**
* Thrown when the angle is undefined.
*
* @return static
*/
public static function forMissingAngle()
{
return new static(lang('Images.rotationAngleRequired'));
}

/**
* Thrown when the direction property is invalid.
*
* @return static
*/
public static function forInvalidDirection(?string $dir = null)
{
return new static(lang('Images.invalidDirection', [$dir]));
}

/**
* Thrown when the path property is invalid.
*
* @return static
*/
public static function forInvalidPath()
{
return new static(lang('Images.invalidPath'));
}

/**
* Thrown when the EXIF function is not supported.
*
* @return static
*/
public static function forEXIFUnsupported()
{
return new static(lang('Images.exifNotSupported'));
}

/**
* Thrown when the image specific is invalid.
*
* @return static
*/
public static function forInvalidImageCreate(?string $extra = null)
{
return new static(lang('Images.unsupportedImageCreate') . ' ' . $extra);
}

/**
* Thrown when the image save failed.
*
* @return static
*/
public static function forSaveFailed()
{
return new static(lang('Images.saveFailed'));
}

/**
* Thrown when the image library path is invalid.
*
* @return static
*/
public static function forInvalidImageLibraryPath(?string $path = null)
{
return new static(lang('Images.libPathInvalid', [$path]));
}

/**
* Thrown when the image process failed.
*
* @return static
*/
public static function forImageProcessFailed()
{
return new static(lang('Images.imageProcessFailed'));
Expand Down
6 changes: 6 additions & 0 deletions system/Images/Handlers/BaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function withFile(string $path)

/**
* Make the image resource object if needed
*
* @return void
*/
abstract protected function ensureResource();

Expand Down Expand Up @@ -422,6 +424,8 @@ public function text(string $text, array $options = [])

/**
* Handler-specific method for overlaying text on an image.
*
* @return void
*/
abstract protected function _text(string $text, array $options = []);

Expand Down Expand Up @@ -722,6 +726,8 @@ public function __call(string $name, array $args = [])
*
* This function lets us re-proportion the width/height
* if users choose to maintain the aspect ratio when resizing.
*
* @return void
*/
protected function reproportion()
{
Expand Down
6 changes: 6 additions & 0 deletions system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ protected function getResourcePath()
/**
* Make the image resource object if needed
*
* @return void
*
* @throws Exception
*/
protected function ensureResource()
Expand All @@ -302,6 +304,8 @@ protected function ensureResource()
/**
* Check if given image format is supported
*
* @return void
*
* @throws ImageException
*/
protected function supportedFormatCheck()
Expand All @@ -318,6 +322,8 @@ protected function supportedFormatCheck()
/**
* Handler-specific method for overlaying text on an image.
*
* @return void
*
* @throws Exception
*/
protected function _text(string $text, array $options = [])
Expand Down

0 comments on commit 2cc7ebe

Please sign in to comment.