Completed
Push — trunk ( 0e7a2e...6a6c5e )
by SuperNova.WS
07:28
created

GlobalContainer::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 93
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 45
nc 1
nop 1
dl 0
loc 93
ccs 0
cts 26
cp 0
crap 2
rs 8.4642
c 0
b 0
f 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
namespace Core;
4
5
use Bonus\BonusCatalog;
6
use Bonus\ValueStorage;
7
use Common\ContainerPlus;
8
use Core\SnPimp;
9
use Modules\ModulesManager;
10
use \SN;
11
use \General;
12
use \Core\Watchdog;
13
use \Core\Repository;
14
use \Meta\Economic\EconomicHelper;
15
use Player\PlayerLevelHelper;
16
17
18
/**
19
 * Class GlobalContainer
20
 *
21
 * Used to describe internal structures of container
22
 *
23
 * Variables ------------------------------------------------------------------------------------------------------------
24
 * @property string                 $cachePrefix
25
 *
26
 * Services ------------------------------------------------------------------------------------------------------------
27
 * @property \debug                 $debug
28
 * @property \DBAL\db_mysql         $db
29
 * @property \classCache            $cache
30
 * @property \classConfig           $config
31
 * @property \Core\Repository       $repository
32
 * @property \Storage               $storage
33
 * @property \Design                $design
34
 * @property \BBCodeParser          $bbCodeParser
35
 * @property \Fleet\FleetDispatcher $fleetDispatcher
36
 * @property Watchdog               $watchdog
37
 *
38
 * @property ValueStorage           $valueStorage
39
 * @property BonusCatalog           $bonusCatalog
40
 *
41
 * @property General                $general
42
 * @property EconomicHelper         $economicHelper
43
 *
44
 * @property PlayerLevelHelper      $playerLevelHelper
45
 * @property SnPimp                 $pimp
46
 *
47
 * @property ModulesManager         $modules
48
 *
49
 * Dummy objects -------------------------------------------------------------------------------------------------------
50
 * @property \TheUser               $theUser
51
 *
52
 * Models --------------------------------------------------------------------------------------------------------------
53
 * @property \TextModel             $textModel
54
 * @property string                 $skinEntityClass
55
 * @property \SkinModel             $skinModel
56
 *
57
 * @package Common
58
 *
59
 */
60
61
// * Unused --------------------------------------------------------------------------------------------------------------
62
// * @property \Common\Types        $types
63
// * @property \DbQueryConstructor  $query
64
// * @property \DbRowDirectOperator $dbGlobalRowOperator
65
// * @property \SnDbCachedOperator $cacheOperator - really DB record operator. But let it be
66
// * @property \classLocale         $localePlayer
67
// *
68
// * @property string $snCacheClass
69
// * @property \SnCache $snCache
70
// *
71
// * @property string $buddyClass
72
// * @property \Buddy\BuddyModel $buddyModel
73
// *
74
// * @property \V2Unit\V2UnitModel $unitModel
75
// * @property \V2Unit\V2UnitList $unitList
76
// *
77
// * @property V2FleetModel $fleetModel
78
// *
79
// * @property PlanetRenderer $planetRenderer
80
// * @property \FleetRenderer $fleetRenderer
81
// * @property $dbOperator - makes CRUD to DB:
82
83
class GlobalContainer extends ContainerPlus {
84
85
  public function __construct(array $values = array()) {
86
    parent::__construct($values);
87
88
    $gc = $this;
89
90
    // Services --------------------------------------------------------------------------------------------------------
91
    // Default db
92
    $gc->db = function (GlobalContainer $c) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type DBAL\db_mysql of property $db.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
93
      SN::$db = new \DBAL\db_mysql($c);
94
95
      return SN::$db;
96
    };
97
98
    $gc->debug = function (/** @noinspection PhpUnusedParameterInspection */
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type debug of property $debug.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
99
      GlobalContainer $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

99
      /** @scrutinizer ignore-unused */ GlobalContainer $c) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
      return new \debug();
101
    };
102
103
    $gc->cache = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type classCache of property $cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
104
      return new \classCache($gc->cachePrefix);
105
    };
106
107
    $gc->config = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type classConfig of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
108
      return new \classConfig($gc->cachePrefix);
109
    };
110
111
112
    $gc->repository = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Core\Repository of property $repository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
113
      return new Repository($gc);
114
    };
115
116
    $gc->storage = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Storage of property $storage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
117
      return new \Storage($gc);
118
    };
119
120
    $gc->design = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Design of property $design.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
121
      return new \Design($gc);
122
    };
123
124
    $gc->bbCodeParser = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type BBCodeParser of property $bbCodeParser.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
