Completed
Push — work-fleets ( 4ec5b3...fe2ede )
by SuperNova.WS
10:06
created

GlobalContainer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 13

Test Coverage

Coverage 0%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
dl 0
loc 66
rs 10
c 8
b 0
f 0
ccs 0
cts 22
cp 0
wmc 1
lcom 0
cbo 13

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 62 1
1
<?php
2
3
namespace Common;
4
5
use \classSupernova;
6
use V2Fleet\V2FleetModel;
7
8
/**
9
 * Class GlobalContainer
10
 *
11
 * Used to describe internal structures of container
12
 *
13
 * @package Pimple
14
 *
15
 * @property \debug               $debug
16
 * @property \db_mysql            $db
17
 * @property \classCache          $cache
18
 * @property \classConfig         $config
19
 * @property \classLocale         $localePlayer
20
 * @property \DbQueryConstructor  $query
21
 * @property \DbRowDirectOperator $dbGlobalRowOperator
22
 * @property \SnDbCachedOperator  $cacheOperator - really DB record operator. But let it be
23
 * @property string               $snCacheClass
24
 * @property \SnCache             $snCache
25
 * @property \Common\Types        $types
26
 * @property string               $buddyClass
27
 * @property \Buddy\BuddyModel    $buddyModel
28
 * @property \V2Unit\V2UnitModel  $unitModel
29
 * @property V2FleetModel         $fleetModel
30
 */
31
class GlobalContainer extends ContainerPlus {
32
33
  public function __construct(array $values = array()) {
34
    parent::__construct($values);
35
36
    $gc = $this;
37
38
    // Default db
39
    $gc->db = function ($c) {
40
      classSupernova::$db = $db = new \db_mysql($c);
41
42
      return $db;
43
    };
44
45
    $gc->debug = function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
46
      return new \debug();
47
    };
48
49
    $gc->types = function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
50
      return new \Common\Types();
51
    };
52
53
    $gc->cache = function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
54
      return new \classCache(classSupernova::$cache_prefix);
55
    };
56
57
    $gc->config = function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
58
      return new \classConfig(classSupernova::$cache_prefix);
59
    };
60
61
    $gc->localePlayer = function (GlobalContainer $c) {
62
      return new \classLocale($c->config->server_locale_log_usage);
63
    };
64
65
    $gc->dbGlobalRowOperator = function (GlobalContainer $c) {
66
      return new \DbRowDirectOperator($c->db);
0 ignored issues
show
Bug introduced by
It seems like $c->db can also be of type object<Closure>; however, DbRowDirectOperator::__construct() does only seem to accept object<db_mysql>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67
    };
68
69
    $gc->query = $gc->factory(function (GlobalContainer $c) {
70
      return new \DbQueryConstructor($c->db);
0 ignored issues
show
Bug introduced by
It seems like $c->db can also be of type object<Closure>; however, DbSqlAware::__construct() does only seem to accept object<db_mysql>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
71
    });
72
73
    $gc->cacheOperator = function (GlobalContainer $gc) {
74
      return new \SnDbCachedOperator($gc);
75
    };
76
77
    $gc->snCacheClass = 'SnCache';
78
    $gc->snCache = function (GlobalContainer $gc) {
79
      return $gc->db->snCache;
80
    };
81
82
    $gc->buddyClass = 'Buddy\BuddyModel';
83
    $gc->buddyModel = function (GlobalContainer $c) {
84
      return new $c->buddyClass($c);
85
    };
86
87
    $gc->unitModel = function (GlobalContainer $c) {
88
      return new \V2Unit\V2UnitModel($c);
89
    };
90
91
    $gc->fleetModel = function (GlobalContainer $c) {
92
      return new V2FleetModel($c);
93
    };
94
  }
95
96
}
97