File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -125,12 +125,19 @@ private function handleColour($colour)
125
125
{
126
126
if (is_string ($ colour ) && $ colour [0 ] == '# ' ) {
127
127
$ hexToRGB = function ($ input ) {
128
+ // ensure input no longer has a # for more predictable division
129
+ // PHP 8.1 does not like implicitly casting a float to an int
130
+ $ input = trim ($ input , '# ' );
131
+
132
+ if (strlen ($ input ) != 3 && strlen ($ input ) != 6 ) {
133
+ throw new \RuntimeException ('Colour should be a 3 or 6 character value after the # ' );
134
+ }
135
+
128
136
// split the array into three chunks
129
- $ split = str_split (trim ( $ input, ' # ' ) , strlen ($ input ) / 3 );
137
+ $ split = str_split ($ input , strlen ($ input ) / 3 );
130
138
131
139
// cope with three character hex reference
132
- // three characters plus a # = 4
133
- if (strlen ($ input ) == 4 ) {
140
+ if (strlen ($ input ) == 3 ) {
134
141
array_walk ($ split , function (&$ character ) {
135
142
$ character = str_repeat ($ character , 2 );
136
143
});
Original file line number Diff line number Diff line change @@ -34,4 +34,20 @@ public function testBadBackgroundColour()
34
34
35
35
new BaconQrCodeProvider (1 , '#000 ' , 'not-a-colour ' );
36
36
}
37
+
38
+ public function testBadTextColourHexRef ()
39
+ {
40
+ $ this ->expectException (\RuntimeException::class);
41
+
42
+ new BaconQrCodeProvider (1 , '#AAAA ' , '#FFF ' );
43
+ }
44
+
45
+ public function testBadBackgroundColourHexRef ()
46
+ {
47
+ $ this ->expectException (\RuntimeException::class);
48
+
49
+ new BaconQrCodeProvider (1 , '#000 ' , '#AAAA ' );
50
+ }
51
+
52
+
37
53
}
You can’t perform that action at this time.
0 commit comments