File tree Expand file tree Collapse file tree 2 files changed +37
-32
lines changed Expand file tree Collapse file tree 2 files changed +37
-32
lines changed Original file line number Diff line number Diff line change 21
21
22
22
namespace WikibaseSolutions \CypherDSL \Traits ;
23
23
24
+ use InvalidArgumentException ;
24
25
use ReflectionClass ;
25
26
use TypeError ;
26
27
use function gettype ;
27
28
use function is_array ;
29
+ use function is_numeric ;
30
+ use function strlen ;
31
+ use function trim ;
28
32
29
33
/**
30
34
* Convenience trait including simple assertions and error reporting functions
@@ -154,4 +158,34 @@ private function isType($types, $userInput): bool
154
158
155
159
return false ;
156
160
}
161
+
162
+ /**
163
+ * Validates the name to see if it can be used as a parameter or variable.
164
+ *
165
+ * @see https://neo4j.com/docs/cypher-manual/current/syntax/naming/#_naming_rules
166
+ *
167
+ * @param string $name
168
+ *
169
+ * @return void
170
+ */
171
+ private static function validateName (string $ name ): void
172
+ {
173
+ $ name = trim ($ name );
174
+
175
+ if ($ name === "" ) {
176
+ throw new InvalidArgumentException ("A name cannot be an empty string " );
177
+ }
178
+
179
+ if (!ctype_alnum ($ name )) {
180
+ throw new InvalidArgumentException ('A name can only contain alphanumeric characters ' );
181
+ }
182
+
183
+ if (is_numeric ($ name [0 ])) {
184
+ throw new InvalidArgumentException ('A name cannot begin with a numeric character ' );
185
+ }
186
+
187
+ if (strlen ($ name ) >= 65535 ) {
188
+ throw new InvalidArgumentException ('A name cannot be longer than 65534 characters ' );
189
+ }
190
+ }
157
191
}
Original file line number Diff line number Diff line change 10
10
11
11
trait HasNameTrait
12
12
{
13
- public static function automaticVariableLength (): int {
13
+ public static function automaticVariableLength (): int
14
+ {
14
15
return 32 ;
15
16
}
16
17
@@ -26,40 +27,10 @@ public static function automaticVariableLength(): int {
26
27
*
27
28
* @return string
28
29
*/
29
- public static function generateName (string $ prefix = 'var ' , int $ length = null ): string
30
+ private static function generateName (string $ prefix = 'var ' , int $ length = null ): string
30
31
{
31
32
$ length ??= self ::automaticVariableLength ();
32
33
33
34
return $ prefix . substr (bin2hex (openssl_random_pseudo_bytes (ceil ($ length / 2 ))), 0 , $ length );
34
35
}
35
-
36
- /**
37
- * Validates the name to see if it can be used as a parameter or variable.
38
- *
39
- * @see https://neo4j.com/docs/cypher-manual/current/syntax/naming/#_naming_rules
40
- *
41
- * @param string $name
42
- *
43
- * @return void
44
- */
45
- public static function validateName (string $ name ): void
46
- {
47
- $ name = trim ($ name );
48
-
49
- if ($ name === "" ) {
50
- throw new InvalidArgumentException ("A name cannot be an empty string " );
51
- }
52
-
53
- if (!ctype_alnum ($ name )) {
54
- throw new InvalidArgumentException ('A name can only contain alphanumeric characters ' );
55
- }
56
-
57
- if (is_numeric ($ name [0 ])) {
58
- throw new InvalidArgumentException ('A name cannot begin with a numeric character ' );
59
- }
60
-
61
- if (strlen ($ name ) >= 65535 ) {
62
- throw new InvalidArgumentException ('A name cannot be longer than 65534 characters ' );
63
- }
64
- }
65
36
}
You can’t perform that action at this time.
0 commit comments