Skip to content

Commit

Permalink
Improve code for phpstan level 6
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed May 2, 2024
1 parent 2558e6c commit 42a8404
Show file tree
Hide file tree
Showing 31 changed files with 279 additions and 31 deletions.
8 changes: 3 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

root = true

[*]
[*.php]
indent_size = 4
indent_style = space
indent_size = 2
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.php]
indent_size = 4
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
/.editorconfig export-ignore
/phpunit.xml export-ignore
/phpcs.xml export-ignore
/phpstan.dist.neon export-ignore
/docker-compose.yml export-ignore
/Dockerfile export-ignore
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
analysis:
build: ./
working_dir: /project
command: bash -c "composer install && ./vendor/bin/phpstan analyze --level=4 ./src"
command: bash -c "composer install && ./vendor/bin/phpstan analyze ./src"
volumes:
- ./:/project
standards:
Expand Down
12 changes: 12 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
level: 6
paths:
- src
exceptions:
check:
missingCheckedExceptionInThrows: true
uncheckedExceptionClasses:
- ImagickException
- ImagickDrawException
- ImagickPixelException
- Error
2 changes: 2 additions & 0 deletions src/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Intervention\Gif;

use Intervention\Gif\Exceptions\EncoderException;
use Intervention\Gif\Traits\CanDecode;
use Intervention\Gif\Traits\CanEncode;
use ReflectionClass;
Expand All @@ -28,6 +29,7 @@ public static function getShortClassname(): string
/**
* Cast object to string
*
* @throws EncoderException
* @return string
*/
public function __toString(): string
Expand Down
35 changes: 34 additions & 1 deletion src/Blocks/ApplicationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,74 @@ class ApplicationExtension extends AbstractExtension
/**
* Data Sub Blocks
*
* @var array
* @var array<DataSubBlock>
*/
protected array $blocks = [];

/**
* Get size of block
*
* @return int
*/
public function getBlockSize(): int
{
return strlen($this->application);
}

/**
* Set application name
*
* @param string $value
* @return ApplicationExtension
*/
public function setApplication(string $value): self
{
$this->application = $value;

return $this;
}

/**
* Get application name
*
* @return string
*/
public function getApplication(): string
{
return $this->application;
}

/**
* Add block to application extension
*
* @param DataSubBlock $block
* @return ApplicationExtension
*/
public function addBlock(DataSubBlock $block): self
{
$this->blocks[] = $block;

return $this;
}

/**
* Set data sub blocks of instance
*
* @param array<DataSubBlock> $blocks
* @return ApplicationExtension
*/
public function setBlocks(array $blocks): self
{
$this->blocks = $blocks;

return $this;
}

/**
* Get blocks of ApplicationExtension
*
* @return array<DataSubBlock>
*/
public function getBlocks(): array
{
return $this->blocks;
Expand Down
9 changes: 6 additions & 3 deletions src/Blocks/ColorTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ColorTable extends AbstractEntity
/**
* Create new instance
*
* @param array $colors
* @param array<Color> $colors
* @return void
*/
public function __construct(protected array $colors = [])
Expand All @@ -21,7 +21,7 @@ public function __construct(protected array $colors = [])
/**
* Return array of current colors
*
* @return array
* @return array<Color>
*/
public function getColors(): array
{
Expand All @@ -34,6 +34,7 @@ public function getColors(): array
* @param int $r
* @param int $g
* @param int $b
* @return self
*/
public function addRgb(int $r, int $g, int $b): self
{
Expand All @@ -46,6 +47,7 @@ public function addRgb(int $r, int $g, int $b): self
* Add color to table
*
* @param Color $color
* @return self
*/
public function addColor(Color $color): self
{
Expand All @@ -57,7 +59,8 @@ public function addColor(Color $color): self
/**
* Reset colors to array of color objects
*
* @param array $colors
* @param array<Color> $colors
* @return self
*/
public function setColors(array $colors): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/CommentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CommentExtension extends AbstractExtension
/**
* Comment blocks
*
* @var array
* @var array<string>
*/
protected array $comments = [];

Expand Down
17 changes: 17 additions & 0 deletions src/Blocks/DataSubBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

class DataSubBlock extends AbstractEntity
{
/**
* Create new instance
*
* @param string $value
* @throws FormatException
* @return void
*/
public function __construct(protected string $value)
{
if ($this->getSize() > 255) {
Expand All @@ -18,11 +25,21 @@ public function __construct(protected string $value)
}
}

/**
* Return size of current block
*
* @return int
*/
public function getSize(): int
{
return strlen($this->value);
}

/**
* Return block value
*
* @return string
*/
public function getValue(): string
{
return $this->value;
Expand Down

0 comments on commit 42a8404

Please sign in to comment.