125
      return new \BBCodeParser($gc);
126
    };
127
128
    $gc->fleetDispatcher = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Fleet\FleetDispatcher of property $fleetDispatcher.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
129
      return new \Fleet\FleetDispatcher($gc);
130
    };
131
132
    $gc->watchdog = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Core\Watchdog of property $watchdog.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
133
      return new Watchdog($gc);
134
    };
135
136
    $gc->valueStorage = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Bonus\ValueStorage of property $valueStorage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Unused Code introduced by
The parameter $gc is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

136
    $gc->valueStorage = function (/** @scrutinizer ignore-unused */ GlobalContainer $gc) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
137
      return new ValueStorage([]);
138
    };
139
140
    $gc->bonusCatalog = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Bonus\BonusCatalog of property $bonusCatalog.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
141
      return new BonusCatalog($gc);
142
    };
143
144
    $gc->general = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type General of property $general.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
145
      return new General($gc);
146
    };
147
148
    $gc->economicHelper = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Meta\Economic\EconomicHelper of property $economicHelper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
149
      return new EconomicHelper($gc);
150
    };
151
152
    $gc->playerLevelHelper = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Player\PlayerLevelHelper of property $playerLevelHelper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
153
      return new PlayerLevelHelper($gc);
154
    };
155
156
    $gc->pimp = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Core\SnPimp of property $pimp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
157
      return new SnPimp($gc);
158
    };
159
160
    $gc->modules = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Modules\ModulesManager of property $modules.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
161
      return new ModulesManager($gc);
162
    };
163
164
    // Dummy objects ---------------------------------------------------------------------------------------------------
165
    $gc->theUser = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type TheUser of property $theUser.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
166
      return new \TheUser($gc);
167
    };
168
169
170
    // Models ----------------------------------------------------------------------------------------------------------
171
    $gc->skinEntityClass = \SkinV2::class;
172
    $gc->skinModel = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type SkinModel of property $skinModel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
173
      return new \SkinModel($gc);
174
    };
175
176
    $gc->textModel = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type TextModel of property $textModel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
177
      return new \TextModel($gc);
178
    };
179
180
181
//    $gc->types = function ($c) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
182
//      return new \Common\Types();
183
//    };
184
//
185
//    $gc->dbOperator = function (GlobalContainer $c) {
186
//      return new \classConfig(SN::$cache_prefix);
187
//    };
188
//
189
//    $gc->localePlayer = function (GlobalContainer $c) {
190
//      return new \classLocale($c->config->server_locale_log_usage);
191
//    };
192
//
193
//    $gc->dbGlobalRowOperator = function (GlobalContainer $c) {
194
//      return new \DbRowDirectOperator($c->db);
195
//    };
196
//
197
//    $gc->query = $gc->factory(function (GlobalContainer $c) {
198
//      return new \DbQueryConstructor($c->db);
199
//    });
200
//
201
//    $gc->cacheOperator = function (GlobalContainer $gc) {
202
//      return new \SnDbCachedOperator($gc);
203
//    };
204
//
205
//    $gc->snCacheClass = 'SnCache';
206
//    $gc->snCache = function (GlobalContainer $gc) {
207
//      return $gc->db->snCache;
208
//    };
209
//
210
//    $gc->buddyClass = 'Buddy\BuddyModel';
211
//    $gc->buddyModel = function (GlobalContainer $c) {
212
//      return new $c->buddyClass($c);
213
//    };
214
//
215
//    $gc->unitModel = function (GlobalContainer $c) {
216
//      return new \V2Unit\V2UnitModel($c);
217
//    };
218
//    $gc->unitList = $this->factory(function (GlobalContainer $c) {
219
//      return new \V2Unit\V2UnitList($c);
220
//    });
221
//
222
//    $gc->fleetModel = function (GlobalContainer $c) {
223
//      return new V2FleetModel($c);
224
//    };
225
//
226
//    $gc->planetRenderer = function (GlobalContainer $c) {
227
//      return new PlanetRenderer($c);
228
//    };
229
//
230
//    $gc->fleetRenderer = function (GlobalContainer $c) {
231
//      return new \FleetRenderer($c);
232
//    };
233
//
234
//    $gc->groupFleet = function (GlobalContainer $c) {
235
//      return sn_get_groups('fleet');
236
//    };
237
//
238
//    $gc->groupFleetAndMissiles = function (GlobalContainer $c) {
239
//      return sn_get_groups(array('fleet', GROUP_STR_MISSILES));
240
//    };
241
//
242
//    $gc->groupRecyclers = function (GlobalContainer $c) {
243
//      return sn_get_groups('flt_recyclers');
244
//    };
245
246
  }
247
248
}
249