88use Webmozart \Assert \Assert ;
99
1010use function array_filter ;
11- use function array_keys ;
11+ use function array_key_exists ;
1212use function current ;
13- use function in_array ;
1413use function mb_strlen ;
1514use function preg_match ;
1615use function strpos ;
1918
2019class Naming extends AbstractValidator
2120{
22- public const SPECIAL_OR_NUMBER = 'SPECIAL_OR_NUMBER ' ;
23- public const SINGLE_DOT = 'SINGLE_DOT ' ;
24- public const SINGLE_HYPHEN = 'SINGLE_HYPHEN ' ;
25- public const SINGLE_APOSTROPHE = 'SINGLE_APOSTROPHE ' ;
26- public const CONSECUTIVE_DOT = 'CONSECUTIVE_DOT ' ;
27- public const CONSECUTIVE_HYPHEN = 'CONSECUTIVE_HYPHEN ' ;
21+ /**
22+ * @var string
23+ */
24+ public const SPECIAL_OR_NUMBER = 'SPECIAL_OR_NUMBER ' ;
25+
26+ /**
27+ * @var string
28+ */
29+ public const SINGLE_DOT = 'SINGLE_DOT ' ;
30+
31+ /**
32+ * @var string
33+ */
34+ public const SINGLE_HYPHEN = 'SINGLE_HYPHEN ' ;
35+
36+ /**
37+ * @var string
38+ */
39+ public const SINGLE_APOSTROPHE = 'SINGLE_APOSTROPHE ' ;
40+
41+ /**
42+ * @var string
43+ */
44+ public const CONSECUTIVE_DOT = 'CONSECUTIVE_DOT ' ;
45+
46+ /**
47+ * @var string
48+ */
49+ public const CONSECUTIVE_HYPHEN = 'CONSECUTIVE_HYPHEN ' ;
50+
51+ /**
52+ * @var string
53+ */
2854 public const CONSECUTIVE_APOSTROPHE = 'CONSECUTIVE_APOSTROPHE ' ;
29- public const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD ' ;
3055
56+ /**
57+ * @var string
58+ */
59+ public const DOT_TOBE_IN_LAST_WORD = 'DOT_TOBE_IN_LAST_WORD ' ;
60+
61+ /** @var array<string, string> */
3162 protected $ messageTemplates = [
3263 self ::SPECIAL_OR_NUMBER => 'Names can contain only letters, hyphens, apostrophe, spaces & full stops ' ,
3364 self ::SINGLE_DOT => 'Single "." character is not allowed ' ,
@@ -39,6 +70,9 @@ class Naming extends AbstractValidator
3970 self ::DOT_TOBE_IN_LAST_WORD => '"." must be at last word character ' ,
4071 ];
4172
73+ /**
74+ * @param mixed[] $options
75+ */
4276 public function __construct (array $ options = [])
4377 {
4478 parent ::__construct ($ options );
@@ -59,27 +93,27 @@ public function isValid($value): bool
5993 $ length = mb_strlen ($ value );
6094 if ($ length === 1 ) {
6195 $ messageTemplates = [
62- '. ' => self ::SINGLE_DOT ,
63- '- ' => self ::SINGLE_HYPHEN ,
64- '\'' => self ::SINGLE_APOSTROPHE ,
96+ '. ' => self ::SINGLE_DOT ,
97+ '- ' => self ::SINGLE_HYPHEN ,
98+ " ' " => self ::SINGLE_APOSTROPHE ,
6599 ];
66100
67- if (in_array ($ value , array_keys ( $ messageTemplates), true )) {
101+ if (array_key_exists ($ value , $ messageTemplates )) {
68102 $ this ->error ($ messageTemplates [$ value ]);
69103 return false ;
70104 }
71105 } else {
72106 $ messageTemplates = [
73- '.. ' => self ::CONSECUTIVE_DOT ,
74- '-- ' => self ::CONSECUTIVE_HYPHEN ,
75- '\'\'' => self ::CONSECUTIVE_APOSTROPHE ,
107+ '.. ' => self ::CONSECUTIVE_DOT ,
108+ '-- ' => self ::CONSECUTIVE_HYPHEN ,
109+ " '' " => self ::CONSECUTIVE_APOSTROPHE ,
76110 ];
77111
78- $ error = array_filter ($ messageTemplates , function ($ key ) use ($ value ) {
112+ $ error = array_filter ($ messageTemplates , function ($ key ) use ($ value ): bool {
79113 return strpos ($ value , $ key ) !== false ;
80114 }, ARRAY_FILTER_USE_KEY );
81115
82- if ($ error ) {
116+ if ($ error !== [] ) {
83117 $ this ->error (current ($ error ));
84118 return false ;
85119 }
0 commit comments