Passed
Push — master ( 6f8b1f...142a48 )
by James
25:51 queued 11:45
created

FireflyServiceProvider::register()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 111
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 64
c 0
b 0
f 0
dl 0
loc 111
rs 8.7853
cc 3
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * FireflyServiceProvider.php
4
 * Copyright (c) 2017 [email protected]
5
 *
6
 * This file is part of Firefly III.
7
 *
8
 * Firefly III is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * Firefly III is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
declare(strict_types=1);
22
23
namespace FireflyIII\Providers;
24
25
use FireflyIII\Exceptions\FireflyException;
26
use FireflyIII\Generator\Chart\Basic\ChartJsGenerator;
27
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
28
use FireflyIII\Helpers\Attachments\AttachmentHelper;
29
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
30
use FireflyIII\Helpers\Chart\MetaPieChart;
31
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
32
use FireflyIII\Helpers\Fiscal\FiscalHelper;
33
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
34
use FireflyIII\Helpers\Help\Help;
35
use FireflyIII\Helpers\Help\HelpInterface;
36
use FireflyIII\Helpers\Report\BalanceReportHelper;
37
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
38
use FireflyIII\Helpers\Report\BudgetReportHelper;
39
use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
40
use FireflyIII\Helpers\Report\NetWorth;
41
use FireflyIII\Helpers\Report\NetWorthInterface;
42
use FireflyIII\Helpers\Report\PopupReport;
43
use FireflyIII\Helpers\Report\PopupReportInterface;
44
use FireflyIII\Helpers\Report\ReportHelper;
45
use FireflyIII\Helpers\Report\ReportHelperInterface;
46
use FireflyIII\Repositories\TransactionType\TransactionTypeRepository;
47
use FireflyIII\Repositories\TransactionType\TransactionTypeRepositoryInterface;
48
use FireflyIII\Repositories\User\UserRepository;
49
use FireflyIII\Repositories\User\UserRepositoryInterface;
50
use FireflyIII\Services\Currency\ExchangeRateInterface;
51
use FireflyIII\Services\IP\IpifyOrg;
52
use FireflyIII\Services\IP\IPRetrievalInterface;
53
use FireflyIII\Services\Password\PwndVerifierV3;
54
use FireflyIII\Services\Password\Verifier;
55
use FireflyIII\Support\Amount;
56
use FireflyIII\Support\FireflyConfig;
57
use FireflyIII\Support\ExpandedForm;
58
use FireflyIII\Support\Form\AccountForm;
59
use FireflyIII\Support\Form\CurrencyForm;
60
use FireflyIII\Support\Form\PiggyBankForm;
61
use FireflyIII\Support\Form\RuleForm;
62
use FireflyIII\Support\Navigation;
63
use FireflyIII\Support\Preferences;
64
use FireflyIII\Support\Steam;
65
use FireflyIII\Support\Twig\AmountFormat;
66
use FireflyIII\Support\Twig\Extension\TransactionGroupTwig;
67
use FireflyIII\Support\Twig\General;
68
use FireflyIII\Support\Twig\Rule;
69
use FireflyIII\Support\Twig\Translation;
70
use FireflyIII\Validation\FireflyValidator;
71
use Illuminate\Foundation\Application;
72
use Illuminate\Support\ServiceProvider;
73
use Twig;
74
use Twig_Extension_Debug;
75
use TwigBridge\Extension\Loader\Functions;
76
use Validator;
77
78
/**
79
 *
80
 * Class FireflyServiceProvider.
81
 *
82
 * @codeCoverageIgnore
83
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
84
 */
