Merge pull request #35 from TomasVotruba/nette-trigger-error

[TriggerExtractor] add simple check for the other message
This commit is contained in:
Tomáš Votruba 2017-09-07 00:33:17 +02:00 committed by GitHub
commit cce616b641
2 changed files with 28 additions and 9 deletions

View File

@ -66,17 +66,30 @@ final class TriggerMessageResolver
$words = explode(' ', $message);
foreach ($words as $word) {
// is method()
if (Strings::endsWith($word, '()') && strlen($word) > 2) {
// doesn't include class in the beggning
if (! Strings::startsWith($word, $class)) {
$word = $class . '::' . $word;
}
}
$completeMessage .= ' ' . $word;
$completeMessage .= ' ' . $this->prependClassToMethodCallIfNeeded($word, $class);
}
return trim($completeMessage);
}
private function prependClassToMethodCallIfNeeded(string $word, string $class): string
{
// is method()
if (Strings::endsWith($word, '()') && strlen($word) > 2) {
// doesn't include class in the beggning
if (! Strings::startsWith($word, $class)) {
return $class . '::' . $word;
}
}
// is method('...')
if (Strings::endsWith($word, '\')')) {
// doesn't include class in the beggning
if (! Strings::startsWith($word, $class)) {
return $class . '::' . $word;
}
}
return $word;
}
}

View File

@ -32,11 +32,17 @@ final class TriggerExtractorTest extends AbstractContainerAwareTestCase
$this->assertCount(2, $deprecations);
$setClassToSetFacoryDeprecation = $deprecations[0];
$injectMethodToTagDeprecation = $deprecations[1];
$this->assertSame(
'Nette\DI\Definition::setClass() second parameter $args is deprecated,'
. ' use Nette\DI\Definition::setFactory()',
$setClassToSetFacoryDeprecation
);
$this->assertSame(
'Nette\DI\Definition::setInject() is deprecated, use Nette\DI\Definition::addTag(\'inject\')',
$injectMethodToTagDeprecation
);
}
}