Skip to content

Commit 9c89e12

Browse files
committed
Refactoring. Removed duplicate code.
1 parent b57f00d commit 9c89e12

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

tools/ContextGenerator.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
class ContextGenerator
1717
{
1818

19+
/**
20+
* Labels and flags that may be used when defining keywords.
21+
*
22+
* @var array
23+
*/
24+
public static $LABELS_FLAGS = array(
25+
'(R)' => 2,
26+
'(D)' => 8,
27+
'(K)' => 16,
28+
'(F)' => 32,
29+
);
30+
1931
/**
2032
* Documentation links for each context.
2133
*
@@ -123,28 +135,12 @@ public static function readWords(array $files)
123135
$type = 1;
124136
$value = trim($words[$i]);
125137

126-
// Reserved keyword.
127-
if (strstr($value, '(R)') !== false) {
128-
$type |= 2;
129-
$value = trim(str_replace('(R)', '', $value));
130-
}
131-
132-
// Data type keyword.
133-
if (strstr($value, '(D)') !== false) {
134-
$type |= 8;
135-
$value = trim(str_replace('(D)', '', $value));
136-
}
137-
138-
// Key keyword.
139-
if (strstr($value, '(K)') !== false) {
140-
$type |= 16;
141-
$value = trim(str_replace('(K)', '', $value));
142-
}
143-
144-
// Function keyword.
145-
if (strstr($value, '(F)') !== false) {
146-
$type |= 32;
147-
$value = trim(str_replace('(F)', '', $value));
138+
// Reserved, data types, keys, functions, etc. keywords.
139+
foreach (static::$LABELS_FLAGS as $label => $flags) {
140+
if (strstr($value, $label) !== false) {
141+
$type |= $flags;
142+
$value = trim(str_replace($label, '', $value));
143+
}
148144
}
149145

150146
// Composed keyword.
@@ -338,7 +334,7 @@ public static function buildAll($input, $output)
338334
}
339335

340336
// Building the context.
341-
print("Building context for {$file}...\n");
337+
sprintf("Building context for %s...\n", $file);
342338
static::build($input . '/' . $file, $output);
343339
}
344340
}

0 commit comments

Comments
 (0)