Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP types #22

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ include, for example:
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I ran the full test suite before pushing the changes and all of the tests pass.
- [ ] I ran the full test suite before pushing the changes and all the tests pass.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- '8.4'
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 1
paths:
- src
ignoreErrors:
- '#Unsafe usage of new static\(\)#'
5 changes: 2 additions & 3 deletions src/Transformation/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class Action extends BaseAction
/**
* Action named constructor.
*
* @param string $genericActionString
* @param string|null $genericActionString Generic action as a string.
*
* @return BaseAction
*/
public static function generic($genericActionString = null)
public static function generic(?string $genericActionString = null): BaseAction
{
return (new static())->setGenericAction($genericActionString);
}
Expand Down
12 changes: 5 additions & 7 deletions src/Transformation/Adjustment/Addon/ViesusCorrect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class ViesusCorrect extends EffectQualifier
/**
* Enhances the image without correcting for red eye.
*/
const NO_REDEYE = 'no_redeye';
public const NO_REDEYE = 'no_redeye';

/**
* Enhances the image and also applies saturation to the skin tones in the image.
*/
const SKIN_SATURATION = 'skin_saturation';
public const SKIN_SATURATION = 'skin_saturation';

/**
* ViesusCorrect constructor.
Expand All @@ -46,9 +46,8 @@ public function __construct()
/**
* Enhances the image without correcting for red eye.
*
* @return ViesusCorrect
*/
public function noRedEye()
public function noRedEye(): static
{
$this->getValue()->setSimpleNamedValue('no', 'redeye');

Expand All @@ -58,12 +57,11 @@ public function noRedEye()
/**
* Enhances the image and also applies saturation to the skin tones in the image.
*
* @param int $level The enhancement level. A positive value boosts the saturation and a negative value
* @param int|null $level The enhancement level. A positive value boosts the saturation and a negative value
* reduces the saturation. (Range: -100 to 100, Server default: 50).
*
* @return ViesusCorrect
*/
public function skinSaturation($level = null)
public function skinSaturation(?int $level = null): static
{
if ($level) {
$this->getValue()->setSimpleNamedValue(self::SKIN_SATURATION, $level);
Expand Down
44 changes: 22 additions & 22 deletions src/Transformation/Adjustment/Adjust.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,33 @@
abstract class Adjust
{
// Common adjustments
const BRIGHTNESS = 'brightness';
const CONTRAST = 'contrast';
const SATURATION = 'saturation';
const GAMMA = 'gamma';
public const BRIGHTNESS = 'brightness';
public const CONTRAST = 'contrast';
public const SATURATION = 'saturation';
public const GAMMA = 'gamma';

// Image adjustments
const RED = 'red';
const GREEN = 'green';
const BLUE = 'blue';
const BRIGHTNESS_HSB = 'brightness_hsb';
const HUE = 'hue';
const TINT = 'tint';
const REPLACE_COLOR = 'replace_color';
const RECOLOR = 'recolor';
public const RED = 'red';
public const GREEN = 'green';
public const BLUE = 'blue';
public const BRIGHTNESS_HSB = 'brightness_hsb';
public const HUE = 'hue';
public const TINT = 'tint';
public const REPLACE_COLOR = 'replace_color';
public const RECOLOR = 'recolor';

const AUTO_BRIGHTNESS = 'auto_brightness';
const AUTO_COLOR = 'auto_color';
const AUTO_CONTRAST = 'auto_contrast';
const FILL_LIGHT = 'fill_light';
const IMPROVE = 'improve';
const VIBRANCE = 'vibrance';
const VIESUS_CORRECT = 'viesus_correct';
public const AUTO_BRIGHTNESS = 'auto_brightness';
public const AUTO_COLOR = 'auto_color';
public const AUTO_CONTRAST = 'auto_contrast';
public const FILL_LIGHT = 'fill_light';
public const IMPROVE = 'improve';
public const VIBRANCE = 'vibrance';
public const VIESUS_CORRECT = 'viesus_correct';

const SHARPEN = 'sharpen';
const UNSHARP_MASK = 'unsharp_mask';
public const SHARPEN = 'sharpen';
public const UNSHARP_MASK = 'unsharp_mask';

const OPACITY_THRESHOLD = 'opacity_threshold';
public const OPACITY_THRESHOLD = 'opacity_threshold';

use CommonAdjustmentTrait;
use ImageAdjustmentTrait;
Expand Down
30 changes: 12 additions & 18 deletions src/Transformation/Adjustment/CommonAdjustmentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,43 @@ trait CommonAdjustmentTrait
/**
* Adjusts the brightness.
*
* @param int $level The level of brightness (Range: -99 to 100, Server default: 80)
* @param int|null $level The level of brightness (Range: -99 to 100, Server default: 80)
*
* @return LevelEffectAction
*/
public static function brightness($level = null)
public static function brightness(?int $level = null): LevelEffectAction
{
return EffectAction::withLevel(Adjust::BRIGHTNESS, EffectRange::BRIGHTNESS, $level);
}

/**
* Adjusts the contrast.
*
* @param int $level The level of contrast (Range: -100 to 100, Server default: 0)
* @param int|null $level The level of contrast (Range: -100 to 100, Server default: 0)
*
* @return LevelEffectAction
*/
public static function contrast($level = null)
public static function contrast(?int $level = null): LevelEffectAction
{
return EffectAction::withLevel(Adjust::CONTRAST, EffectRange::DEFAULT_RANGE, $level);
}

/**
* Adjusts the color saturation.
*
* @param int $level The level of color saturation (Range: -100 to 100, Server default: 80).
* @param int|null $level The level of color saturation (Range: -100 to 100, Server default: 80).
*
* @return LevelEffectAction
*/
public static function saturation($level = null)
public static function saturation(?int $level = null): LevelEffectAction
{
return EffectAction::withLevel(Adjust::SATURATION, EffectRange::DEFAULT_RANGE, $level);
}

/**
* Adjusts the gamma level.
*
* @param int $level The level of gamma (Range: -50 to 150, Server default: 0).
* @param int|null $level The level of gamma (Range: -50 to 150, Server default: 0).
*
* @return LevelEffectAction
*/
public static function gamma($level = null)
public static function gamma(?int $level = null): LevelEffectAction
{
return EffectAction::withLevel(Adjust::GAMMA, EffectRange::SHIFTED_RANGE, $level);
}
Expand All @@ -72,11 +68,10 @@ public static function gamma($level = null)
*
* @see https://cloudinary.com/documentation/image_transformations#applying_3d_luts_to_images
*
* @param string $lutId The 3D LUT file id
* @param string|null $lutId The 3D LUT file id
*
* @return LutLayer
*/
public static function by3dLut($lutId = null)
public static function by3dLut(?string $lutId = null): LutLayer
{
return ClassUtils::verifyInstance($lutId, LutLayer::class);
}
Expand All @@ -87,12 +82,11 @@ public static function by3dLut($lutId = null)
* This is a generic way to apply an effect. For example, you could set $name to "gamma" and $args to 50, and this
* would have the same effect as calling gamma(50).
*
* @param string $name The effect name.
* @param string $name The effect name.
* @param mixed ...$args The qualifiers of the effect.
*
* @return EffectAction
*/
public static function generic($name, ...$args)
public static function generic(string $name, ...$args): EffectAction
{
return EffectAction::named($name, ...$args);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Transformation/Adjustment/FillLight.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FillLight extends BlendEffectQualifier
/**
* @var array $valueOrder The order of the values.
*/
protected $valueOrder = [0, 'value', 'bias'];
protected array $valueOrder = [0, 'value', 'bias'];

/**
* FillLight constructor.
Expand All @@ -40,11 +40,10 @@ public function __construct($blend = null, $bias = null)
/**
* Sets the bias.
*
* @param int $bias The bias to apply to the fill light effect (Range: -100 to 100, Server default: 0).
* @param ?int $bias The bias to apply to the fill light effect (Range: -100 to 100, Server default: 0).
*
* @return FillLight
*/
public function bias($bias)
public function bias(?int $bias): static
{
$this->getValue()->setSimpleValue('bias', $bias);

Expand Down
Loading
Loading