These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Basis\Provider; |
||
4 | |||
5 | use Basis\Application; |
||
6 | use Basis\Cache; |
||
7 | use Basis\Config; |
||
8 | use Basis\Converter; |
||
9 | use Basis\Dispatcher; |
||
10 | use Basis\Filesystem; |
||
11 | use Basis\Framework; |
||
12 | use Basis\Service; |
||
13 | use Basis\Http; |
||
14 | use GuzzleHttp\Client; |
||
15 | use League\Container\ServiceProvider\AbstractServiceProvider; |
||
16 | |||
17 | class CoreProvider extends AbstractServiceProvider |
||
18 | { |
||
19 | protected $provides = [ |
||
20 | Cache::class, |
||
21 | Config::class, |
||
22 | Converter::class, |
||
23 | Dispatcher::class, |
||
24 | Framework::class, |
||
25 | Http::class, |
||
26 | ]; |
||
27 | |||
28 | public function register() |
||
29 | { |
||
30 | View Code Duplication | $this->getContainer()->share(Config::class, function () { |
|
0 ignored issues
–
show
|
|||
31 | $app = $this->getContainer()->get(Application::class); |
||
32 | $framework = $this->getContainer()->get(Framework::class); |
||
33 | $fs = $this->getContainer()->get(Filesystem::class); |
||
34 | $converter = $this->getContainer()->get(Converter::class); |
||
35 | return new Config($app, $framework, $fs, $converter); |
||
36 | }); |
||
37 | |||
38 | $this->getContainer()->share(Cache::class, function () { |
||
39 | $fs = $this->getContainer()->get(Filesystem::class); |
||
40 | $converter = $this->getContainer()->get(Converter::class); |
||
41 | return new Cache($fs, $converter); |
||
42 | }); |
||
43 | |||
44 | $this->getContainer()->share(Converter::class, function () { |
||
45 | return new Converter(); |
||
46 | }); |
||
47 | |||
48 | 1 | $this->getContainer()->share(Dispatcher::class, function () { |
|
49 | 1 | $client = $this->getContainer()->get(Client::class); |
|
50 | 1 | $service = $this->getContainer()->get(Service::class); |
|
51 | 1 | return new Dispatcher($client, $service); |
|
52 | }); |
||
53 | |||
54 | $this->getContainer()->share(Framework::class, function () { |
||
55 | return new Framework($this->getContainer(), dirname(dirname(__DIR__))); |
||
56 | }); |
||
57 | |||
58 | 1 | $this->getContainer()->share(Http::class, function () { |
|
59 | 1 | return new Http($this->getContainer()->get(Application::class)); |
|
60 | }); |
||
61 | } |
||
62 | } |
||
63 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.