Skip to content

Commit

Permalink
Merge pull request #16 from vormkracht10/static-analysis
Browse files Browse the repository at this point in the history
Static analysis
  • Loading branch information
Baspa committed Sep 26, 2022
2 parents a97b920 + 24a0e2b commit 5962e89
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 20 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PHPStan

on: [push, pull_request]

jobs:
phpstan:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}

- name: Run composer install
run: composer install -n --prefer-dist

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"pestphp/pest": "^1.21",
"phpstan/phpstan": "^1.8",
"spatie/ray": "^1.28"
},
"autoload": {
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:

paths:
- src/

# Level 9 is the highest level
level: 5

# ignoreErrors:
# - '#PHPDoc tag @var#'
#
# excludePaths:
# - ./*/*/FileToBeExcluded.php
#
# checkMissingIterableValueType: false
30 changes: 16 additions & 14 deletions src/Transformations.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

class Transformations
{
protected array $transformations = [];

/**
* Downscales an image proportionally to fit the given width and height in pixels.
*
Expand Down Expand Up @@ -98,10 +100,10 @@ public function crop(int|string $width, int|string $height, int|string $offsetX
*
* @param string $ratio two numbers greater than zero separated by :
* @param int|string $offsetX horizontal and vertical offsets in pixels or percents or shortcuts.
* @param int $offsetY horizontal and vertical offsets in percents.
* @param string|null $offsetY horizontal and vertical offsets in percents.
* @return self
*/
public function cropByRatio(string $ratio, int|string $offsetX = null, int|string $offsetY = null): self
public function cropByRatio(string $ratio, int|string $offsetX = null, string|null $offsetY = null): self
{
$this->transformations['crop_by_ratio'] = CropByRatio::transform($ratio, $offsetX, $offsetY);

Expand All @@ -114,12 +116,12 @@ public function cropByRatio(string $ratio, int|string $offsetX = null, int|strin
* @param string $tag one of the tags.
* @param string $ratio two numbers greater than zero separated by :
* @param string $width in percentages e.g. 50p.
* @param string $heigt in percentages e.g. 50p.
* @param string $offsetX horizontal and vertical offsets in percents or shortcuts.
* @param string $offsetY horizontal and vertical offsets in percents.
* @param string $height in percentages e.g. 50p.
* @param int|string $offsetX horizontal and vertical offsets in percents or shortcuts.
* @param string|null $offsetY horizontal and vertical offsets in percents.
* @return self
*/
public function cropByObjects(string $tag, string $ratio = null, string $width = null, string $height = null, int|string $offsetX = null, string $offsetY = null): self
public function cropByObjects(string $tag, string $ratio = null, string $width = null, string $height = null, int|string $offsetX = null, string|null $offsetY = null): self
{
$this->transformations['crop_by_objects'] = CropByObjects::transform($tag, $ratio, $width, $height, $offsetX, $offsetY);

Expand All @@ -131,11 +133,11 @@ public function cropByObjects(string $tag, string $ratio = null, string $width =
*
* @param int $width in pixels.
* @param int $height in pixels.
* @param int $offsetX horizontal and vertical offsets in percents or shortcuts.
* @param int|null $offsetY horizontal and vertical offsets in percents.
* @param string $offsetX horizontal and vertical offsets in percents or shortcuts.
* @param string|null $offsetY horizontal and vertical offsets in percents.
* @return self
*/
public function scaleCrop(int $width, int $height, string $offsetX = null, $offsetY = null): self
public function scaleCrop(int $width, int $height, string $offsetX = null, string|null $offsetY = null): self
{
$this->transformations['scale_crop'] = ScaleCrop::transform($width, $height, $offsetX, $offsetY);

Expand All @@ -148,11 +150,11 @@ public function scaleCrop(int $width, int $height, string $offsetX = null, $offs
* @param int $width in pixels.
* @param int $height in pixels.
* @param string $type one of the types.
* @param int $offsetX horizontal and vertical offsets in percents or shortcuts.
* @param int|null $offsetY horizontal and vertical offsets in percents.
* @param string $offsetX horizontal and vertical offsets in percents or shortcuts.
* @param string|null $offsetY horizontal and vertical offsets in percents.
* @return self
*/
public function smartCrop(int $width, int $height, string $type, string $offsetX = null, string $offsetY = null): self
public function smartCrop(int $width, int $height, string $type, string $offsetX = null, string|null $offsetY = null): self
{
$this->transformations['smart_crop'] = SmartCrop::transform($width, $height, $type, $offsetX, $offsetY);

Expand All @@ -175,7 +177,7 @@ public function setFill(string $color): self
/**
* Sets the object's size in the image from 1 to 100.
*
* @param string integer between 1 and 100.
* @param int $zoom integer between 1 and 100.
* @return self
*/
public function zoomObjects(int $zoom): self
Expand Down Expand Up @@ -377,7 +379,7 @@ public function sharpen(int $strength = null): self
/**
* The default behavior goes with parsing EXIF tags of original images and rotating them according to the “Orientation” tag.
*
* @param int $angle
* @param bool $rotate
* @return self
*/
public function autoRotate(bool $rotate): self
Expand Down
4 changes: 2 additions & 2 deletions src/Transformations/BasicColorAdjustments.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public static function validate(string $key, ...$args): bool
return $value >= -100 && $value <= 100;
default:
return false;

break;
}
}

return false;
}

public static function generateUrl(string $url, array $values): string
Expand Down
2 changes: 1 addition & 1 deletion src/Transformations/SmartCrop.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function validate(string $key, ...$args): bool
}

if ($key === self::TYPE) {
return CropType::tryFrom($value);
return CropType::tryFrom($value) !== null;
}

return false;
Expand Down
5 changes: 2 additions & 3 deletions src/UploadcareTransformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class UploadcareTransformation extends Transformations
{
protected string $uuid;
protected array $transformations = [];
protected string $url;
protected string $baseUrl;
protected ?string $filename = null;
Expand All @@ -18,7 +17,7 @@ public function __construct(string $uuid, string $cdnUrl = 'https://ucarecdn.com
$this->baseUrl = $cdnUrl;
}

public function filename(string $filename)
public function filename(string $filename): string
{
$this->filename = $filename;

Expand Down Expand Up @@ -56,7 +55,7 @@ public function getUrl(): string
return $url;
}

public function __toString()
public function __toString(): string
{
return $this->getUrl();
}
Expand Down

0 comments on commit 5962e89

Please sign in to comment.