1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Fix missing phpdoc and configure phpstan

This commit is contained in:
Vincent Langlet
2024-02-29 10:19:45 +01:00
parent ba39c13d2b
commit 1ed31f3cdf
10 changed files with 47 additions and 17 deletions

View File

@@ -99,7 +99,7 @@ jobs:
run: vendor/bin/phpunit --no-coverage
- name: Run analyzer
run: vendor/bin/phpstan analyze --level=4 ./src
run: vendor/bin/phpstan
- name: Validate coding standards
run: vendor/bin/phpcs

20
phpstan.dist.neon Normal file
View File

@@ -0,0 +1,20 @@
parameters:
level: 4
paths:
- src
exceptions:
check:
missingCheckedExceptionInThrows: true
uncheckedExceptionClasses:
- Intervention\Image\Exceptions\AnimationException
- Intervention\Image\Exceptions\ColorException
- Intervention\Image\Exceptions\DriverException
- Intervention\Image\Exceptions\GeometryException
- Intervention\Image\Exceptions\FontException
- Intervention\Image\Exceptions\InputException
- Intervention\Image\Exceptions\NotSupportedException
- Intervention\Image\Exceptions\NotWritableException
- ImagickException
- ImagickDrawException
- ImagickPixelException
- Error

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Intervention\Image;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\CollectionInterface;
use ArrayIterator;
use Countable;
@@ -198,10 +197,6 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
*/
public function slice(int $offset, ?int $length = null): CollectionInterface
{
if ($offset >= count($this->items)) {
throw new RuntimeException('Offset exceeds the maximum value.');
}
$this->items = array_slice($this->items, $offset, $length);
return $this;

View File

@@ -20,6 +20,9 @@ abstract class AbstractDrawModifier extends DriverSpecialized implements Modifie
return $this->drawable->position();
}
/**
* @throws DecoderException
*/
public function backgroundColor(): ColorInterface
{
try {
@@ -31,6 +34,9 @@ abstract class AbstractDrawModifier extends DriverSpecialized implements Modifie
return $color;
}
/**
* @throws DecoderException
*/
public function borderColor(): ColorInterface
{
try {

View File

@@ -6,7 +6,7 @@ namespace Intervention\Image\Drivers\Gd;
use Intervention\Image\Drivers\AbstractDriver;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorProcessorInterface;
@@ -36,7 +36,7 @@ class Driver extends AbstractDriver
public function checkHealth(): void
{
if (!extension_loaded('gd') || !function_exists('gd_info')) {
throw new RuntimeException(
throw new DriverException(
'GD PHP extension must be installed to use this driver.'
);
}

View File

@@ -43,7 +43,11 @@ class GifEncoder extends DriverSpecializedEncoder
);
}
$builder->setLoops($image->loops());
try {
$builder->setLoops($image->loops());
} catch (\Exception $e) {
throw new EncoderException($e->getMessage(), $e->getCode(), $e);
}
return new EncodedImage($builder->encode(), 'image/gif');
}

View File

@@ -9,7 +9,6 @@ use ImagickException;
use Iterator;
use Intervention\Image\Interfaces\CoreInterface;
use Intervention\Image\Exceptions\AnimationException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\CollectionInterface;
use Intervention\Image\Interfaces\FrameInterface;
@@ -98,10 +97,6 @@ class Core implements CoreInterface, Iterator
*/
public function slice(int $offset, ?int $length = null): CollectionInterface
{
if ($offset >= $this->count()) {
throw new RuntimeException('Offset exceeds the maximum value.');
}
$allowed_indexes = [];
$length = is_null($length) ? $this->count() : $length;
for ($i = $offset; $i < $offset + $length; $i++) {

View File

@@ -8,7 +8,7 @@ use Imagick;
use ImagickPixel;
use Intervention\Image\Drivers\AbstractDriver;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Image;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ColorProcessorInterface;
@@ -38,7 +38,7 @@ class Driver extends AbstractDriver
public function checkHealth(): void
{
if (!extension_loaded('imagick') || !class_exists('Imagick')) {
throw new RuntimeException(
throw new DriverException(
'Imagick PHP extension must be installed to use this driver.'
);
}

View File

@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Exceptions;
class DriverException extends RuntimeException
{
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Intervention\Image\Interfaces;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\RuntimeException;
interface DriverInterface
@@ -78,7 +79,7 @@ interface DriverInterface
* Check whether all requirements for operating the driver are met and
* throw exception if the check fails.
*
* @throws RuntimeException
* @throws DriverException
* @return void
*/
public function checkHealth(): void;