Completed
Push — trunk ( 91a948...0e7a2e )
by SuperNova.WS
05:44
created

GlobalContainer::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 97
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

101
      /** @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...
102
      return new \debug();
103
    };
104
105
    $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...
106
      return new \classCache($gc->cachePrefix);
107
    };
108
109
    $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...
110
      return new \classConfig($gc->cachePrefix);
111
    };
112
113
114
    $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...
115
      return new Repository($gc);
116
    };
117
118
    $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...
119
      return new \Storage($gc);
120
    };
121
122
    $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...
123
      return new \Design($gc);
124
    };
125
126
    $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...
127
      return new \BBCodeParser($gc);
128
    };
129
130
    $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...
131
      return new \Fleet\FleetDispatcher($gc);
132
    };
133
134
    $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...
135
      return new Watchdog($gc);
136
    };
137
138
    $gc->eventBus = function (GlobalContainer $gc) {
0 ignored issues
show
Documentation Bug introduced by
It seems like function(...) { /* ... */ } of type callable is incompatible with the declared type Event\EventBus of property $eventBus.

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...
139
      return new EventBus($gc);
140
    };
141
142
    $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

142
    $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...
143
      return new ValueStorage([]);
144
    };
145
146
    $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...
147
      return new BonusCatalog($gc);
148
    };
149
150
    $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...
151
      return new General($gc);
152
    };
153
154
    $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...
155
      return new EconomicHelper($gc);
156
    };
157
158
    $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...
159
      return new PlayerLevelHelper($gc);
160
    };
161
162
    $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...
163
      return new SnPimp($gc);
164
    };
165
166
    $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...
167
      return new ModulesManager($gc);
168
    };
169
170
    // Dummy objects ---------------------------------------------------------------------------------------------------
171
    $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...
172
      return new \TheUser($gc);
173
    };
174
175
176
    // Models ----------------------------------------------------------------------------------------------------------
177
    $gc->skinEntityClass = \SkinV2::class;
178
    $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...
179
      return new \SkinModel($gc);
180
    };
181
182
    $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...
183
      return new \TextModel($gc);
184
    };
185
186
187
//    $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...
188
//      return new \Common\Types();
189
//    };
190
//
191
//    $gc->dbOperator = function (GlobalContainer $c) {
192
//      return new \classConfig(SN::$cache_prefix);
193
//    };
194
//
195
//    $gc->localePlayer = function (GlobalContainer $c) {
196
//      return new \classLocale($c->config->server_locale_log_usage);
197
//    };
198
//
199
//    $gc->dbGlobalRowOperator = function (GlobalContainer $c) {
200
//      return new \DbRowDirectOperator($c->db);
201
//    };
202
//
203
//    $gc->query = $gc->factory(function (GlobalContainer $c) {
204
//      return new \DbQueryConstructor($c->db);
205
//    });
206
//
207
//    $gc->cacheOperator = function (GlobalContainer $gc) {
208
//      return new \SnDbCachedOperator($gc);
209
//    };
210
//
211
//    $gc->snCacheClass = 'SnCache';
212
//    $gc->snCache = function (GlobalContainer $gc) {
213
//      return $gc->db->snCache;
214
//    };
215
//
216
//    $gc->buddyClass = 'Buddy\BuddyModel';
217
//    $gc->buddyModel = function (GlobalContainer $c) {
218
//      return new $c->buddyClass($c);
219
//    };
220
//
221
//    $gc->unitModel = function (GlobalContainer $c) {
222
//      return new \V2Unit\V2UnitModel($c);
223
//    };
224
//    $gc->unitList = $this->factory(function (GlobalContainer $c) {
225
//      return new \V2Unit\V2UnitList($c);
226
//    });
227
//
228
//    $gc->fleetModel = function (GlobalContainer $c) {
229
//      return new V2FleetModel($c);
230
//    };
231
//
232
//    $gc->planetRenderer = function (GlobalContainer $c) {
233
//      return new PlanetRenderer($c);
234
//    };
235
//
236
//    $gc->fleetRenderer = function (GlobalContainer $c) {
237
//      return new \FleetRenderer($c);
238
//    };
239
//
240
//    $gc->groupFleet = function (GlobalContainer $c) {
241
//      return sn_get_groups('fleet');
242
//    };
243
//
244
//    $gc->groupFleetAndMissiles = function (GlobalContainer $c) {
245
//      return sn_get_groups(array('fleet', GROUP_STR_MISSILES));
246
//    };
247
//
248
//    $gc->groupRecyclers = function (GlobalContainer $c) {
249
//      return sn_get_groups('flt_recyclers');
250
//    };
251
252
  }
253
254
}
255