1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FondBot\Providers; |
6
|
|
|
|
7
|
|
|
use FondBot\Foundation\Kernel; |
8
|
|
|
use Illuminate\Contracts\Cache\Store; |
9
|
|
|
use FondBot\Conversation\IntentManager; |
10
|
|
|
use Illuminate\Support\ServiceProvider; |
11
|
|
|
use FondBot\Conversation\FallbackIntent; |
12
|
|
|
use FondBot\Conversation\SessionManager; |
13
|
|
|
use FondBot\Conversation\ConversationManager; |
14
|
|
|
use Illuminate\Contracts\Config\Repository as Config; |
15
|
|
|
|
16
|
|
|
class ConversationServiceProvider extends ServiceProvider |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Register the service provider. |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function register(): void |
24
|
|
|
{ |
25
|
|
|
$this->app->singleton(ConversationManager::class, function () { |
26
|
|
|
return new ConversationManager($this->app->make(Kernel::class)); |
|
|
|
|
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
$this->app->singleton(SessionManager::class, function () { |
30
|
|
|
return new SessionManager( |
31
|
|
|
$this->app, |
32
|
|
|
$this->app->make(Store::class) |
33
|
|
|
); |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
$this->app->singleton(IntentManager::class, function () { |
37
|
|
|
/** @var Config $config */ |
38
|
|
|
$config = $this->app[Config::class]; |
39
|
|
|
|
40
|
|
|
$intents = $config->get('fondbot.intents', []); |
41
|
|
|
$fallbackIntent = $config->get('fondbot.fallback_intent', FallbackIntent::class); |
42
|
|
|
|
43
|
|
|
$manager = new IntentManager; |
44
|
|
|
$manager->register($intents, $fallbackIntent); |
45
|
|
|
|
46
|
|
|
return $manager; |
47
|
|
|
}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the services provided by the provider. |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function provides(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
ConversationManager::class, |
59
|
|
|
SessionManager::class, |
60
|
|
|
IntentManager::class, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.