Complex classes like Lexer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Lexer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Lexer |
||
| 22 | { |
||
| 23 | private $language; |
||
| 24 | private $lines; |
||
| 25 | private $linesCount; |
||
| 26 | private $line; |
||
| 27 | private $trimmedLine; |
||
| 28 | private $lineNumber; |
||
| 29 | private $eos; |
||
| 30 | private $keywords; |
||
| 31 | private $keywordsCache = array(); |
||
| 32 | private $stepKeywordTypesCache = array(); |
||
| 33 | private $deferredObjects = array(); |
||
| 34 | private $deferredObjectsCount = 0; |
||
| 35 | private $stashedToken; |
||
| 36 | private $inPyString = false; |
||
| 37 | private $pyStringSwallow = 0; |
||
| 38 | private $featureStarted = false; |
||
| 39 | private $allowMultilineArguments = false; |
||
| 40 | private $allowSteps = false; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Initializes lexer. |
||
| 44 | * |
||
| 45 | * @param KeywordsInterface $keywords Keywords holder |
||
| 46 | */ |
||
| 47 | 55 | public function __construct(KeywordsInterface $keywords) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Sets lexer input. |
||
| 54 | * |
||
| 55 | * @param string $input Input string |
||
| 56 | * @param string $language Language name |
||
| 57 | * |
||
| 58 | * @throws Exception\LexerException |
||
| 59 | */ |
||
| 60 | 53 | public function analyse($input, $language = 'en') |
|
| 61 | { |
||
| 62 | // try to detect unsupported encoding |
||
| 63 | 53 | if ('UTF-8' !== mb_detect_encoding($input, 'UTF-8', true)) { |
|
| 64 | throw new LexerException('Feature file is not in UTF8 encoding'); |
||
| 65 | } |
||
| 66 | |||
| 67 | 53 | $input = strtr($input, array("\r\n" => "\n", "\r" => "\n")); |
|
| 68 | |||
| 69 | 53 | $this->lines = explode("\n", $input); |
|
| 70 | 53 | $this->linesCount = count($this->lines); |
|
| 71 | 53 | $this->line = $this->lines[0]; |
|
| 72 | 53 | $this->lineNumber = 1; |
|
| 73 | 53 | $this->trimmedLine = null; |
|
| 74 | 53 | $this->eos = false; |
|
| 75 | |||
| 76 | 53 | $this->deferredObjects = array(); |
|
| 77 | 53 | $this->deferredObjectsCount = 0; |
|
| 78 | 53 | $this->stashedToken = null; |
|
| 79 | 53 | $this->inPyString = false; |
|
| 80 | 53 | $this->pyStringSwallow = 0; |
|
| 81 | |||
| 82 | 53 | $this->featureStarted = false; |
|
| 83 | 53 | $this->allowMultilineArguments = false; |
|
| 84 | 53 | $this->allowSteps = false; |
|
| 85 | |||
| 86 | 53 | $this->keywords->setLanguage($this->language = $language); |
|
| 87 | 53 | $this->keywordsCache = array(); |
|
| 88 | 53 | $this->stepKeywordTypesCache = array(); |
|
| 89 | 53 | } |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Returns current lexer language. |
||
| 93 | * |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | 52 | public function getLanguage() |
|
| 97 | { |
||
| 98 | 52 | return $this->language; |
|
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Returns next token or previously stashed one. |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | 53 | public function getAdvancedToken() |
|
| 107 | { |
||
| 108 | 53 | return $this->getStashedToken() ?: $this->getNextToken(); |
|
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Defers token. |
||
| 113 | * |
||
| 114 | * @param array $token Token to defer |
||
| 115 | */ |
||
| 116 | public function deferToken(array $token) |
||
| 117 | { |
||
| 118 | $token['deferred'] = true; |
||
| 119 | $this->deferredObjects[] = $token; |
||
| 120 | ++$this->deferredObjectsCount; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Predicts for number of tokens. |
||
| 125 | * |
||
| 126 | * @return array |
||
| 127 | */ |
||
| 128 | 53 | public function predictToken() |
|
| 129 | { |
||
| 130 | 53 | if (null === $this->stashedToken) { |
|
| 131 | 53 | $this->stashedToken = $this->getNextToken(); |
|
| 132 | 53 | } |
|
| 133 | |||
| 134 | 53 | return $this->stashedToken; |
|
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Constructs token with specified parameters. |
||
| 139 | * |
||
| 140 | * @param string $type Token type |
||
| 141 | * @param string $value Token value |
||
| 142 | * |
||
| 143 | * @return array |
||
| 144 | */ |
||
| 145 | 53 | public function takeToken($type, $value = null) |
|
| 146 | { |
||
| 147 | return array( |
||
| 148 | 53 | 'type' => $type, |
|
| 149 | 53 | 'line' => $this->lineNumber, |
|
| 150 | 53 | 'value' => $value ?: null, |
|
| 151 | 'deferred' => false |
||
| 152 | 53 | ); |
|
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Consumes line from input & increments line counter. |
||
| 157 | */ |
||
| 158 | 53 | protected function consumeLine() |
|
| 159 | { |
||
| 160 | 53 | ++$this->lineNumber; |
|
| 161 | |||
| 162 | 53 | if (($this->lineNumber - 1) === $this->linesCount) { |
|
| 163 | 50 | $this->eos = true; |
|
| 164 | |||
| 165 | 50 | return; |
|
| 166 | } |
||
| 167 | |||
| 168 | 53 | $this->line = $this->lines[$this->lineNumber - 1]; |
|
| 169 | 53 | $this->trimmedLine = null; |
|
| 170 | 53 | } |
|
| 171 | |||
| 172 | /** |
||
| 173 | * Returns trimmed version of line. |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | 53 | protected function getTrimmedLine() |
|
| 178 | { |
||
| 179 | 53 | return null !== $this->trimmedLine ? $this->trimmedLine : $this->trimmedLine = trim($this->line); |
|
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Returns stashed token or null if hasn't. |
||
| 184 | * |
||
| 185 | * @return array|null |
||
| 186 | */ |
||
| 187 | 53 | protected function getStashedToken() |
|
| 188 | { |
||
| 189 | 53 | $stashedToken = $this->stashedToken; |
|
| 190 | 53 | $this->stashedToken = null; |
|
| 191 | |||
| 192 | 53 | return $stashedToken; |
|
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Returns deferred token or null if hasn't. |
||
| 197 | * |
||
| 198 | * @return array|null |
||
| 199 | */ |
||
| 200 | 53 | protected function getDeferredToken() |
|
| 201 | { |
||
| 202 | 53 | if (!$this->deferredObjectsCount) { |
|
| 203 | 53 | return null; |
|
| 204 | } |
||
| 205 | |||
| 206 | --$this->deferredObjectsCount; |
||
| 207 | |||
| 208 | return array_shift($this->deferredObjects); |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Returns next token from input. |
||
| 213 | * |
||
| 214 | * @return array |
||
| 215 | */ |
||
| 216 | 53 | protected function getNextToken() |
|
| 217 | { |
||
| 218 | 53 | return $this->getDeferredToken() |
|
| 219 | 53 | ?: $this->scanEOS() |
|
| 220 | 53 | ?: $this->scanLanguage() |
|
| 221 | 53 | ?: $this->scanComment() |
|
| 222 | 53 | ?: $this->scanPyStringOp() |
|
| 223 | 53 | ?: $this->scanPyStringContent() |
|
| 224 | 53 | ?: $this->scanStep() |
|
| 225 | 53 | ?: $this->scanScenario() |
|
| 226 | 53 | ?: $this->scanBackground() |
|
| 227 | 53 | ?: $this->scanOutline() |
|
| 228 | 53 | ?: $this->scanExamples() |
|
| 229 | 53 | ?: $this->scanFeature() |
|
| 230 | 52 | ?: $this->scanTags() |
|
| 231 | 51 | ?: $this->scanTableRow() |
|
| 232 | 51 | ?: $this->scanNewline() |
|
| 233 | 53 | ?: $this->scanText(); |
|
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Scans for token with specified regex. |
||
| 238 | * |
||
| 239 | * @param string $regex Regular expression |
||
| 240 | * @param string $type Expected token type |
||
| 241 | * |
||
| 242 | * @return null|array |
||
| 243 | */ |
||
| 244 | 11 | protected function scanInput($regex, $type) |
|
| 245 | { |
||
| 246 | 11 | if (!preg_match($regex, $this->line, $matches)) { |
|
| 247 | 4 | return null; |
|
| 248 | } |
||
| 249 | |||
| 250 | 9 | $token = $this->takeToken($type, $matches[1]); |
|
| 251 | 9 | $this->consumeLine(); |
|
| 252 | |||
| 253 | 9 | return $token; |
|
| 254 | } |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Scans for token with specified keywords. |
||
| 258 | * |
||
| 259 | * @param string $keywords Keywords (splitted with |) |
||
| 260 | * @param string $type Expected token type |
||
| 261 | * |
||
| 262 | * @return null|array |
||
| 263 | */ |
||
| 264 | 53 | protected function scanInputForKeywords($keywords, $type) |
|
| 265 | { |
||
| 266 | 53 | if (!preg_match('/^(\s*)(' . $keywords . '):\s*(.*)/u', $this->line, $matches)) { |
|
| 267 | 53 | return null; |
|
| 268 | } |
||
| 269 | |||
| 270 | 52 | $token = $this->takeToken($type, $matches[3]); |
|
| 271 | 52 | $token['keyword'] = $matches[2]; |
|
| 272 | 52 | $token['indent'] = mb_strlen($matches[1], 'utf8'); |
|
| 273 | |||
| 274 | 52 | $this->consumeLine(); |
|
| 275 | |||
| 276 | // turn off language searching |
||
| 277 | 52 | if ('Feature' === $type) { |
|
| 278 | 52 | $this->featureStarted = true; |
|
| 279 | 52 | } |
|
| 280 | |||
| 281 | // turn off PyString and Table searching |
||
| 282 | 52 | if ('Feature' === $type || 'Scenario' === $type || 'Outline' === $type) { |
|
| 283 | 52 | $this->allowMultilineArguments = false; |
|
| 284 | 52 | } elseif ('Examples' === $type) { |
|
| 285 | 16 | $this->allowMultilineArguments = true; |
|
| 286 | 16 | } |
|
| 287 | |||
| 288 | // turn on steps searching |
||
| 289 | 52 | if ('Scenario' === $type || 'Background' === $type || 'Outline' === $type) { |
|
| 290 | 47 | $this->allowSteps = true; |
|
| 291 | 47 | } |
|
| 292 | |||
| 293 | 52 | return $token; |
|
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Scans EOS from input & returns it if found. |
||
| 298 | * |
||
| 299 | * @return null|array |
||
| 300 | */ |
||
| 301 | 53 | protected function scanEOS() |
|
| 309 | |||
| 310 | /** |
||
| 311 | * Returns keywords for provided type. |
||
| 312 | * |
||
| 313 | * @param string $type Keyword type |
||
| 314 | * |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | 53 | protected function getKeywords($type) |
|
| 318 | { |
||
| 319 | 53 | if (!isset($this->keywordsCache[$type])) { |
|
| 320 | 53 | $getter = 'get' . $type . 'Keywords'; |
|
| 321 | 53 | $keywords = $this->keywords->$getter(); |
|
| 322 | |||
| 323 | 53 | if ('Step' === $type) { |
|
| 324 | 44 | $padded = array(); |
|
| 325 | 44 | foreach (explode('|', $keywords) as $keyword) { |
|
| 326 | 44 | $padded[] = false !== mb_strpos($keyword, '<', 0, 'utf8') |
|
| 327 | 44 | ? preg_quote(mb_substr($keyword, 0, -1, 'utf8'), '/') . '\s*' |
|
| 328 | 44 | : preg_quote($keyword, '/') . '\s+'; |
|
| 329 | 44 | } |
|
| 330 | |||
| 331 | 44 | $keywords = implode('|', $padded); |
|
| 332 | 44 | } |
|
| 333 | |||
| 334 | 53 | $this->keywordsCache[$type] = $keywords; |
|
| 335 | 53 | } |
|
| 336 | |||
| 337 | 53 | return $this->keywordsCache[$type]; |
|
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Scans Feature from input & returns it if found. |
||
| 342 | * |
||
| 343 | * @return null|array |
||
| 344 | */ |
||
| 345 | 53 | protected function scanFeature() |
|
| 346 | { |
||
| 347 | 53 | return $this->scanInputForKeywords($this->getKeywords('Feature'), 'Feature'); |
|
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Scans Background from input & returns it if found. |
||
| 352 | * |
||
| 353 | * @return null|array |
||
| 354 | */ |
||
| 355 | 53 | protected function scanBackground() |
|
| 356 | { |
||
| 357 | 53 | return $this->scanInputForKeywords($this->getKeywords('Background'), 'Background'); |
|
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Scans Scenario from input & returns it if found. |
||
| 362 | * |
||
| 363 | * @return null|array |
||
| 364 | */ |
||
| 365 | 53 | protected function scanScenario() |
|
| 366 | { |
||
| 367 | 53 | return $this->scanInputForKeywords($this->getKeywords('Scenario'), 'Scenario'); |
|
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Scans Scenario Outline from input & returns it if found. |
||
| 372 | * |
||
| 373 | * @return null|array |
||
| 374 | */ |
||
| 375 | 53 | protected function scanOutline() |
|
| 376 | { |
||
| 377 | 53 | return $this->scanInputForKeywords($this->getKeywords('Outline'), 'Outline'); |
|
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Scans Scenario Outline Examples from input & returns it if found. |
||
| 382 | * |
||
| 383 | * @return null|array |
||
| 384 | */ |
||
| 385 | 53 | protected function scanExamples() |
|
| 386 | { |
||
| 387 | 53 | return $this->scanInputForKeywords($this->getKeywords('Examples'), 'Examples'); |
|
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Scans Step from input & returns it if found. |
||
| 392 | * |
||
| 393 | * @return null|array |
||
| 394 | */ |
||
| 395 | 53 | protected function scanStep() |
|
| 396 | { |
||
| 397 | 53 | if (!$this->allowSteps) { |
|
| 398 | 53 | return null; |
|
| 399 | } |
||
| 400 | |||
| 401 | 44 | $keywords = $this->getKeywords('Step'); |
|
| 402 | 44 | if (!preg_match('/^\s*(' . $keywords . ')([^\s].+)/u', $this->line, $matches)) { |
|
| 403 | 41 | return null; |
|
| 404 | } |
||
| 405 | |||
| 406 | 40 | $keyword = trim($matches[1]); |
|
| 407 | 40 | $token = $this->takeToken('Step', $keyword); |
|
| 408 | 40 | $token['keyword_type'] = $this->getStepKeywordType($keyword); |
|
| 409 | 40 | $token['text'] = $matches[2]; |
|
| 410 | |||
| 411 | 40 | $this->consumeLine(); |
|
| 412 | 40 | $this->allowMultilineArguments = true; |
|
| 413 | |||
| 414 | 40 | return $token; |
|
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Scans PyString from input & returns it if found. |
||
| 419 | * |
||
| 420 | * @return null|array |
||
| 421 | */ |
||
| 422 | 53 | protected function scanPyStringOp() |
|
| 423 | { |
||
| 424 | 53 | if (!$this->allowMultilineArguments) { |
|
| 425 | 53 | return null; |
|
| 426 | } |
||
| 427 | |||
| 428 | 41 | if (false === ($pos = mb_strpos($this->line, '"""', 0, 'utf8'))) { |
|
| 429 | 41 | return null; |
|
| 430 | } |
||
| 431 | |||
| 432 | 10 | $this->inPyString = !$this->inPyString; |
|
| 433 | 10 | $token = $this->takeToken('PyStringOp'); |
|
| 434 | 10 | $this->pyStringSwallow = $pos; |
|
| 435 | |||
| 436 | 10 | $this->consumeLine(); |
|
| 437 | |||
| 438 | 10 | return $token; |
|
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Scans PyString content. |
||
| 443 | * |
||
| 444 | * @return null|array |
||
| 445 | */ |
||
| 446 | 53 | protected function scanPyStringContent() |
|
| 447 | { |
||
| 448 | 53 | if (!$this->inPyString) { |
|
| 449 | 53 | return null; |
|
| 450 | } |
||
| 451 | |||
| 452 | 10 | $token = $this->scanText(); |
|
| 453 | // swallow trailing spaces |
||
| 454 | 10 | $token['value'] = preg_replace('/^\s{0,' . $this->pyStringSwallow . '}/u', '', $token['value']); |
|
| 455 | |||
| 456 | 10 | return $token; |
|
| 457 | } |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Scans Table Row from input & returns it if found. |
||
| 461 | * |
||
| 462 | * @return null|array |
||
| 463 | */ |
||
| 464 | 51 | protected function scanTableRow() |
|
| 465 | { |
||
| 466 | 51 | if (!$this->allowMultilineArguments) { |
|
| 467 | 45 | return null; |
|
| 468 | } |
||
| 469 | |||
| 470 | 36 | $line = $this->getTrimmedLine(); |
|
| 471 | 36 | if (!isset($line[0]) || '|' !== $line[0] || '|' !== substr($line, -1)) { |
|
| 472 | 36 | return null; |
|
| 473 | } |
||
| 474 | |||
| 475 | 17 | $token = $this->takeToken('TableRow'); |
|
| 476 | 17 | $line = mb_substr($line, 1, mb_strlen($line, 'utf8') - 2, 'utf8'); |
|
| 477 | 17 | $columns = array_map(function ($column) { |
|
| 478 | 17 | return trim(str_replace('\\|', '|', $column)); |
|
| 479 | 17 | }, preg_split('/(?<!\\\)\|/u', $line)); |
|
| 480 | 17 | $token['columns'] = $columns; |
|
| 481 | |||
| 482 | 17 | $this->consumeLine(); |
|
| 483 | |||
| 484 | 17 | return $token; |
|
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Scans Tags from input & returns it if found. |
||
| 489 | * |
||
| 490 | * @return null|array |
||
| 491 | */ |
||
| 492 | 52 | protected function scanTags() |
|
| 493 | { |
||
| 494 | 52 | $line = $this->getTrimmedLine(); |
|
| 495 | 52 | if (!isset($line[0]) || '@' !== $line[0]) { |
|
| 496 | 51 | return null; |
|
| 497 | } |
||
| 498 | |||
| 499 | 5 | $token = $this->takeToken('Tag'); |
|
| 500 | 5 | $tags = explode('@', mb_substr($line, 1, mb_strlen($line, 'utf8') - 1, 'utf8')); |
|
| 501 | 5 | $tags = array_map('trim', $tags); |
|
| 502 | 5 | $token['tags'] = $tags; |
|
| 503 | |||
| 504 | 5 | $this->consumeLine(); |
|
| 505 | |||
| 506 | 5 | return $token; |
|
| 507 | } |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Scans Language specifier from input & returns it if found. |
||
| 511 | * |
||
| 512 | * @return null|array |
||
| 513 | */ |
||
| 514 | 53 | protected function scanLanguage() |
|
| 515 | { |
||
| 516 | 53 | if ($this->featureStarted) { |
|
| 517 | 52 | return null; |
|
| 518 | } |
||
| 519 | |||
| 520 | 53 | if ($this->inPyString) { |
|
| 521 | return null; |
||
| 522 | } |
||
| 523 | |||
| 524 | 53 | if (0 !== mb_strpos(ltrim($this->line), '#', 0, 'utf8')) { |
|
| 525 | 53 | return null; |
|
| 526 | } |
||
| 527 | |||
| 528 | 11 | return $this->scanInput('/^\s*\#\s*language:\s*([\w_\-]+)\s*$/', 'Language'); |
|
| 529 | } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Scans Comment from input & returns it if found. |
||
| 533 | * |
||
| 534 | * @return null|array |
||
| 535 | */ |
||
| 536 | 53 | protected function scanComment() |
|
| 537 | { |
||
| 538 | 53 | if ($this->inPyString) { |
|
| 539 | 10 | return null; |
|
| 540 | } |
||
| 541 | |||
| 542 | 53 | $line = $this->getTrimmedLine(); |
|
| 543 | 53 | if (0 !== mb_strpos($line, '#', 0, 'utf8')) { |
|
| 544 | 53 | return null; |
|
| 545 | } |
||
| 546 | |||
| 547 | 8 | $token = $this->takeToken('Comment', $line); |
|
| 548 | 8 | $this->consumeLine(); |
|
| 549 | |||
| 550 | 8 | return $token; |
|
| 551 | } |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Scans Newline from input & returns it if found. |
||
| 555 | * |
||
| 556 | * @return null|array |
||
| 557 | */ |
||
| 558 | 51 | protected function scanNewline() |
|
| 559 | { |
||
| 560 | 51 | if ('' !== $this->getTrimmedLine()) { |
|
| 561 | 29 | return null; |
|
| 562 | } |
||
| 563 | |||
| 564 | 51 | $token = $this->takeToken('Newline', mb_strlen($this->line, 'utf8')); |
|
| 565 | 51 | $this->consumeLine(); |
|
| 566 | |||
| 567 | 51 | return $token; |
|
| 568 | } |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Scans text from input & returns it if found. |
||
| 572 | * |
||
| 573 | * @return null|array |
||
| 574 | */ |
||
| 575 | 36 | protected function scanText() |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Returns step type keyword (Given, When, Then, etc.). |
||
| 585 | * |
||
| 586 | * @param string $native Step keyword in provided language |
||
| 587 | * @return string |
||
| 588 | */ |
||
| 589 | 40 | private function getStepKeywordType($native) |
|
| 590 | { |
||
| 591 | // Consider "*" as a AND keyword so that it is normalized to the previous step type |
||
| 592 | 40 | if ('*' === $native) { |
|
| 593 | return 'And'; |
||
| 594 | } |
||
| 595 | |||
| 596 | 40 | if (empty($this->stepKeywordTypesCache)) { |
|
| 597 | 40 | $this->stepKeywordTypesCache = array( |
|
| 598 | 40 | 'Given' => explode('|', $this->keywords->getGivenKeywords()), |
|
| 599 | 40 | 'When' => explode('|', $this->keywords->getWhenKeywords()), |
|
| 600 | 40 | 'Then' => explode('|', $this->keywords->getThenKeywords()), |
|
| 601 | 40 | 'And' => explode('|', $this->keywords->getAndKeywords()), |
|
| 602 | 40 | 'But' => explode('|', $this->keywords->getButKeywords()) |
|
| 603 | 40 | ); |
|
| 604 | 40 | } |
|
| 605 | |||
| 606 | 40 | foreach ($this->stepKeywordTypesCache as $type => $keywords) { |
|
| 607 | 40 | if (in_array($native, $keywords) || in_array($native . '<', $keywords)) { |
|
| 608 | 40 | return $type; |
|
| 609 | } |
||
| 614 | } |
||
| 615 |