Passed
Pull Request — release-2.1 (#5269)
by Fran
07:34 queued 02:42
created
Sources/random_compat/random_bytes_libsodium_legacy.php 1 patch
Braces   +20 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,7 +26,8 @@  discard block
 block discarded – undo
26 26
  * SOFTWARE.
27 27
  */
28 28
 
29
-if (!is_callable('random_bytes')) {
29
+if (!is_callable('random_bytes'))
30
+{
30 31
     /**
31 32
      * If the libsodium PHP extension is loaded, we'll use it above any other
32 33
      * solution.
@@ -42,16 +43,20 @@  discard block
 block discarded – undo
42 43
      */
43 44
     function random_bytes($bytes)
44 45
     {
45
-        try {
46
+        try
47
+        {
46 48
             /** @var int $bytes */
47 49
             $bytes = RandomCompat_intval($bytes);
48
-        } catch (TypeError $ex) {
50
+        }
51
+        catch (TypeError $ex)
52
+        {
49 53
             throw new TypeError(
50 54
                 'random_bytes(): $bytes must be an integer'
51 55
             );
52 56
         }
53 57
 
54
-        if ($bytes < 1) {
58
+        if ($bytes < 1)
59
+        {
55 60
             throw new Error(
56 61
                 'Length must be greater than 0'
57 62
             );
@@ -66,19 +71,25 @@  discard block
 block discarded – undo
66 71
          * \Sodium\randombytes_buf() doesn't allow more than 2147483647 bytes to be
67 72
          * generated in one invocation.
68 73
          */
69
-        if ($bytes > 2147483647) {
70
-            for ($i = 0; $i < $bytes; $i += 1073741824) {
74
+        if ($bytes > 2147483647)
75
+        {
76
+            for ($i = 0; $i < $bytes; $i += 1073741824)
77
+            {
71 78
                 $n = ($bytes - $i) > 1073741824
72 79
                     ? 1073741824
73 80
                     : $bytes - $i;
74 81
                 $buf .= Sodium::randombytes_buf((int) $n);
75 82
             }
76
-        } else {
83
+        }
84
+        else
85
+        {
77 86
             $buf .= Sodium::randombytes_buf((int) $bytes);
78 87
         }
79 88
 
80
-        if (is_string($buf)) {
81
-            if (RandomCompat_strlen($buf) === $bytes) {
89
+        if (is_string($buf))
90
+        {
91
+            if (RandomCompat_strlen($buf) === $bytes)
92
+            {
82 93
                 return $buf;
83 94
             }
84 95
         }
Please login to merge, or discard this patch.
Sources/random_compat/random_bytes_libsodium.php 1 patch
Braces   +20 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,7 +26,8 @@  discard block
 block discarded – undo
26 26
  * SOFTWARE.
27 27
  */
28 28
 
29
-if (!is_callable('random_bytes')) {
29
+if (!is_callable('random_bytes'))
30
+{
30 31
     /**
31 32
      * If the libsodium PHP extension is loaded, we'll use it above any other
32 33
      * solution.
@@ -42,16 +43,20 @@  discard block
 block discarded – undo
42 43
      */
43 44
     function random_bytes($bytes)
44 45
     {
45
-        try {
46
+        try
47
+        {
46 48
             /** @var int $bytes */
47 49
             $bytes = RandomCompat_intval($bytes);
48
-        } catch (TypeError $ex) {
50
+        }
51
+        catch (TypeError $ex)
52
+        {
49 53
             throw new TypeError(
50 54
                 'random_bytes(): $bytes must be an integer'
51 55
             );
52 56
         }
53 57
 
54
-        if ($bytes < 1) {
58
+        if ($bytes < 1)
59
+        {
55 60
             throw new Error(
56 61
                 'Length must be greater than 0'
57 62
             );
@@ -62,21 +67,27 @@  discard block
 block discarded – undo
62 67
          * generated in one invocation.
63 68
          */
64 69
         /** @var string|bool $buf */
65
-        if ($bytes > 2147483647) {
70
+        if ($bytes > 2147483647)
71
+        {
66 72
             $buf = '';
67
-            for ($i = 0; $i < $bytes; $i += 1073741824) {
73
+            for ($i = 0; $i < $bytes; $i += 1073741824)
74
+            {
68 75
                 $n = ($bytes - $i) > 1073741824
69 76
                     ? 1073741824
70 77
                     : $bytes - $i;
71 78
                 $buf .= \Sodium\randombytes_buf($n);
72 79
             }
73
-        } else {
80
+        }
81
+        else
82
+        {
74 83
             /** @var string|bool $buf */
75 84
             $buf = \Sodium\randombytes_buf($bytes);
76 85
         }
77 86
 
78
-        if (is_string($buf)) {
79
-            if (RandomCompat_strlen($buf) === $bytes) {
87
+        if (is_string($buf))
88
+        {
89
+            if (RandomCompat_strlen($buf) === $bytes)
90
+            {
80 91
                 return $buf;
81 92
             }
82 93
         }
Please login to merge, or discard this patch.