Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
7 | class MailServiceProvider extends BaseServiceProvider |
||
8 | { |
||
9 | /** |
||
10 | * Register the service provider. |
||
11 | */ |
||
12 | public function register() |
||
18 | |||
19 | /** |
||
20 | * Register the Mailer instance. |
||
21 | */ |
||
22 | protected function registerMailer() |
||
54 | |||
55 | /** |
||
56 | * Set a few dependencies on the mailer instance. |
||
57 | * |
||
58 | * @param \ElfSundae\Multimail\Mailer $mailer |
||
59 | * @param \Illuminate\Foundation\Application $app |
||
60 | */ |
||
61 | protected function setMailerDependencies($mailer, $app) |
||
67 | |||
68 | /** |
||
69 | * Register the Swift Mailer instance. |
||
70 | */ |
||
71 | public function registerSwiftMailer() |
||
81 | |||
82 | /** |
||
83 | * Register the Swift Transport instance. |
||
84 | */ |
||
85 | protected function registerSwiftTransport() |
||
86 | { |
||
87 | $this->app->singleton('swift.transport', function ($app) { |
||
88 | return new TransportManager($app); |
||
89 | }); |
||
90 | |||
91 | $this->app->alias('swift.transport', TransportManager::class); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Register the Swift Mailer Manager instance. |
||
96 | */ |
||
97 | protected function registerSwiftMailerManager() |
||
106 | |||
107 | /** |
||
108 | * Get the services provided by the provider. |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | public function provides() |
||
121 | } |
||
122 |