These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the overtrue/wechat. |
||
5 | * |
||
6 | * (c) overtrue <[email protected]> |
||
7 | * |
||
8 | * This source file is subject to the MIT license that is bundled |
||
9 | * with this source code in the file LICENSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * MiniProgramServiceProvider.php. |
||
14 | * |
||
15 | * This file is part of the wechat. |
||
16 | * |
||
17 | * (c) mingyoung <[email protected]> |
||
18 | * |
||
19 | * This source file is subject to the MIT license that is bundled |
||
20 | * with this source code in the file LICENSE. |
||
21 | */ |
||
22 | |||
23 | namespace EasyWeChat\Foundation\ServiceProviders; |
||
24 | |||
25 | use EasyWeChat\Encryption\Encryptor; |
||
26 | use EasyWeChat\MiniProgram\AccessToken; |
||
27 | use EasyWeChat\MiniProgram\Material\Temporary; |
||
28 | use EasyWeChat\MiniProgram\MiniProgram; |
||
29 | use EasyWeChat\MiniProgram\Notice\Notice; |
||
30 | use EasyWeChat\MiniProgram\QRCode\QRCode; |
||
31 | use EasyWeChat\MiniProgram\Server\Guard; |
||
32 | use EasyWeChat\MiniProgram\Sns\Sns; |
||
33 | use EasyWeChat\MiniProgram\Staff\Staff; |
||
34 | use Pimple\Container; |
||
35 | use Pimple\ServiceProviderInterface; |
||
36 | |||
37 | /** |
||
38 | * Class MiniProgramServiceProvider. |
||
39 | */ |
||
40 | class MiniProgramServiceProvider implements ServiceProviderInterface |
||
41 | { |
||
42 | /** |
||
43 | * Registers services on the given container. |
||
44 | * |
||
45 | * This method should only be used to configure services and parameters. |
||
46 | * It should not get services. |
||
47 | * |
||
48 | * @param Container $pimple A container instance |
||
49 | */ |
||
50 | public function register(Container $pimple) |
||
51 | { |
||
52 | View Code Duplication | $pimple['mini_program.access_token'] = function ($pimple) { |
|
0 ignored issues
–
show
|
|||
53 | return new AccessToken( |
||
54 | $pimple['config']['mini_program']['app_id'], |
||
55 | $pimple['config']['mini_program']['secret'], |
||
56 | $pimple['cache'] |
||
57 | ); |
||
58 | }; |
||
59 | |||
60 | View Code Duplication | $pimple['mini_program.encryptor'] = function ($pimple) { |
|
61 | return new Encryptor( |
||
62 | $pimple['config']['mini_program']['app_id'], |
||
63 | $pimple['config']['mini_program']['token'], |
||
64 | $pimple['config']['mini_program']['aes_key'] |
||
65 | ); |
||
66 | }; |
||
67 | |||
68 | View Code Duplication | $pimple['mini_program.server'] = function ($pimple) { |
|
69 | $server = new Guard($pimple['config']['mini_program']['token']); |
||
70 | $server->debug($pimple['config']['debug']); |
||
71 | $server->setEncryptor($pimple['mini_program.encryptor']); |
||
72 | |||
73 | return $server; |
||
74 | }; |
||
75 | |||
76 | $pimple['mini_program.staff'] = function ($pimple) { |
||
77 | return new Staff($pimple['mini_program.access_token']); |
||
78 | }; |
||
79 | |||
80 | $pimple['mini_program.notice'] = function ($pimple) { |
||
81 | return new Notice($pimple['mini_program.access_token']); |
||
82 | }; |
||
83 | |||
84 | $pimple['mini_program.material_temporary'] = function ($pimple) { |
||
85 | return new Temporary($pimple['mini_program.access_token']); |
||
86 | }; |
||
87 | |||
88 | $pimple['mini_program.sns'] = function ($pimple) { |
||
89 | return new Sns( |
||
90 | $pimple['mini_program.access_token'], |
||
91 | $pimple['config']['mini_program'] |
||
92 | ); |
||
93 | }; |
||
94 | |||
95 | $pimple['mini_program.qrcode'] = function ($pimple) { |
||
96 | return new QRCode( |
||
97 | $pimple['mini_program.access_token'], |
||
98 | $pimple['config']['mini_program'] |
||
99 | ); |
||
100 | }; |
||
101 | |||
102 | $pimple['mini_program'] = function ($pimple) { |
||
103 | return new MiniProgram($pimple); |
||
104 | }; |
||
105 | } |
||
106 | } |
||
107 |
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.