File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace LasseRafn \Hexer \Exceptions ;
4+
5+ class PercentageIsNotAnInteger extends \Exception
6+ {
7+ }
Original file line number Diff line number Diff line change 44
55use LasseRafn \Hexer \Exceptions \HexTooLongException ;
66use LasseRafn \Hexer \Exceptions \HexTooShortException ;
7+ use LasseRafn \Hexer \Exceptions \PercentageIsNotAnInteger ;
78use LasseRafn \Hexer \Exceptions \PercentageTooHighException ;
89use LasseRafn \Hexer \Exceptions \PercentageTooLowException ;
910
@@ -55,8 +56,19 @@ public function darken($percentage = 0)
5556 return $ this ->brightnessModifier ->adjustBrightness ($ this ->hex , $ percentage * -1 );
5657 }
5758
59+ /**
60+ * @param integer $percentage
61+ *
62+ * @throws PercentageTooHighException
63+ * @throws PercentageTooLowException
64+ * @throws PercentageIsNotAnInteger
65+ */
5866 private function validatePercentage ($ percentage )
5967 {
68+ if ( ! is_int ($ percentage )) {
69+ throw new PercentageIsNotAnInteger ("The percentage ( {$ percentage }) is not an integer. " );
70+ }
71+
6072 if ($ percentage < 0 ) {
6173 throw new PercentageTooLowException ("The percentage ( {$ percentage }) is below zero (0) " );
6274 }
@@ -66,6 +78,10 @@ private function validatePercentage($percentage)
6678 }
6779 }
6880
81+ /**
82+ * @throws HexTooLongException
83+ * @throws HexTooShortException
84+ */
6985 private function validateHex ()
7086 {
7187 $ hex = str_replace ('# ' , '' , $ this ->hex );
Original file line number Diff line number Diff line change @@ -100,6 +100,14 @@ public function test_will_fail_with_too_high_percentage_input()
100100 $ hex ->lighten (101 );
101101 }
102102
103+ public function test_will_fail_with_a_non_integer_percentage_input ()
104+ {
105+ $ this ->expectException (\LasseRafn \Hexer \Exceptions \PercentageIsNotAnInteger::class);
106+
107+ $ hex = new \LasseRafn \Hexer \Hex ('#fff ' );
108+ $ hex ->lighten ('ab12 ' );
109+ }
110+
103111 public function test_will_return_initial_hex_with_zero_percentage ()
104112 {
105113 $ hex = new \LasseRafn \Hexer \Hex ('#fff ' );
You can’t perform that action at this time.
0 commit comments