File tree Expand file tree Collapse file tree 6 files changed +24
-0
lines changed
Expand file tree Collapse file tree 6 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ class Colorspace implements ColorspaceInterface
4040 */
4141 public static function colorFromNormalized (array $ normalized ): CmykColor
4242 {
43+ if (!in_array (count ($ normalized ), [4 , 5 ])) {
44+ throw new InvalidArgumentException ('Number of color channels must be 4 or 5 for ' . static ::class);
45+ }
46+
4347 // add alpha value if missing
4448 $ normalized = count ($ normalized ) === 4 ? array_pad ($ normalized , 5 , 1 ) : $ normalized ;
4549
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ class Colorspace implements ColorspaceInterface
4242 */
4343 public static function colorFromNormalized (array $ normalized ): HslColor
4444 {
45+ if (!in_array (count ($ normalized ), [3 , 4 ])) {
46+ throw new InvalidArgumentException ('Number of color channels must be 3 or 4 for ' . static ::class);
47+ }
48+
4549 // add alpha value if missing
4650 $ normalized = count ($ normalized ) === 3 ? array_pad ($ normalized , 4 , 1 ) : $ normalized ;
4751
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ class Colorspace implements ColorspaceInterface
4242 */
4343 public static function colorFromNormalized (array $ normalized ): HsvColor
4444 {
45+ if (!in_array (count ($ normalized ), [3 , 4 ])) {
46+ throw new InvalidArgumentException ('Number of color channels must be 3 or 4 for ' . static ::class);
47+ }
48+
4549 // add alpha value if missing
4650 $ normalized = count ($ normalized ) === 3 ? array_pad ($ normalized , 4 , 1 ) : $ normalized ;
4751
Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ class Colorspace implements ColorspaceInterface
4141 */
4242 public static function colorFromNormalized (array $ normalized ): OklabColor
4343 {
44+ if (!in_array (count ($ normalized ), [3 , 4 ])) {
45+ throw new InvalidArgumentException ('Number of color channels must be 3 or 4 for ' . static ::class);
46+ }
47+
4448 // add alpha value if missing
4549 $ normalized = count ($ normalized ) === 3 ? array_pad ($ normalized , 4 , 1 ) : $ normalized ;
4650
Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ class Colorspace implements ColorspaceInterface
4444 */
4545 public static function colorFromNormalized (array $ normalized ): OklchColor
4646 {
47+ if (!in_array (count ($ normalized ), [3 , 4 ])) {
48+ throw new InvalidArgumentException ('Number of color channels must be 3 or 4 for ' . static ::class);
49+ }
50+
4751 // add alpha value if missing
4852 $ normalized = count ($ normalized ) === 3 ? array_pad ($ normalized , 4 , 1 ) : $ normalized ;
4953
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ class Colorspace implements ColorspaceInterface
4343 */
4444 public static function colorFromNormalized (array $ normalized ): RgbColor
4545 {
46+ if (!in_array (count ($ normalized ), [3 , 4 ])) {
47+ throw new InvalidArgumentException ('Number of color channels must be 3 or 4 for ' . static ::class);
48+ }
49+
4650 // add alpha value if missing
4751 $ normalized = count ($ normalized ) === 3 ? array_pad ($ normalized , 4 , 1 ) : $ normalized ;
4852
You can’t perform that action at this time.
0 commit comments