diff --git a/README.md b/README.md index 2f3ed15..5362ece 100644 --- a/README.md +++ b/README.md @@ -1285,7 +1285,7 @@ In **Couleur**, the `Css` color space refers to the **named colors** according - **Dedicated functions** namespace : `matthieumastadenis\couleur\utils\hexRgb` ; - **Accepted aliases** : `hex`, `hexrgb`, `hex-rgb`, `hex_rgb`, `hexadecimal` ; - **Coordinates** : `red`, `green`, `blue` ; - + ### HSL - **ColorSpace** case: `ColorSpace::Hsl` ; @@ -1293,7 +1293,7 @@ In **Couleur**, the `Css` color space refers to the **named colors** according - **Dedicated functions** namespace : `matthieumastadenis\couleur\utils\hsl` ; - **Accepted aliases** : `hsl`, `hsla` ; - **Coordinates** : `hue`, `saturation`, `lightness` ; - + ### HSV - **ColorSpace** case: `ColorSpace::Hsv` ; @@ -1301,7 +1301,7 @@ In **Couleur**, the `Css` color space refers to the **named colors** according - **Dedicated functions** namespace : `matthieumastadenis\couleur\utils\hsv` ; - **Accepted aliases** : `hsv`, `hsb` ; - **Coordinates** : `hue`, `saturation`, `value` ; - + ### HWB - **ColorSpace** case: `ColorSpace::Hwb` ; diff --git a/phpunit.xml b/phpunit.xml index b2a20b5..2334db8 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,11 +1,11 @@ - + src/tests diff --git a/src/Color.php b/src/Color.php index cae024b..a29457c 100644 --- a/src/Color.php +++ b/src/Color.php @@ -21,12 +21,12 @@ use matthieumastadenis\couleur\colors\XyzD65; /** - * An immutable object representing a color expressed in a precise and supported color space. - * + * An immutable object representing a color expressed in a precise and supported color space. + * * It can be converted to another supported color space using one of the to...() methods. - * Variant instances can be created with the change() method. - * - * This class is abstract so it can not be instanciated directly. + * Variant instances can be created with the change() method. + * + * This class is abstract so it can not be instanciated directly. * It is inherited by all classes in the matthieumastadenis\couleur\colors namespace. */ abstract class Color { @@ -47,7 +47,7 @@ public function __toString( /* #endregion */ - /* #region Public Static Methods */ + /* #region Public Static Methods */ /** * Returns the ColorSpace instance corresponding to the current color. @@ -62,7 +62,7 @@ public static function space( /* #endregion */ - /* #region Public Methods */ + /* #region Public Methods */ /** * Returns an array containing all coordinates of the current color. @@ -85,15 +85,15 @@ public function stringify( ) :string { return \implode(', ', $this->coordinates()); - } - + } + /** * Returns a new ColorInterface instance corresponding to the current color converted into the $to color space. * * @param ColorSpace|\Stringable|string|null $to The desired output color space (can be an instance of the ColorSpace enum or a stringable alias) * @param ColorInterface|null $fallback A ColorInterface instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return ColorInterface The converted color object */ public function to( @@ -115,7 +115,7 @@ public function to( * * @param Css|null $fallback A colors\Css instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Css The converted color object */ public function toCss( @@ -134,7 +134,7 @@ public function toCss( * * @param HexRgb|null $fallback A colors\HexRgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return HexRgb The converted color object */ public function toHexRgb( @@ -153,7 +153,7 @@ public function toHexRgb( * * @param Hsl|null $fallback A colors\Hsl instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hsl The converted color object */ public function toHsl( @@ -172,7 +172,7 @@ public function toHsl( * * @param Hsv|null $fallback A colors\Hsv instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hsv The converted color object */ public function toHsv( @@ -191,7 +191,7 @@ public function toHsv( * * @param Hwb|null $fallback A colors\Hwb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hwb The converted color object */ public function toHwb( @@ -210,7 +210,7 @@ public function toHwb( * * @param Lab|null $fallback A colors\Lab instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Lab The converted color object */ public function toLab( @@ -229,7 +229,7 @@ public function toLab( * * @param Lch|null $fallback A colors\Lch instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Lch The converted color object */ public function toLch( @@ -248,7 +248,7 @@ public function toLch( * * @param LinP3|null $fallback A colors\LinP3 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinP3 The converted color object */ public function toLinP3( @@ -267,7 +267,7 @@ public function toLinP3( * * @param LinProPhoto|null $fallback A colors\LinProPhoto instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinProPhoto The converted color object */ public function toLinProPhoto( @@ -286,7 +286,7 @@ public function toLinProPhoto( * * @param LinRgb|null $fallback A colors\LinRgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinRgb The converted color object */ public function toLinRgb( @@ -305,7 +305,7 @@ public function toLinRgb( * * @param OkLab|null $fallback A colors\OkLab instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return OkLab The converted color object */ public function toOkLab( @@ -324,7 +324,7 @@ public function toOkLab( * * @param OkLch|null $fallback A colors\OkLch instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return OkLch The converted color object */ public function toOkLch( @@ -343,7 +343,7 @@ public function toOkLch( * * @param P3|null $fallback A colors\P3 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return P3 The converted color object */ public function toP3( @@ -362,7 +362,7 @@ public function toP3( * * @param ProPhoto|null $fallback A colors\ProPhoto instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return ProPhoto The converted color object */ public function toProPhoto( @@ -381,7 +381,7 @@ public function toProPhoto( * * @param Rgb|null $fallback A colors\Rgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Rgb The converted color object */ public function toRgb( @@ -400,7 +400,7 @@ public function toRgb( * * @param XyzD50|null $fallback A colors\XyzD50 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return XyzD50 The converted color object */ public function toXyzD50( @@ -419,7 +419,7 @@ public function toXyzD50( * * @param XyzD65|null $fallback A colors\XyzD65 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return XyzD65 The converted color object */ public function toXyzD65( @@ -434,5 +434,5 @@ public function toXyzD65( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/ColorFactory.php b/src/ColorFactory.php index 57887db..afa9478 100644 --- a/src/ColorFactory.php +++ b/src/ColorFactory.php @@ -23,17 +23,17 @@ abstract class ColorFactory { - /* #region Public Static Methods */ + /* #region Public Static Methods */ /** - * Returns a new ColorInterface instance corresponding to $value. + * Returns a new ColorInterface instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $to The desired output color space (if not specified it will be the same as $from) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param ColorInterface|null $fallback A ColorInterface instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return ColorInterface|null */ public static function new( @@ -48,8 +48,8 @@ public static function new( utils\setFromAndTo( value : $value, to : $to, - from : $from, - throw : $throw, + from : $from, + throw : $throw, ); if (!($from instanceof ColorSpace) @@ -67,13 +67,13 @@ public static function new( } /** - * Returns a new colors\Css instance corresponding to $value. + * Returns a new colors\Css instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Css|null $fallback A colors\Css instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Css|null */ public static function newCss( @@ -92,13 +92,13 @@ public static function newCss( } /** - * Returns a new colors\HexRgb instance corresponding to $value. + * Returns a new colors\HexRgb instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param HexRgb|null $fallback A colors\HexRgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return HexRgb|null */ public static function newHexRgb( @@ -117,13 +117,13 @@ public static function newHexRgb( } /** - * Returns a new colors\Hsl instance corresponding to $value. + * Returns a new colors\Hsl instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Hsl|null $fallback A colors\Hsl instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hsl|null */ public static function newHsl( @@ -142,13 +142,13 @@ public static function newHsl( } /** - * Returns a new colors\Hsv instance corresponding to $value. + * Returns a new colors\Hsv instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Hsv|null $fallback A colors\Hsv instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hsv|null */ public static function newHsv( @@ -167,13 +167,13 @@ public static function newHsv( } /** - * Returns a new colors\Hwb instance corresponding to $value. + * Returns a new colors\Hwb instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Hwb|null $fallback A colors\Hwb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hwb|null */ public static function newHwb( @@ -192,13 +192,13 @@ public static function newHwb( } /** - * Returns a new colors\Lab instance corresponding to $value. + * Returns a new colors\Lab instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Lab|null $fallback A colors\Lab instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Lab|null */ public static function newLab( @@ -217,13 +217,13 @@ public static function newLab( } /** - * Returns a new colors\Lch instance corresponding to $value. + * Returns a new colors\Lch instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Lch|null $fallback A colors\Lch instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Lch|null */ public static function newLch( @@ -242,13 +242,13 @@ public static function newLch( } /** - * Returns a new colors\LinP3 instance corresponding to $value. + * Returns a new colors\LinP3 instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param LinP3|null $fallback A colors\LinP3 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinP3|null */ public static function newLinP3( @@ -267,13 +267,13 @@ public static function newLinP3( } /** - * Returns a new colors\LinProPhoto instance corresponding to $value. + * Returns a new colors\LinProPhoto instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param LinProPhoto|null $fallback A colors\LinProPhoto instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinProPhoto|null */ public static function newLinProPhoto( @@ -292,13 +292,13 @@ public static function newLinProPhoto( } /** - * Returns a new colors\LinRgb instance corresponding to $value. + * Returns a new colors\LinRgb instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param LinRgb|null $fallback A colors\LinRgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinRgb|null */ public static function newLinRgb( @@ -317,13 +317,13 @@ public static function newLinRgb( } /** - * Returns a new colors\OkLab instance corresponding to $value. + * Returns a new colors\OkLab instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param OkLab|null $fallback A colors\OkLab instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return OkLab|null */ public static function newOkLab( @@ -342,13 +342,13 @@ public static function newOkLab( } /** - * Returns a new colors\OkLch instance corresponding to $value. + * Returns a new colors\OkLch instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param OkLch|null $fallback A colors\OkLch instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return OkLch|null */ public static function newOkLch( @@ -367,13 +367,13 @@ public static function newOkLch( } /** - * Returns a new colors\P3 instance corresponding to $value. + * Returns a new colors\P3 instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param P3|null $fallback A colors\P3 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return P3|null */ public static function newP3( @@ -392,13 +392,13 @@ public static function newP3( } /** - * Returns a new colors\ProPhoto instance corresponding to $value. + * Returns a new colors\ProPhoto instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param ProPhoto|null $fallback A colors\ProPhoto instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return ProPhoto|null */ public static function newProPhoto( @@ -417,13 +417,13 @@ public static function newProPhoto( } /** - * Returns a new colors\Rgb instance corresponding to $value. + * Returns a new colors\Rgb instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param Rgb|null $fallback A colors\Rgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Rgb|null */ public static function newRgb( @@ -442,13 +442,13 @@ public static function newRgb( } /** - * Returns a new colors\XyzD50 instance corresponding to $value. + * Returns a new colors\XyzD50 instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param XyzD50|null $fallback A colors\XyzD50 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return XyzD50|null */ public static function newXyzD50( @@ -467,13 +467,13 @@ public static function newXyzD50( } /** - * Returns a new colors\XyzD65 instance corresponding to $value. + * Returns a new colors\XyzD65 instance corresponding to $value. * * @param mixed $value A color string (like '#ff0000' or 'rgb(255,0,0)') or a coordinates array (like [ 'ff', '00', '00' ] or [ 255, 0, 0]) * @param ColorSpace|\Stringable|string|null $from The input color space (if not specified it will be automatically guessed by interpreting the format of $value) * @param XyzD65|null $fallback A colors\XyzD65 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return XyzD65|null */ public static function newXyzD65( @@ -492,5 +492,5 @@ public static function newXyzD65( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/ColorInterface.php b/src/ColorInterface.php index e803d9e..4cdfb8d 100644 --- a/src/ColorInterface.php +++ b/src/ColorInterface.php @@ -21,15 +21,15 @@ use matthieumastadenis\couleur\colors\XyzD65; /** - * An immutable object representing a color expressed in a precise and supported color space. - * + * An immutable object representing a color expressed in a precise and supported color space. + * * It can be converted to another supported color space using one of the to...() methods. - * Variant instances can be created with the change() method. - * + * Variant instances can be created with the change() method. + * */ interface ColorInterface extends \Stringable { - + /* #region Magic Methods */ /** @@ -45,7 +45,7 @@ public function __toString( /* #endregion */ /* #region Public Static Methods */ - + /** * Returns an array containing all supported aliases for the ColorSpace of the current color. * @@ -71,7 +71,7 @@ public static function space( /** * Returns a new ColorInterface instance of the same class, with modified coordinates. * Each implementation of this method may add its own parameters, depending on the corresponding color space. - * + * * @return ColorInterface */ public function change( @@ -96,14 +96,14 @@ public function coordinates( public function stringify( ) :string; - + /** * Returns a new ColorInterface instance corresponding to the current color converted into the $to color space. * * @param ColorSpace|\Stringable|string|null $to The desired output color space (can be an instance of the ColorSpace enum or a stringable alias) * @param ColorInterface|null $fallback A ColorInterface instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return ColorInterface The converted color object */ public function to( @@ -117,7 +117,7 @@ public function to( * * @param Css|null $fallback A colors\Css instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Css The converted color object */ public function toCss( @@ -130,7 +130,7 @@ public function toCss( * * @param HexRgb|null $fallback A colors\HexRgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return HexRgb The converted color object */ public function toHexRgb( @@ -143,7 +143,7 @@ public function toHexRgb( * * @param Hsl|null $fallback A colors\Hsl instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hsl The converted color object */ public function toHsl( @@ -156,7 +156,7 @@ public function toHsl( * * @param Hsv|null $fallback A colors\Hsv instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hsv The converted color object */ public function toHsv( @@ -169,7 +169,7 @@ public function toHsv( * * @param Hwb|null $fallback A colors\Hwb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Hwb The converted color object */ public function toHwb( @@ -182,7 +182,7 @@ public function toHwb( * * @param Lab|null $fallback A colors\Lab instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Lab The converted color object */ public function toLab( @@ -195,7 +195,7 @@ public function toLab( * * @param Lch|null $fallback A colors\Lch instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Lch The converted color object */ public function toLch( @@ -208,7 +208,7 @@ public function toLch( * * @param LinP3|null $fallback A colors\LinP3 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinP3 The converted color object */ public function toLinP3( @@ -221,7 +221,7 @@ public function toLinP3( * * @param LinProPhoto|null $fallback A colors\LinProPhoto instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinProPhoto The converted color object */ public function toLinProPhoto( @@ -234,7 +234,7 @@ public function toLinProPhoto( * * @param LinRgb|null $fallback A colors\LinRgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return LinRgb The converted color object */ public function toLinRgb( @@ -247,7 +247,7 @@ public function toLinRgb( * * @param OkLab|null $fallback A colors\OkLab instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return OkLab The converted color object */ public function toOkLab( @@ -260,7 +260,7 @@ public function toOkLab( * * @param OkLch|null $fallback A colors\OkLch instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return OkLch The converted color object */ public function toOkLch( @@ -273,7 +273,7 @@ public function toOkLch( * * @param P3|null $fallback A colors\P3 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return P3 The converted color object */ public function toP3( @@ -286,7 +286,7 @@ public function toP3( * * @param ProPhoto|null $fallback A colors\ProPhoto instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return ProPhoto The converted color object */ public function toProPhoto( @@ -299,7 +299,7 @@ public function toProPhoto( * * @param Rgb|null $fallback A colors\Rgb instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return Rgb The converted color object */ public function toRgb( @@ -312,7 +312,7 @@ public function toRgb( * * @param XyzD50|null $fallback A colors\XyzD50 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return XyzD50 The converted color object */ public function toXyzD50( @@ -325,7 +325,7 @@ public function toXyzD50( * * @param XyzD65|null $fallback A colors\XyzD65 instance used as a fallback in case of failure * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return XyzD65 The converted color object */ public function toXyzD65( @@ -335,4 +335,4 @@ public function toXyzD65( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/ColorSpace.php b/src/ColorSpace.php index d6bf079..6ccb1b1 100644 --- a/src/ColorSpace.php +++ b/src/ColorSpace.php @@ -22,13 +22,13 @@ use matthieumastadenis\couleur\exceptions\UnsupportedColorSpace; /** - * Represents a color space supported by Couleur. - * + * Represents a color space supported by Couleur. + * * Can be accessed using aliases (all accepted alias are documented at https://github.com/matthieumastadenis/couleur-dev#-color-spaces). * Provides access to dedicated functions (clean(), from(), stringify(), verify()). */ enum ColorSpace :string { - + /* #region Cases */ case Css = Css::class; @@ -50,16 +50,16 @@ enum ColorSpace :string { case XyzD65 = XyzD65::class; /* #endregion */ - + /* #region Public Static Methods */ - + /** * Returns an array containing all supported aliases and the corresponding ColorSpace instances. * * @return array */ public static function allAliases( - + ) :array { $aliases = []; @@ -76,14 +76,14 @@ public static function allAliases( /** * Returns the ColorSpace instance corresponding to the alias $name, if it exists. - * - * If $name does not match a supported alias, an UnsupportedColorSpace Exception will be thrown by default, + * + * If $name does not match a supported alias, an UnsupportedColorSpace Exception will be thrown by default, * unless a $fallback is provided or $throw is set to false. In that case, the method will return $fallback. * * @param \Stringable|string $name Name or alias of the desired ColorSpace * @param ColorSpace|null $fallback Fallback returned if $name is not a supported alias * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return static|null The ColorSpace instance matching the $name alias, $fallback instead */ public static function fromAlias( @@ -107,7 +107,7 @@ public static function fromAlias( } /* #endregion */ - + /* #region Public Methods */ /** @@ -116,7 +116,7 @@ public static function fromAlias( * @return array */ public function aliases( - + ) :array { return ($this->value)::aliases(); } @@ -189,5 +189,5 @@ protected function callback( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/Constant.php b/src/Constant.php index e88dd83..3ad3148 100644 --- a/src/Constant.php +++ b/src/Constant.php @@ -7,31 +7,31 @@ /** * Represents a configuration constant accepted by Couleur. * Allows to easily define the constant and/or access its default value. - * + * * All supported constants are in uppercase and prefixed with 'COULEUR_'. */ enum Constant :int { - + /* #region Cases */ case LEGACY = 0; case PRECISION = 9; /* #endregion */ - + /* #region Public Methods */ /** * Returns the value of the current constant if it exists. - * + * * If the constant exists but is not defined, returns its default value or $value if provided. * If the constant does not exists, returns $value. - * + * * If $create is set to true, the constant will be defined with $value as a value. * * @param mixed $value Fallback value (also used to define the constant if $create is true) * @param boolean $create If true the constant will be defined with $value as a value - * + * * @return mixed The constant value if it exists and is declared, its default value or $value otherwise */ public function value( @@ -46,5 +46,5 @@ public function value( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/CssColor.php b/src/CssColor.php index 11ea7c2..87dd61c 100644 --- a/src/CssColor.php +++ b/src/CssColor.php @@ -12,7 +12,7 @@ * It can be converted to RGB or Hexadecimal RGB coordinates, or directly to an instance of colors\Rgb or colors\HexRgb. */ enum CssColor { - + /* #region Cases */ case aliceblue; @@ -165,7 +165,7 @@ enum CssColor { case yellowgreen; /* #endregion */ - + /* #region Public Static Methods */ /** @@ -327,7 +327,7 @@ public static function allHexRgbCoordinates( static::yellowgreen->name => [ '9A', 'CD', '32' ], ]; } - + /** * Returns an array containing RGB coordinates for all supported CSS colors. * @@ -492,7 +492,7 @@ public static function allRgbCoordinates( * Returns true if the $name CSS color exists, false otherwise. * * @param \Stringable|string $name The named CSS color you're looking for - * + * * @return boolean True if $name is an existing CSS color, false otherwise */ public static function exists( @@ -505,15 +505,15 @@ public static function exists( } /** - * Returns the instance of the CssColor enum corresponding to the color $name if it exists. - * - * If $name does not correspond to an existing CSS color, a new UnsupportedCssColor Exception will be thrown by default, + * Returns the instance of the CssColor enum corresponding to the color $name if it exists. + * + * If $name does not correspond to an existing CSS color, a new UnsupportedCssColor Exception will be thrown by default, * except if a $fallback is provided or if the $throw parameter is set to false. In that case, the method will retun $fallback. * * @param \Stringable|string $name Name of the desired CSS color. It should correspond to one of the enum's cases * @param CssColor|null $fallback Instance of the CssColor enum to return in case of failure (null by default) * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return static|null */ public static function fromCss( @@ -538,11 +538,11 @@ public static function fromCss( /** * Returns the instance of the CssColor enum corresponding to the provided Hexadecimal RGB coordinates, if it exists. - * - * By default and if the $closest parameter is true, the supported color which has the closest coordinates will be returned. - * - * If $closest is false and no supported color matches the provided coordinates, a new UnsupportedCssColor Exception will be - * thrown by default, except if a $fallback is provided or if the $throw parameter is set to false. In that case, the + * + * By default and if the $closest parameter is true, the supported color which has the closest coordinates will be returned. + * + * If $closest is false and no supported color matches the provided coordinates, a new UnsupportedCssColor Exception will be + * thrown by default, except if a $fallback is provided or if the $throw parameter is set to false. In that case, the * method will return $fallback. * * @param string $red Red coordinate of the desired CSS color. It should be a string containing an hexadecimal number between '00' and 'FF' @@ -551,7 +551,7 @@ public static function fromCss( * @param boolean $closest If true, returns the supported CSS color which is the closest from provided coordinates. If false, throws an Exception or returns $fallback * @param CssColor|null $fallback Instance of the CssColor enum to return in case of failure (null by default) * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return static|null */ public static function fromHexRgb( @@ -568,7 +568,7 @@ public static function fromHexRgb( $array = [ $red, $green, $blue ]; $distances = []; $value = null; - + foreach (static::allHexRgbCoordinates() as $color => $values) { if ($array === $values) { $value = $color; @@ -584,28 +584,28 @@ public static function fromHexRgb( + \abs(\hexDec($values[2]) - \hexDec($blue)) ; } - + if (\count($distances)) { $value ??= \array_search( needle : \min($distances), haystack : $distances, ); } - + if (!$value) { $value = '#'.\implode('', $array); } return static::fromCss($value, $fallback, $throw); - } + } /** * Returns the instance of the CssColor enum corresponding to the provided RGB coordinates, if it exists. - * - * By default and if the $closest parameter is true, the supported color which has the closest coordinates will be returned. - * - * If $closest is false and no supported color matches the provided coordinates, a new UnsupportedCssColor Exception will be - * thrown by default, except if a $fallback is provided or if the $throw parameter is set to false. In that case, the + * + * By default and if the $closest parameter is true, the supported color which has the closest coordinates will be returned. + * + * If $closest is false and no supported color matches the provided coordinates, a new UnsupportedCssColor Exception will be + * thrown by default, except if a $fallback is provided or if the $throw parameter is set to false. In that case, the * method will return $fallback. * * @param string $red Red coordinate of the desired CSS color. It should be a number between 0 and 255 @@ -614,7 +614,7 @@ public static function fromHexRgb( * @param boolean $closest If true, returns the supported CSS color which is the closest from provided coordinates. If false, throws an Exception or returns $fallback * @param CssColor|null $fallback Instance of the CssColor enum to return in case of failure (null by default) * @param boolean|null $throw If false the method will not throw exceptions, $fallback will be returned instead - * + * * @return static|null */ public static function fromRgb( @@ -628,7 +628,7 @@ public static function fromRgb( $array = [ $red, $green, $blue ]; $distances = []; $value = null; - + foreach (static::allRgbCoordinates() as $color => $values) { if ($array === $values) { $value = $color; @@ -644,14 +644,14 @@ public static function fromRgb( + \abs($values[2] - $blue) ; } - + if (\count($distances)) { $value ??= \array_search( needle : \min($distances), haystack : $distances, ); } - + if (!$value) { $value = 'rgb('.\implode(',', $array).')'; } @@ -674,7 +674,7 @@ public static function names( } /* #endregion */ - + /* #region Public Methods */ /** @@ -682,7 +682,7 @@ public static function names( * * @param Css|null $fallback An instance of matthieumastadenis\couleur\colors\Css used as a fallback in case of error * @param boolean|null $throw If false no exception will be thrown, $fallback will be returned instead - * + * * @return Css|null */ public function toCss( @@ -702,7 +702,7 @@ public function toCss( * * @param HexRgb|null $fallback An instance of matthieumastadenis\couleur\colors\HexRgb used as a fallback in case of error * @param boolean|null $throw If false no exception will be thrown, $fallback will be returned instead - * + * * @return HexRgb|null */ public function toHexRgb( @@ -716,7 +716,7 @@ public function toHexRgb( throw : $throw, ); } - + /** * Return an array containing Hexadecimal RGB coordinates corresponding to the current CssColor. * @@ -727,15 +727,15 @@ public function toHexRgbCoordinates( ) :array { return static::allHexRgbCoordinates()[$this->name]; } - + /** * Returns a string corresponding to the current CssColor exprimed in Hexadecimal RGB according to the CSS syntax. * * @param boolean|null $alpha If true opacity will always be included, if false it will never be included, if null it will be included only if different from FF * @param boolean $short If true a short value (like #F00) will be returned if possible, if false the method will always return a long value (like #FF0000) * @param boolean $uppercase If true the returned string will be in uppercase, if false in lowercase - * @param boolean $sharp If true the returned string will start with a sharp character (#), if false it won't - * + * @param boolean $sharp If true the returned string will start with a sharp character (#), if false it won't + * * @return string */ public function toHexRgbString( @@ -745,7 +745,7 @@ public function toHexRgbString( bool $sharp = true, ) :string { $values = $this->toHexRgbCoordinates(); - + return utils\hexRgb\stringify( red : $values[0], green : $values[1], @@ -763,7 +763,7 @@ public function toHexRgbString( * * @param Rgb|null $fallback An instance of matthieumastadenis\couleur\colors\Rgb used as a fallback in case of error * @param boolean|null $throw If false no exception will be thrown, $fallback will be returned instead - * + * * @return Rgb|null */ public function toRgb( @@ -777,7 +777,7 @@ public function toRgb( throw : $throw, ); } - + /** * Return an array containing RGB coordinates corresponding to the current CssColor. * @@ -788,13 +788,13 @@ public function toRgbCoordinates( ) :array { return static::allRgbCoordinates()[$this->name]; } - + /** * Returns a string corresponding to the current CssColor exprimed in RGB according to the CSS syntax. * * @param boolean|null $legacy If true the returned string will use the old CSS syntax (like rgb(255,0,0)), if false the modern one (rgb(100% 0% 0% / 100%)), if null it will depend on the value of the COULEUR_LEGACY constant * @param boolean|null $alpha If true opacity will always be included, if false it will never be included, if null it will be included only if different from FF - * + * * @return string */ public function toRgbString( @@ -815,5 +815,5 @@ public function toRgbString( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/colors/Css.php b/src/colors/Css.php index 42a38a4..a24d33b 100644 --- a/src/colors/Css.php +++ b/src/colors/Css.php @@ -13,17 +13,17 @@ class Css implements ColorInterface { /* #region Constructor */ - + public function __construct( public readonly CssColor|\Stringable|string $color, ) { - + } /* #endregion */ - + /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -55,8 +55,8 @@ public function stringify( ) :string { return utils\css\stringify($this->color); - } + } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/colors/HexRgb.php b/src/colors/HexRgb.php index bc394a9..27ed572 100644 --- a/src/colors/HexRgb.php +++ b/src/colors/HexRgb.php @@ -23,9 +23,9 @@ public function __construct( } /* #endregion */ - - /* #region Public Static Methods */ - + + /* #region Public Static Methods */ + public static function aliases( ) :array { @@ -39,7 +39,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -63,14 +63,14 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $alpha = null, bool $short = true, bool|null $uppercase = null, bool $sharp = true, - ) :string { + ) :string { return utils\hexRgb\stringify( red : $this->red, green : $this->green, @@ -84,5 +84,5 @@ public function stringify( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/colors/Hsl.php b/src/colors/Hsl.php index cb0a0e2..24309ec 100644 --- a/src/colors/Hsl.php +++ b/src/colors/Hsl.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -36,7 +36,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -60,8 +60,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -79,4 +79,4 @@ public function stringify( } /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/Hsv.php b/src/colors/Hsv.php index afc746e..62f914f 100644 --- a/src/colors/Hsv.php +++ b/src/colors/Hsv.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -36,7 +36,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -60,8 +60,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -79,4 +79,4 @@ public function stringify( } /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/Hwb.php b/src/colors/Hwb.php index 40bfa22..cdf8fa0 100644 --- a/src/colors/Hwb.php +++ b/src/colors/Hwb.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -35,7 +35,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -59,8 +59,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -78,4 +78,4 @@ public function stringify( } /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/Lab.php b/src/colors/Lab.php index e0334f3..1a90231 100644 --- a/src/colors/Lab.php +++ b/src/colors/Lab.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -38,7 +38,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -63,7 +63,7 @@ public function change( throw : $throw, ); } - + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -82,4 +82,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/Lch.php b/src/colors/Lch.php index 656fbc4..abc1691 100644 --- a/src/colors/Lch.php +++ b/src/colors/Lch.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -38,7 +38,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -62,8 +62,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -82,4 +82,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/LinP3.php b/src/colors/LinP3.php index 493fae0..cb00600 100644 --- a/src/colors/LinP3.php +++ b/src/colors/LinP3.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -39,7 +39,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -63,8 +63,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $alpha = null, int|null $precision = null, @@ -81,4 +81,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/LinProPhoto.php b/src/colors/LinProPhoto.php index 9457b61..18ca1ec 100644 --- a/src/colors/LinProPhoto.php +++ b/src/colors/LinProPhoto.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -39,7 +39,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -63,8 +63,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $alpha = null, int|null $precision = null, @@ -81,4 +81,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/LinRgb.php b/src/colors/LinRgb.php index 5c41259..9583a77 100644 --- a/src/colors/LinRgb.php +++ b/src/colors/LinRgb.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -33,15 +33,15 @@ public static function aliases( 'srgb-linear', 'linrgb', 'lin-rgb', - 'lin_rgb', + 'lin_rgb', 'linsrgb', 'lin-srgb', - 'lin_srgb', + 'lin_srgb', ]; } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -65,8 +65,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -84,4 +84,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/OkLab.php b/src/colors/OkLab.php index 34e227e..47ab32f 100644 --- a/src/colors/OkLab.php +++ b/src/colors/OkLab.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -37,7 +37,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -62,7 +62,7 @@ public function change( throw : $throw, ); } - + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -81,4 +81,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/OkLch.php b/src/colors/OkLch.php index 46714b5..685a1c2 100644 --- a/src/colors/OkLch.php +++ b/src/colors/OkLch.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -37,7 +37,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -61,8 +61,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -81,4 +81,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/P3.php b/src/colors/P3.php index 2719503..9442bee 100644 --- a/src/colors/P3.php +++ b/src/colors/P3.php @@ -25,7 +25,7 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -37,7 +37,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -61,8 +61,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $alpha = null, int|null $precision = null, @@ -79,4 +79,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/ProPhoto.php b/src/colors/ProPhoto.php index 41ff756..ded8c38 100644 --- a/src/colors/ProPhoto.php +++ b/src/colors/ProPhoto.php @@ -25,8 +25,8 @@ public function __construct( /* #endregion */ /* #region Public Static Methods */ - - + + public static function aliases( ) :array { @@ -38,7 +38,7 @@ public static function aliases( } /* #endregion */ - + /* #region Public Methods */ public function change( @@ -62,8 +62,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -81,4 +81,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/Rgb.php b/src/colors/Rgb.php index 6f635da..6ff048e 100644 --- a/src/colors/Rgb.php +++ b/src/colors/Rgb.php @@ -23,9 +23,9 @@ public function __construct( } /* #endregion */ - + /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -37,10 +37,10 @@ public static function aliases( 's_rgb', ]; } - + /* #endregion */ - - /* #region Public Methods */ + + /* #region Public Methods */ public function change( \Stringable|string|int|float|null $red = null, @@ -63,8 +63,8 @@ public function change( fallback : $fallback, throw : $throw, ); - } - + } + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -82,5 +82,5 @@ public function stringify( } /* #endregion */ - -} \ No newline at end of file + +} diff --git a/src/colors/XyzD50.php b/src/colors/XyzD50.php index 7986c8f..22bda95 100644 --- a/src/colors/XyzD50.php +++ b/src/colors/XyzD50.php @@ -23,9 +23,9 @@ public function __construct( } /* #endregion */ - + /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -35,9 +35,9 @@ public static function aliases( 'xyzd50', ]; } - + /* #endregion */ - + /* #region Public Methods */ public function change( @@ -62,7 +62,7 @@ public function change( throw : $throw, ); } - + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -80,4 +80,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/colors/XyzD65.php b/src/colors/XyzD65.php index e6e776b..05d0b3d 100644 --- a/src/colors/XyzD65.php +++ b/src/colors/XyzD65.php @@ -23,9 +23,9 @@ public function __construct( } /* #endregion */ - + /* #region Public Static Methods */ - + public static function aliases( ) :array { @@ -36,9 +36,9 @@ public static function aliases( 'xyz', ]; } - + /* #endregion */ - + /* #region Public Methods */ public function change( @@ -63,7 +63,7 @@ public function change( throw : $throw, ); } - + public function stringify( bool|null $legacy = null, bool|null $alpha = null, @@ -82,4 +82,4 @@ public function stringify( /* #endregion */ -} \ No newline at end of file +} diff --git a/src/exceptions/CallbackDoesNotExist.php b/src/exceptions/CallbackDoesNotExist.php index 8c7a307..8765766 100644 --- a/src/exceptions/CallbackDoesNotExist.php +++ b/src/exceptions/CallbackDoesNotExist.php @@ -2,12 +2,12 @@ namespace matthieumastadenis\couleur\exceptions; -class CallbackDoesNotExist +class CallbackDoesNotExist extends \Exception { public function __construct( - string $callback, - int $code = 0, + string $callback, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/exceptions/ClassDoesNotExist.php b/src/exceptions/ClassDoesNotExist.php index 5366b3a..7760ec2 100644 --- a/src/exceptions/ClassDoesNotExist.php +++ b/src/exceptions/ClassDoesNotExist.php @@ -6,8 +6,8 @@ class ClassDoesNotExist extends \Exception { public function __construct( - string $class, - int $code = 0, + string $class, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/exceptions/MissingColorValue.php b/src/exceptions/MissingColorValue.php index 46230b1..71c6048 100644 --- a/src/exceptions/MissingColorValue.php +++ b/src/exceptions/MissingColorValue.php @@ -2,12 +2,12 @@ namespace matthieumastadenis\couleur\exceptions; -class MissingColorValue +class MissingColorValue extends \Exception { public function __construct( string $name, - int $code = 0, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/exceptions/UnknownColorSpace.php b/src/exceptions/UnknownColorSpace.php index eb809e0..8269958 100644 --- a/src/exceptions/UnknownColorSpace.php +++ b/src/exceptions/UnknownColorSpace.php @@ -2,12 +2,12 @@ namespace matthieumastadenis\couleur\exceptions; -class UnknownColorSpace +class UnknownColorSpace extends \Exception { public function __construct( string|null $space = null, - int $code = 0, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/exceptions/UnsupportedColorSpace.php b/src/exceptions/UnsupportedColorSpace.php index 270308b..1faf786 100644 --- a/src/exceptions/UnsupportedColorSpace.php +++ b/src/exceptions/UnsupportedColorSpace.php @@ -2,12 +2,12 @@ namespace matthieumastadenis\couleur\exceptions; -class UnsupportedColorSpace +class UnsupportedColorSpace extends \Exception { public function __construct( - string $space, - int $code = 0, + string $space, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/exceptions/UnsupportedCoordinateModifier.php b/src/exceptions/UnsupportedCoordinateModifier.php index 563db6a..ed9bb88 100644 --- a/src/exceptions/UnsupportedCoordinateModifier.php +++ b/src/exceptions/UnsupportedCoordinateModifier.php @@ -2,12 +2,12 @@ namespace matthieumastadenis\couleur\exceptions; -class UnsupportedCoordinateModifier +class UnsupportedCoordinateModifier extends \Exception { public function __construct( - string $modifier, - int $code = 0, + string $modifier, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/exceptions/UnsupportedCssColor.php b/src/exceptions/UnsupportedCssColor.php index f82f796..cab1930 100644 --- a/src/exceptions/UnsupportedCssColor.php +++ b/src/exceptions/UnsupportedCssColor.php @@ -2,12 +2,12 @@ namespace matthieumastadenis\couleur\exceptions; -class UnsupportedCssColor +class UnsupportedCssColor extends \Exception { public function __construct( string $name, - int $code = 0, + int $code = 0, \Throwable|null $previous = null, ) { parent::__construct( @@ -16,4 +16,4 @@ public function __construct( previous : $previous, ); } -} \ No newline at end of file +} diff --git a/src/tests/CssColorTest.php b/src/tests/CssColorTest.php index 7352c79..5e84a2c 100644 --- a/src/tests/CssColorTest.php +++ b/src/tests/CssColorTest.php @@ -5,10 +5,10 @@ use matthieumastadenis\couleur\CssColor; use PHPUnit\Framework\TestCase; -class CssColorTest +class CssColorTest extends TestCase { - const COLORS = [ + const COLORS = [ 'lightpink' => [ 'case' => CssColor::lightpink, 'hexRgb' => [ 'FF', 'B6', 'C1' ], @@ -131,4 +131,4 @@ public function test_toRgbCoordinates_returnsAnArrayOfRgbCoordinatesMatchingTheC -} \ No newline at end of file +} diff --git a/src/tests/utils/hexRgb/StringifyTest.php b/src/tests/utils/hexRgb/StringifyTest.php index db555c7..b372680 100644 --- a/src/tests/utils/hexRgb/StringifyTest.php +++ b/src/tests/utils/hexRgb/StringifyTest.php @@ -5,14 +5,14 @@ use matthieumastadenis\couleur\utils\hexRgb; use PHPUnit\Framework\TestCase; -class StringifyTest +class StringifyTest extends TestCase { const LOOPS = 30; - const CHARS = [ - '0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', 'A', 'B', + const CHARS = [ + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', ]; @@ -366,7 +366,7 @@ public function test_resultIsInLowercaseIfUppercaseParamIsFalse( $g1 = \strtolower($g1); $b1 = \strtolower($b1); } - + $hex = hexRgb\stringify($r1, $g1, $b1, uppercase : false); $this->assertSame( @@ -376,4 +376,4 @@ public function test_resultIsInLowercaseIfUppercaseParamIsFalse( } } -} \ No newline at end of file +} diff --git a/src/utils/css/conversions.php b/src/utils/css/conversions.php index 147c029..5165b2c 100644 --- a/src/utils/css/conversions.php +++ b/src/utils/css/conversions.php @@ -98,7 +98,7 @@ function toRgb( if (!($color instanceof CssColor)) { $color = CssColor::fromCss($color); } - + return $color?->toRgbCoordinates() ?? [ 0, 0, 0, 255 ]; } @@ -113,4 +113,4 @@ function toXyzD65( CssColor|\Stringable|string $color, ) :array { return linRgb\toXyzD65(... toLinRgb($color)); -} \ No newline at end of file +} diff --git a/src/utils/css/utils.php b/src/utils/css/utils.php index f4f6358..6077a11 100644 --- a/src/utils/css/utils.php +++ b/src/utils/css/utils.php @@ -11,7 +11,7 @@ * * @param mixed $value * @param boolean $throw - * + * * @return CssColor */ function clean( @@ -35,11 +35,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Css, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Css, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -58,11 +58,11 @@ function verify( return ($value instanceof CssColor) || (\is_string($value) && CssColor::exists($value)) || (\is_array($value) - && (\count($value) === 1) + && (\count($value) === 1) && (($value[0] instanceof CssColor) || ( \is_string($value[0] ?? null) && CssColor::exists($value[0]) )) ) ; -} \ No newline at end of file +} diff --git a/src/utils/hexRgb/conversions.php b/src/utils/hexRgb/conversions.php index 93f38d9..09fcad7 100644 --- a/src/utils/hexRgb/conversions.php +++ b/src/utils/hexRgb/conversions.php @@ -162,4 +162,4 @@ function toXyzD65( string $opacity = 'FF', ) :array { return linRgb\toXyzD65(... toLinRgb($red, $green, $blue, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/hexRgb/utils.php b/src/utils/hexRgb/utils.php index ba756ca..6b1c26e 100644 --- a/src/utils/hexRgb/utils.php +++ b/src/utils/hexRgb/utils.php @@ -40,11 +40,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::HexRgb, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::HexRgb, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -63,7 +63,7 @@ function stringify( $blue = utils\cleanHexValue($blue); $value = $red.$green.$blue; $lower = null; - + if ($alpha ?? (\strtoupper($opacity) !== 'FF')) { $value .= $opacity; } @@ -100,7 +100,7 @@ function verify( mixed $value, ) :bool { return \is_string($value) && \preg_match( - pattern : '/^#?[0-9A-Fa-f]{3,8}$/', + pattern : '/^#?[0-9A-Fa-f]{3,8}$/', subject : $value, ); -} \ No newline at end of file +} diff --git a/src/utils/hsl/conversions.php b/src/utils/hsl/conversions.php index ee9ede8..6de9199 100644 --- a/src/utils/hsl/conversions.php +++ b/src/utils/hsl/conversions.php @@ -44,7 +44,7 @@ function toHsv( ? 0 : 200 * (1 - $lightness / $value) ; - + return [ $hue, $saturation, @@ -155,7 +155,7 @@ function toRgb( if ($hue < 0) { $hue = 6 - \fmod(-$hue, 6); } - + $hue = \fmod($hue, 6); $saturation = \max(0, \min(1, $saturation / 100)); $lightness = \max(0, \min(1, $lightness / 100)); @@ -166,27 +166,27 @@ function toRgb( $red = $c; $green = $x; $blue = 0; - } + } else if ($hue < 2) { $red = $x; $green = $c; $blue = 0; - } + } else if ($hue < 3) { $red = 0; $green = $c; $blue = $x; - } + } else if ($hue < 4) { $red = 0; $green = $x; $blue = $c; - } + } else if ($hue < 5) { $red = $x; $green = 0; $blue = $c; - } + } else { $red = $c; $green = 0; @@ -223,4 +223,4 @@ function toXyzD65( float $opacity = 100, ) :array { return linRgb\toXyzD65(... toLinRgb($hue, $saturation, $lightness, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/hsl/utils.php b/src/utils/hsl/utils.php index 7f9431b..03172a8 100644 --- a/src/utils/hsl/utils.php +++ b/src/utils/hsl/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Hsl, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Hsl, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -103,4 +103,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::Hsl); -} \ No newline at end of file +} diff --git a/src/utils/hsv/conversions.php b/src/utils/hsv/conversions.php index 01812db..2f6a108 100644 --- a/src/utils/hsv/conversions.php +++ b/src/utils/hsv/conversions.php @@ -173,4 +173,4 @@ function toXyzD65( float $opacity = 100, ) :array { return linRgb\toXyzD65(... toLinRgb($hue, $saturation, $value, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/hsv/utils.php b/src/utils/hsv/utils.php index 2e27e60..9a9398b 100644 --- a/src/utils/hsv/utils.php +++ b/src/utils/hsv/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Hsv, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Hsv, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -95,4 +95,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::Hsv); -} \ No newline at end of file +} diff --git a/src/utils/hwb/conversions.php b/src/utils/hwb/conversions.php index 9778f64..edbb906 100644 --- a/src/utils/hwb/conversions.php +++ b/src/utils/hwb/conversions.php @@ -180,4 +180,4 @@ function toXyzD65( float $opacity = 100, ) :array { return linRgb\toXyzD65(... toLinRgb($hue, $whiteness, $blackness, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/hwb/utils.php b/src/utils/hwb/utils.php index 201c1b5..b9b32b9 100644 --- a/src/utils/hwb/utils.php +++ b/src/utils/hwb/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Hwb, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Hwb, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -98,4 +98,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::Hwb); -} \ No newline at end of file +} diff --git a/src/utils/lab/conversions.php b/src/utils/lab/conversions.php index 8b5ee8d..2aa53da 100644 --- a/src/utils/lab/conversions.php +++ b/src/utils/lab/conversions.php @@ -66,17 +66,17 @@ function toLch( float $opacity = 100, ) :array { $lab = [ $lightness, $a, $b ]; - $hue = \atan2($lab[2], $lab[1]) * 180 / \pi(); + $hue = \atan2($lab[2], $lab[1]) * 180 / \pi(); - return [ - $lab[0], - \sqrt(\pow($lab[1], 2) + \pow($lab[2], 2)), - ($hue >= 0 - ? $hue + return [ + $lab[0], + \sqrt(\pow($lab[1], 2) + \pow($lab[2], 2)), + ($hue >= 0 + ? $hue : $hue + 360 ), $opacity, - ]; + ]; } function toLinP3( @@ -158,14 +158,14 @@ function toXyzD50( float $opacity = 100, ) :array { $lab = [ $lightness, $a, $b ]; - $a = 24389/27; - $b = 216/24389; - $f = []; - $f[1] = ($lab[0] + 16) / 116; - $f[0] = $lab[1] / 500 + $f[1]; - $f[2] = $f[1] - $lab[2] / 200; - $xyz = [ - (\pow($f[0], 3) > $b) + $a = 24389/27; + $b = 216/24389; + $f = []; + $f[1] = ($lab[0] + 16) / 116; + $f[0] = $lab[1] / 500 + $f[1]; + $f[2] = $f[1] - $lab[2] / 200; + $xyz = [ + (\pow($f[0], 3) > $b) ? \pow($f[0], 3) : (116 * $f[0] - 16) / $a, ($lab[0] > $a * $b) @@ -174,14 +174,14 @@ function toXyzD50( (\pow($f[2], 3) > $b) ? \pow($f[2], 3) : (116 * $f[2] - 16) / $a, - ]; + ]; $d50 = [ - 0.3457 / 0.3585, - 1.00000, + 0.3457 / 0.3585, + 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585, ]; - + return utils\push( value : (float) ($opacity / 100), array : \array_map( @@ -199,4 +199,4 @@ function toXyzD65( float $opacity = 100, ) :array { return xyzD50\toXyzD65(... toXyzD50($lightness, $a, $b, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/lab/utils.php b/src/utils/lab/utils.php index e981fd7..79ac587 100644 --- a/src/utils/lab/utils.php +++ b/src/utils/lab/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Lab, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Lab, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -98,4 +98,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::Lab); -} \ No newline at end of file +} diff --git a/src/utils/lch/conversions.php b/src/utils/lch/conversions.php index a2c0100..7159102 100644 --- a/src/utils/lch/conversions.php +++ b/src/utils/lch/conversions.php @@ -65,12 +65,12 @@ function toLab( float $hue = 0, float $opacity = 100, ) :array { - return [ - $lightness, - $chroma * \cos($hue * \pi() / 180), - $chroma * \sin($hue * \pi() / 180), + return [ + $lightness, + $chroma * \cos($hue * \pi() / 180), + $chroma * \sin($hue * \pi() / 180), $opacity, - ]; + ]; } function toLinP3( @@ -161,4 +161,4 @@ function toXyzD65( float $opacity = 100, ) :array { return xyzD50\toXyzD65(... toXyzD50($lightness, $chroma, $hue, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/lch/utils.php b/src/utils/lch/utils.php index 1232e28..18e4b05 100644 --- a/src/utils/lch/utils.php +++ b/src/utils/lch/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Lch, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Lch, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -99,4 +99,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::Lch); -} \ No newline at end of file +} diff --git a/src/utils/linP3/conversions.php b/src/utils/linP3/conversions.php index a44e70f..693bda1 100644 --- a/src/utils/linP3/conversions.php +++ b/src/utils/linP3/conversions.php @@ -128,7 +128,7 @@ function toP3( ? -1 : 1 ; - + return ($abs > 0.0031308) ? $sign * (1.055 * \pow($abs, 1/2.4) - 0.055) : 12.92 * $v diff --git a/src/utils/linP3/utils.php b/src/utils/linP3/utils.php index 0c4290e..e09d0aa 100644 --- a/src/utils/linP3/utils.php +++ b/src/utils/linP3/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::LinP3, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::LinP3, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::LinP3); -} \ No newline at end of file +} diff --git a/src/utils/linProPhoto/conversions.php b/src/utils/linProPhoto/conversions.php index c46d2a7..ddd0f11 100644 --- a/src/utils/linProPhoto/conversions.php +++ b/src/utils/linProPhoto/conversions.php @@ -173,8 +173,8 @@ function toXyzD50( [ 0.0, 0.0, 0.8251046025104601 ], ], b : [ - $red, - $green, + $red, + $green, $blue, ], ), @@ -188,4 +188,4 @@ function toXyzD65( float $opacity = 1, ) :array { return xyzD50\toXyzD65(... toXyzD50($red, $green, $blue, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/linProPhoto/utils.php b/src/utils/linProPhoto/utils.php index b63050a..c5781ef 100644 --- a/src/utils/linProPhoto/utils.php +++ b/src/utils/linProPhoto/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::LinProPhoto, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::LinProPhoto, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::LinProPhoto); -} \ No newline at end of file +} diff --git a/src/utils/linRgb/conversions.php b/src/utils/linRgb/conversions.php index 091e025..a957455 100644 --- a/src/utils/linRgb/conversions.php +++ b/src/utils/linRgb/conversions.php @@ -128,7 +128,7 @@ function toRgb( ? -1 : 1 ; - + return 255 * (($abs > 0.0031308) ? $sign * (1.055 * \pow($abs, 1/2.4) - 0.055) : 12.92 * $v @@ -181,10 +181,10 @@ function toXyzD65( [ 0.01933081871559182, 0.11919477979462598, 0.9505321522496607 ], ], b : [ - $red, - $green, + $red, + $green, $blue, ], ), ); -} \ No newline at end of file +} diff --git a/src/utils/linRgb/utils.php b/src/utils/linRgb/utils.php index 99d073d..2e583a9 100644 --- a/src/utils/linRgb/utils.php +++ b/src/utils/linRgb/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::LinRgb, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::LinRgb, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::LinRgb); -} \ No newline at end of file +} diff --git a/src/utils/okLab/conversions.php b/src/utils/okLab/conversions.php index 01b52a6..75983e6 100644 --- a/src/utils/okLab/conversions.php +++ b/src/utils/okLab/conversions.php @@ -171,9 +171,9 @@ function toXyzD65( value : $opacity / 100, array : utils\multiplyMatrices( a : [ - [ 1.2268798733741557, -0.5578149965554813, 0.28139105017721583 ], - [ -0.04057576262431372, 1.1122868293970594, -0.07171106666151701 ], - [ -0.07637294974672142, -0.4214933239627914, 1.5869240244272418 ], + [ 1.2268798733741557, -0.5578149965554813, 0.28139105017721583 ], + [ -0.04057576262431372, 1.1122868293970594, -0.07171106666151701 ], + [ -0.07637294974672142, -0.4214933239627914, 1.5869240244272418 ], ], b : \array_map( callback : fn ($v) => $v ** 3, @@ -187,5 +187,5 @@ function toXyzD65( ), ), ), - ); -} \ No newline at end of file + ); +} diff --git a/src/utils/okLab/utils.php b/src/utils/okLab/utils.php index 81260a9..7ceee9b 100644 --- a/src/utils/okLab/utils.php +++ b/src/utils/okLab/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::OkLab, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::OkLab, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -98,4 +98,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::OkLab); -} \ No newline at end of file +} diff --git a/src/utils/okLch/conversions.php b/src/utils/okLch/conversions.php index f52283d..9826c7d 100644 --- a/src/utils/okLch/conversions.php +++ b/src/utils/okLch/conversions.php @@ -111,11 +111,11 @@ function toOkLab( float $opacity = 100, ) :array { return [ - $lightness, - $chroma * \cos($hue * \pi() / 180), - $chroma * \sin($hue * \pi() / 180), + $lightness, + $chroma * \cos($hue * \pi() / 180), + $chroma * \sin($hue * \pi() / 180), $opacity, - ]; + ]; } function toP3( @@ -161,4 +161,4 @@ function toXyzD65( float $opacity = 100, ) :array { return okLab\toXyzD65(... toOkLab($lightness, $chroma, $hue, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/okLch/utils.php b/src/utils/okLch/utils.php index d9e6887..df0ebf3 100644 --- a/src/utils/okLch/utils.php +++ b/src/utils/okLch/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::OkLch, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::OkLch, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -99,4 +99,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::OkLch); -} \ No newline at end of file +} diff --git a/src/utils/p3/utils.php b/src/utils/p3/utils.php index f111646..999baa3 100644 --- a/src/utils/p3/utils.php +++ b/src/utils/p3/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::P3, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::P3, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::P3); -} \ No newline at end of file +} diff --git a/src/utils/proPhoto/conversions.php b/src/utils/proPhoto/conversions.php index d2b1e1a..5522990 100644 --- a/src/utils/proPhoto/conversions.php +++ b/src/utils/proPhoto/conversions.php @@ -103,7 +103,7 @@ function toLinProPhoto( $sign = ($v < 0) ? -1 : 1; - + return ($abs <= $et) ? $v / 16 : $sign * \pow($abs, 1.8) @@ -175,4 +175,4 @@ function toXyzD65( float $opacity = 1, ) :array { return xyzD50\toXyzD65(... toXyzD50($red, $green, $blue, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/proPhoto/utils.php b/src/utils/proPhoto/utils.php index 9ad4856..6cca981 100644 --- a/src/utils/proPhoto/utils.php +++ b/src/utils/proPhoto/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::ProPhoto, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::ProPhoto, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::ProPhoto); -} \ No newline at end of file +} diff --git a/src/utils/rgb/conversions.php b/src/utils/rgb/conversions.php index 958e565..c47ff40 100644 --- a/src/utils/rgb/conversions.php +++ b/src/utils/rgb/conversions.php @@ -21,8 +21,8 @@ function toCss( float $opacity = 255, ) :CssColor { return CssColor::fromRgb( - (int) \round($red), - (int) \round($green), + (int) \round($red), + (int) \round($green), (int) \round($blue), ); } @@ -55,9 +55,9 @@ function toHsl( $lightness = ($max + $min) / 2; if ($max == $min) { - $hue = + $hue = $saturation = 0; - } + } else { $d = $max - $min; $saturation = ($lightness > 0.5) @@ -81,8 +81,8 @@ function toHsl( } return [ - (float) $hue * 360, - (float) $saturation * 100, + (float) $hue * 360, + (float) $saturation * 100, (float) $lightness * 100, (float) $opacity / 2.55, ]; @@ -221,6 +221,6 @@ function toXyzD65( float $green = 0, float $blue = 0, float $opacity = 255, -) :array { +) :array { return linRgb\toXyzD65(... toLinRgb($red, $green, $blue, $opacity)); -} \ No newline at end of file +} diff --git a/src/utils/rgb/utils.php b/src/utils/rgb/utils.php index dd61849..e57277d 100644 --- a/src/utils/rgb/utils.php +++ b/src/utils/rgb/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::Rgb, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::Rgb, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -110,8 +110,8 @@ function verify( ) :bool { return utils\isColorString($value, ColorSpace::Rgb) || utils\validateArray( - value : $value, + value : $value, filter : fn ($v) => !\is_object($v) && ((int) $v >= 0) && ((int) $v <= 255) ) ; -} \ No newline at end of file +} diff --git a/src/utils/utils.php b/src/utils/utils.php index 90eccae..ba07a62 100644 --- a/src/utils/utils.php +++ b/src/utils/utils.php @@ -8,14 +8,14 @@ use matthieumastadenis\couleur\exceptions\UnsupportedCoordinateModifier; /** - * Add leading zero to $value if it is a stringable value starting with a dot. - * This function is useful for converting CSS opacity shortcuts to proper boolean + * Add leading zero to $value if it is a stringable value starting with a dot. + * This function is useful for converting CSS opacity shortcuts to proper boolean * numbers: '.5' is converted to '0.5'. - * If $value is not stringable or does not start with a dot, it is returned without + * If $value is not stringable or does not start with a dot, it is returned without * any change. * * @param \Stringable|string|integer|float $value The value to transform - * + * * @return \Stringable|string|integer|float The transformed or unchanged value */ function addLeadingZero( @@ -29,18 +29,18 @@ function addLeadingZero( /** * Returns the $value coordinate replaced or updated by $new. - * + * * If $new is null, $value will be returned. * If $new is a simple stringable or number, it will simply be returned instead of $value. * If $new is a string starting with a modifier character (+, -, *, /, %) or ending with a percentage character (%), $value will be modified then returned. - * + * * Examples: changeCoordinate(50, '+5') returns 55 ; * changeCoordinate(50, '-5') returns 45 ; * changeCoordinate(50, '*2') returns 100 ; * changeCoordinate(50, '/2') returns 25 ; * changeCoordinate(50, '%6') returns 2 ; * changeCoordinate(50, '10%') returns 5 ; - * changeCoordinate(50, '+10%') returns 55 ; + * changeCoordinate(50, '+10%') returns 55 ; * changeCoordinate(50, '-10%') returns 45 ; * changeCoordinate(50, '*10%') returns 250 ; * changeCoordinate(50, '/10%') returns 10 ; @@ -50,7 +50,7 @@ function addLeadingZero( * @param \Stringable|string|integer|float|null $new Either a new value which will be returned instead of the original $value, or a modifier string which will be used to update $value * @param boolean $hex If true $value and $new will be considered as strings containing hexadecimal numbers * @param boolean $throw If false the function will not throw exceptions - * + * * @return \Stringable|string|integer|float */ function changeCoordinate( @@ -109,7 +109,7 @@ function changeCoordinate( ? throw new UnsupportedCoordinateModifier($modifier) : $original, }; - + return $hex ? decToHex(\round($result)) : $result @@ -117,31 +117,31 @@ function changeCoordinate( } /** - * Clean a single color coordinate. - * - * The purpose of this function is to transform any coordinate that is part of a color + * Clean a single color coordinate. + * + * The purpose of this function is to transform any coordinate that is part of a color * to a proper float number in the expected range. - * - * By default, it uses 0 as the $min value and 100 as the $max value, so if you call - * the function with '150' or 150 the result will be (float) 100, and if you call the - * function with '-150' or -150 the result will be (float) 0. You can define both + * + * By default, it uses 0 as the $min value and 100 as the $max value, so if you call + * the function with '150' or 150 the result will be (float) 100, and if you call the + * function with '-150' or -150 the result will be (float) 0. You can define both * $min and $max to null if you want an unbounded result. - * - * Percentages are automatically converted using $max value. For example, if you call + * + * Percentages are automatically converted using $max value. For example, if you call * the function with $max=255 and with a $value of '50%' the result will be (float) 127.5. - * - * If you set $round to true, the value will be rounded with $precision decimals. The + * + * If you set $round to true, the value will be rounded with $precision decimals. The * $precision can not exceed \ini_get('precision'), and will be considered as 0 by default. * * @param \Stringable|string|integer|float $value The stringable or number to clean * @param integer $min Minimum allowed value (can be null to unbound) * @param integer $max Maximum allowed value (can be null to unbound) - * @param boolean $loop + * @param boolean $loop * @param integer|null $precision Used to round the value * @param boolean $round If true the value will be rounded * @param \Stringable|string|null $padLeft * @param integer|null $length - * + * * @return float */ function cleanCoordinate( @@ -174,7 +174,7 @@ function cleanCoordinate( if ($max !== null) { $value = \min($value, $max); } - + $value = (float) $value; return ($padLeft === null) @@ -182,21 +182,21 @@ function cleanCoordinate( : \str_pad( string : $value, length : $length ?? \strlen((string) $max), - pad_string : $padLeft, + pad_string : $padLeft, pad_type : \STR_PAD_LEFT, ) ; } /** - * This function transforms a potentially invalid number of decimals to a valid + * This function transforms a potentially invalid number of decimals to a valid * number of decimals, which can be use in any rounding function. - * - * It returns the minimum integer value between $precision and \ini_get('precision'). + * + * It returns the minimum integer value between $precision and \ini_get('precision'). * If the $precision parameter is null, it will be considered as 0. * * @param integer|null $precision A potentially invalid number of decimals - * + * * @return integer The corresponding valid number of decimals */ function cleanPrecision( @@ -214,15 +214,15 @@ function cleanPrecision( /** * Return the value of a constant if it exists, or $value if the constant does not exists. * If $create is set to true, the constant will be defined with $value as a value. - * - * The purpose of this function is to handle constants which are specific to the - * matthieumastadenis/couleur package, so it only uses uppercase constants prefixed + * + * The purpose of this function is to handle constants which are specific to the + * matthieumastadenis/couleur package, so it only uses uppercase constants prefixed * with 'COULEUR_'. It is not made to be used with external or third-party constants. * * @param \Stringable|string $name The constant name (will be converted to uppercase and prefixed with 'COULEUR_') * @param mixed $value Fallback value (also used to define the constant if $create is true) * @param boolean $create If true the constant will be defined with $value as a value - * + * * @return mixed The constant value if it exists, $value otherwise */ function constant( @@ -231,7 +231,7 @@ function constant( bool $create = false, ) :mixed { $name = \strtoupper((string) $name); - + if (!\str_starts_with($name, 'COULEUR_')) { $name = "COULEUR_$name"; } @@ -248,20 +248,20 @@ function constant( } /** - * Clean an hexadecimal value so it contains exaclty $length characters. + * Clean an hexadecimal value so it contains exaclty $length characters. * Also converts the value to uppercase or lowercase if $uppercase is set to true or false. - * - * The purpose of this function is to help converting short hexadecimal color values to their + * + * The purpose of this function is to help converting short hexadecimal color values to their * longer form, like #f00 to #ff0000. It should be called separately for red, green and blue. - * + * * If $value is 'f' and $length is 2, the result will be 'ff'. * * @param \Stringable|string $value The hexadecimal string to clean * @param integer $length The minimum length expected - * @param boolean|null $uppercase If true $value will be converted to uppercase, + * @param boolean|null $uppercase If true $value will be converted to uppercase, * if false $value will be converted to lowercase, * if null the case remains unchanged - * + * * @return string The cleaned hexadecimal $value */ function cleanHexValue( @@ -273,7 +273,7 @@ function cleanHexValue( $value = (string) $value; $prefix = (string) ($prefix ?? $value); $l = \strlen($value); - + while ($l < $length) { $value = $prefix.$value; $l++; @@ -296,7 +296,7 @@ function cleanHexValue( * @param integer $length * @param boolean|null $uppercase * @param integer|null $precision - * + * * @return string */ function decToHex( @@ -315,20 +315,20 @@ function decToHex( } /** - * Attempts to guess a color space by interpreting $value. - * + * Attempts to guess a color space by interpreting $value. + * * This fonction only works with color spaces handled by the matthieumastadenis\couleur\ColorSpace enum. - * - * If $value does not correspond to any of these color spaces, a UnknownColorSpace exception will be thrown by default. + * + * If $value does not correspond to any of these color spaces, a UnknownColorSpace exception will be thrown by default. * If the $throw parameter is set to false, $fallback will be returned instead. * - * @param mixed $value A color value to analyze. Typically it should be an array like [ 255,0,0 ] or a + * @param mixed $value A color value to analyze. Typically it should be an array like [ 255,0,0 ] or a * stringable color expression like 'rgb(255,0,0)'. - * @param ColorSpace|null $fallback Fallback value returned if no color space was found and no exception was thrown. - * @param boolean|null $throw If $value does not correspond to any supported color space and this parameter - * is true, the fonction will throw a UnknownColorSpace exception. If $throw is null, + * @param ColorSpace|null $fallback Fallback value returned if no color space was found and no exception was thrown. + * @param boolean|null $throw If $value does not correspond to any supported color space and this parameter + * is true, the fonction will throw a UnknownColorSpace exception. If $throw is null, * an exception will only be thrown if $fallback is also null. - * + * * @return ColorSpace|null The ColorSpace instance corresponding to $value, $fallback otherwise */ function findColorSpace( @@ -363,16 +363,16 @@ function findColorSpace( /** * This function is used when converting a color value to any color space. - * + * * If the $from parameter is null, the function uses findColorSpace() to identify the input color space from the format of $value. - * + * * If the $to parameter is null, it will be the same as the specified or identified input color space. * * @param mixed $value * @param ColorSpace|\Stringable|string|null $to * @param ColorSpace|\Stringable|string|null $from * @param boolean $throw - * + * * @return array */ function findFromAndTo( @@ -398,7 +398,7 @@ function findFromAndTo( ); return [ - 'from' => $from, + 'from' => $from, 'to' => $to ]; } @@ -423,7 +423,7 @@ function hexToDec( * * @param mixed $value * @param \Stringable|string|array|null $spaces - * + * * @return boolean */ function isColorString( @@ -444,18 +444,18 @@ function isColorString( if ($space === null) { $space = '[0-9A-Za-z]+'; } - + $n = '-?[0-9\.]*((deg)|%)?'; $s = '[\s,]*'; $os = '[\s,\/]*'; - + if (\preg_match( - pattern : "/^($space\s*\()|(color\s*\($space)$s$n$s$n$s$n$os$n\s*\)?$/", + pattern : "/^($space\s*\()|(color\s*\($space)$s$n$s$n$s$n$os$n\s*\)?$/", subject : $value, )) { return true; } - } + } return false; } @@ -464,7 +464,7 @@ function isColorString( * Returns true if $value is an array or an instance of \Traversable, false otherwise. * * @param mixed $value The value to test as an iterable - * + * * @return boolean True if $value is an array or an instance of \Traversable, false otherwise */ function isIterable( @@ -480,7 +480,7 @@ function isIterable( * Returns false otherwise. * * @param mixed $value The value to test as a stringable - * + * * @return boolean True if $value is a string or a \Stringable object, false otherwise */ function isStringable( @@ -492,36 +492,36 @@ function isStringable( } /** - * Where the magic happens. This is used by several color spaces conversion functions. - * + * Where the magic happens. This is used by several color spaces conversion functions. + * * This function is directly inspired by the multiplyMatrices() function in color.js form Lea Verou and Chris Lilley. * (see https://github.com/LeaVerou/color.js/blob/main/src/multiply-matrices.js) - * + * * It returns an array which is the product of the two number matrices passed as parameters. * * @param array $a m x n matrice * @param array $b n x p matrice - * + * * @return array m x p product */ function multiplyMatrices( - array $a, + array $a, array $b, ) :array { $m = count($a); - if (!\is_array($a[0] ?? null)) { - // $a is vector, convert to [[a, b, c, ...]] - $a = [ $a ]; - } + if (!\is_array($a[0] ?? null)) { + // $a is vector, convert to [[a, b, c, ...]] + $a = [ $a ]; + } - if (!\is_array($b[0])) { - // $b is vector, convert to [[a], [b], [c], ...]] + if (!\is_array($b[0])) { + // $b is vector, convert to [[a], [b], [c], ...]] $b = \array_map( - callback : fn ($v) => [ $v ], + callback : fn ($v) => [ $v ], array : $b, ); - } + } $p = count($b[0]); @@ -553,30 +553,30 @@ function multiplyMatrices( array : $a, ); - if ($m === 1) { + if ($m === 1) { // Avoid [[a, b, c, ...]]: - $product = $product[0]; - } + $product = $product[0]; + } - if ($p === 1) { + if ($p === 1) { // Avoid [[a], [b], [c], ...]]: return \array_map( callback : fn ($v) => $v[0], array : $product, ); - } + } - return $product; + return $product; } /** - * Parse any color value and returns an array of corresponding cleaned coordinates. - * + * Parse any color value and returns an array of corresponding cleaned coordinates. + * * Typically $value should be an array of coordinates like [ 255,0,0 ], or a stringable color expression like 'rgb(255,0,0)'. - * + * * @param mixed $value * @param int|float|null $opacityFactor - * + * * @return array */ function parseColorValue( @@ -590,12 +590,12 @@ function parseColorValue( } /** - * Parse a stringable color expression like 'rgb(255,0,0)' and returns an array + * Parse a stringable color expression like 'rgb(255,0,0)' and returns an array * of corresponding cleaned coordinates, like [ 255,0,0,255 ]. - * + * * @param \Stringable|string $value * @param int|float|null $opacityFactor - * + * * @return array */ function parseStringColorValue( @@ -607,10 +607,10 @@ function parseStringColorValue( \array_keys(ColorSpace::allAliases()), [ 'color', '(', ')' ], ); - + $string = \str_replace( search : $replace, - replace : '', + replace : '', subject : \trim((string) $value, ', '), ); @@ -662,18 +662,18 @@ function ($v, $i) use ($opacityFactor, $opacityIndex) { /** * Adds $value to $array and returns $array. - * + * * By default $value will simply be pushed at the end of $array. - * + * * If $index is specified, $value will be added to $array with $index as a key. * By default if $array already contains a value with the $index key, it will not be replaced, * except if $replace is set to true. - * + * * @param mixed $value * @param array $array * @param string|integer|null $index * @param boolean $replace - * + * * @return array */ function push( @@ -693,29 +693,29 @@ function push( } /** - * This function is equivalent to findFromAndTo(), but with $to and $from parameters passed + * This function is equivalent to findFromAndTo(), but with $to and $from parameters passed * as reference so they can be automatically exported to the scope from which it is called. - * + * * It is notably used by the to() function. * * @param mixed $value * @param ColorSpace|\Stringable|string|null $to * @param ColorSpace|\Stringable|string|null $from * @param boolean $throw - * + * * @return array */ function setFromAndTo( mixed $value, ColorSpace|\Stringable|string|null &$to = null, ColorSpace|\Stringable|string|null &$from = null, - bool|null $throw = true, + bool|null $throw = true, ) :array { $results = findFromAndTo( value : $value, to : $to, - from : $from, - throw : $throw, + from : $from, + throw : $throw, ); $to = $results['to'] ?? null; @@ -727,7 +727,7 @@ function setFromAndTo( /** * If $haystack starts with one of the values provided in $needles, returns the needle. Otherwise the function returns false. * If $returnNeedle is set to false, the function will return true instead of the needle prefix. - * + * * Examples : startsWith('+50', '+') returns '+' ; * startsWith('-50', [ '+', '-' ]) returns '-' ; * startsWith('-50', [ '+', '-' ], false) returns true ; @@ -765,10 +765,10 @@ function startsWith( } /** - * This is the highest-level function used to convert any color value to any color space. - * + * This is the highest-level function used to convert any color value to any color space. + * * It uses setFromAndTo() to find the color spaces corresponding to the $to and $from parameters if those are null. - * + * * If the conversion succeeds, it always returns an array of values, like [ 255,0,0,255 ] or [ 'FF','00','00','FF' ]. * In case of errors, it will throw exceptions, except if $throw if set to false (or if $throw is null and $fallback is not null). * @@ -777,7 +777,7 @@ function startsWith( * @param ColorSpace|\Stringable|string|null $from * @param array|null $fallback * @param boolean|null $throw - * + * * @return array */ function to( @@ -790,15 +790,15 @@ function to( setFromAndTo( value : $value, to : $to, - from : $from, - throw : $throw, + from : $from, + throw : $throw, ); if (!($from instanceof ColorSpace) || !($to instanceof ColorSpace)) { return $fallback; } - + return toColor( value : $value, to : $to, @@ -810,14 +810,14 @@ function to( /** - * Converts $value to an array and returns it. - * + * Converts $value to an array and returns it. + * * If $keep is true and $value is not already an array, the returned array will include $value. * If $keep is false and $value is not already an array, the returned array will be empty. * * @param mixed $value * @param boolean $keep - * + * * @return array */ function toArray( @@ -835,10 +835,10 @@ function toArray( /** * Converts $value to an iterable and returns it. - * + * * If $value is an array or an instance of \Traversable it will be returned without modification. * Otherwise $value will be converted to an array then returned. - * + * * If $keep is true and $value is not already an iterabble, the returned array will include $value. * If $keep is false and $value is not already an iterable, the returned array will be empty. * @@ -857,11 +857,11 @@ function toIterable( } /** - * Converts any color value to the specified $to color space. + * Converts any color value to the specified $to color space. * This function is notably called directly by the to() function. - * + * * If $from is null, it will use the $to same color space than the $to parameter. - * + * * If the conversion succeeds, it always returns an array of values, like [ 255,0,0,255 ] or [ 'FF','00','00','FF' ]. * In case of errors, it will throw exceptions, except if $throw if set to false (or if $throw is null and $fallback is not null). * @@ -870,7 +870,7 @@ function toIterable( * @param ColorSpace|null $from * @param array|null $fallback * @param boolean|null $throw - * + * * @return array */ function toColor( @@ -907,7 +907,7 @@ function toColor( if ($from === $to) { return $values; } - + foreach ([ $convert, $cleanTo ] as $callback) { if (!\function_exists($callback)) { return $throw @@ -926,7 +926,7 @@ function toColor( * @param ColorSpace|\Stringable|string|null $value * @param ColorSpace|null $fallback * @param boolean|null $throw - * + * * @return ColorSpace|null */ function toColorSpace( @@ -955,7 +955,7 @@ function toColorSpace( * * @param mixed $value The value to validate * @param callable $filter The filter used to validate the array values (if $value is an array) - * + * * @return boolean True if $value is an array and if all of its values are validated using $filter, false otherwise */ function validateArray( @@ -963,4 +963,4 @@ function validateArray( callable $filter, ) :bool { return \is_array($value) && (\array_filter($value, $filter) === $value); -} \ No newline at end of file +} diff --git a/src/utils/xyzD50/conversions.php b/src/utils/xyzD50/conversions.php index 517c92d..b7c5619 100644 --- a/src/utils/xyzD50/conversions.php +++ b/src/utils/xyzD50/conversions.php @@ -67,15 +67,15 @@ function toLab( ) :array { $xyz = [ $x, $y, $z ]; $d50 = [ - 0.3457 / 0.3585, - 1.00000, + 0.3457 / 0.3585, + 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585, ]; - $a = 216/24389; - $b = 24389/27; + $a = 216/24389; + $b = 24389/27; - $xyz = \array_map( + $xyz = \array_map( fn ($k, $v) => $v / $d50[$k], \array_keys($xyz), \array_values($xyz), @@ -89,12 +89,12 @@ function toLab( $xyz, ); - return [ - (116 * $f[1]) - 16, - 500 * ($f[0] - $f[1]), - 200 * ($f[1] - $f[2]), + return [ + (116 * $f[1]) - 16, + 500 * ($f[0] - $f[1]), + 200 * ($f[1] - $f[2]), $opacity * 100, - ]; + ]; } function toLch( @@ -130,8 +130,8 @@ function toLinProPhoto( [ 0.0, 0.0, 1.2119675456389454 ], ], b : [ - $x, - $y, + $x, + $y, $z, ], ), @@ -207,10 +207,10 @@ function toXyzD65( [ 0.012314001688319899, -0.020507696433477912, 1.3303659366080753 ], ], b : [ - $x, - $y, + $x, + $y, $z, ], ), ); -} \ No newline at end of file +} diff --git a/src/utils/xyzD50/utils.php b/src/utils/xyzD50/utils.php index af64be2..aaaab45 100644 --- a/src/utils/xyzD50/utils.php +++ b/src/utils/xyzD50/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::XyzD50, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::XyzD50, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::XyzD50); -} \ No newline at end of file +} diff --git a/src/utils/xyzD65/conversions.php b/src/utils/xyzD65/conversions.php index 9e703a7..8504849 100644 --- a/src/utils/xyzD65/conversions.php +++ b/src/utils/xyzD65/conversions.php @@ -211,4 +211,4 @@ function toXyzD50( b : [ $x, $y, $z ], ), ); -} \ No newline at end of file +} diff --git a/src/utils/xyzD65/utils.php b/src/utils/xyzD65/utils.php index c15ba35..4eed063 100644 --- a/src/utils/xyzD65/utils.php +++ b/src/utils/xyzD65/utils.php @@ -38,11 +38,11 @@ function from( bool|null $throw = null, ) :array { return utils\to( - value : $value, - to : ColorSpace::XyzD65, - from : $from, - fallback : $fallback, - throw : $throw, + value : $value, + to : ColorSpace::XyzD65, + from : $from, + fallback : $fallback, + throw : $throw, ); } @@ -81,4 +81,4 @@ function verify( mixed $value, ) :bool { return utils\isColorString($value, ColorSpace::XyzD65); -} \ No newline at end of file +}