85
class FireflyServiceProvider extends ServiceProvider
86
{
87
    /**
88
     * Start provider.
89
     */
90
    public function boot(): void
91
    {
92
        Validator::resolver(
93
        /** @noinspection MoreThanThreeArgumentsInspection */
94
            function ($translator, $data, $rules, $messages) {
95
                return new FireflyValidator($translator, $data, $rules, $messages);
96
            }
97
        );
98
        $config = app('config');
99
        Twig::addExtension(new Functions($config));
100
        Twig::addExtension(new General);
101
        Twig::addExtension(new TransactionGroupTwig);
102
        Twig::addExtension(new Translation);
103
        Twig::addExtension(new Rule);
104
        Twig::addExtension(new AmountFormat);
105
        Twig::addExtension(new Twig_Extension_Debug);
106
    }
107
108
    /**
109
     * Register stuff.
110
     *
111
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
112
     */
113
    public function register(): void
114
    {
115
        $this->app->bind(
116
            'preferences',
117
            function () {
118
                return new Preferences;
119
            }
120
        );
121
122
        $this->app->bind(
123
            'fireflyconfig',
124
            function () {
125
                return new FireflyConfig;
126
            }
127
        );
128
        $this->app->bind(
129
            'navigation',
130
            function () {
131
                return new Navigation;
132
            }
133
        );
134
        $this->app->bind(
135
            'amount',
136
            function () {
137
                return new Amount;
138
            }
139
        );
140
141
        $this->app->bind(
142
            'steam',
143
            function () {
144
                return new Steam;
145
            }
146
        );
147
        $this->app->bind(
148
            'expandedform',
149
            static function () {
150
                return new ExpandedForm;
151
            }
152
        );
153
154
        $this->app->bind(
155
            'accountform',
156
            static function () {
157
                return new AccountForm;
158
            }
159
        );
160
        $this->app->bind(
161
            'currencyform',
162
            static function () {
163
                return new CurrencyForm;
164
            }
165
        );
166
167
        $this->app->bind(
168
            'piggybankform',
169
            static function () {
170
                return new PiggyBankForm;
171
            }
172
        );
173
174
        $this->app->bind(
175
            'ruleform',
176
            static function () {
177
                return new RuleForm;
178
            }
179
        );
180
181
        // chart generator:
182
        $this->app->bind(GeneratorInterface::class, ChartJsGenerator::class);
183
184
        // chart builder
185
        $this->app->bind(
186
            MetaPieChartInterface::class,
187
            function (Application $app) {
188
                /** @var MetaPieChart $chart */
189
                $chart = app(MetaPieChart::class);
190
                if ($app->auth->check()) {
191
                    $chart->setUser(auth()->user());
192
                }
193
194
                return $chart;
195
            }
196
        );
197
198
        // other generators
199
        $this->app->bind(UserRepositoryInterface::class, UserRepository::class);
200
        $this->app->bind(TransactionTypeRepositoryInterface::class, TransactionTypeRepository::class);
201
        $this->app->bind(AttachmentHelperInterface::class, AttachmentHelper::class);
202
203
        // more generators:
204
        $this->app->bind(PopupReportInterface::class, PopupReport::class);
205
        $this->app->bind(HelpInterface::class, Help::class);
206
        $this->app->bind(ReportHelperInterface::class, ReportHelper::class);
207
        $this->app->bind(FiscalHelperInterface::class, FiscalHelper::class);
208
        $this->app->bind(BalanceReportHelperInterface::class, BalanceReportHelper::class);
209
        $this->app->bind(BudgetReportHelperInterface::class, BudgetReportHelper::class);
210
        $class = (string)config(sprintf('firefly.cer_providers.%s', (string)config('firefly.cer_provider')));
211
        if ('' === $class) {
212
            throw new FireflyException('Invalid currency exchange rate provider. Cannot continue.');
213
        }
214
        $this->app->bind(ExchangeRateInterface::class, $class);
215
216
        // password verifier thing
217
        $this->app->bind(Verifier::class, PwndVerifierV3::class);
218
219
        // IP thing:
220
        $this->app->bind(IPRetrievalInterface::class, IpifyOrg::class);
221
222
        // net worth thing.
223
        $this->app->bind(NetWorthInterface::class, NetWorth::class);
224
    }
225
}
226