Completed
Push — work-fleets ( 6cc592...094cef )
by SuperNova.WS
06:07
created

GlobalContainer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 12

Test Coverage

Coverage 52.38%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
dl 0
loc 62
rs 10
c 6
b 0
f 0
ccs 11
cts 21
cp 0.5238
wmc 1
lcom 0
cbo 12

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 58 1
1
<?php
2
3
namespace Common;
4
5
use \classSupernova;
6
7
/**
8
 * Class GlobalContainer
9
 *
10
 * Used to describe internal structures of container
11
 *
12
 * @package Pimple
13
 *
14
 * @property \debug               $debug
15
 * @property \db_mysql            $db
16
 * @property \classCache          $cache
17
 * @property \classConfig         $config
18
 * @property \classLocale         $localePlayer
19
 * @property \DbQueryConstructor  $query
20
 * @property \DbRowDirectOperator $dbGlobalRowOperator
21
 * @property \SnDbCachedOperator  $cacheOperator - really DB record operator. But let it be
22
 * @property string               $snCacheClass
23
 * @property \SnCache             $snCache
24
 * @property \Common\Types        $types
25
 * @property string               $buddyClass
26
 * @property \Buddy\BuddyModel    $buddyModel
27
 * @property \V2Unit\V2UnitModel  $unitModel
28
 */
29
class GlobalContainer extends ContainerPlus {
30
31 1
  public function __construct(array $values = array()) {
32 1
    parent::__construct($values);
33
34 1
    $gc = $this;
35
36
    // Default db
37
    $gc->db = function ($c) {
38 1
      classSupernova::$db = $db = new \db_mysql($c);
39
40 1
      return $db;
41
    };
42
43
    $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...
44
      return new \debug();
45
    };
46
47
    $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...
48 1
      return new \Common\Types();
49
    };
50
51
    $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...
52
      return new \classCache(classSupernova::$cache_prefix);
53
    };
54
55
    $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...
56
      return new \classConfig(classSupernova::$cache_prefix);
57
    };
58
59
    $gc->localePlayer = function (GlobalContainer $c) {
60
      return new \classLocale($c->config->server_locale_log_usage);
61
    };
62
63
    $gc->dbGlobalRowOperator = function (GlobalContainer $c) {
64 1
      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...
65
    };
66
67
    $gc->query = $gc->factory(function (GlobalContainer $c) {
68
      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...
69 1
    });
70
71
    $gc->cacheOperator = function (GlobalContainer $gc) {
72
      return new \SnDbCachedOperator($gc);
73
    };
74
75 1
    $gc->snCacheClass = 'SnCache';
76
    $gc->snCache = function (GlobalContainer $gc) {
77
      return $gc->db->snCache;
78
    };
79
80 1
    $gc->buddyClass = 'Buddy\BuddyModel';
81
    $gc->buddyModel = function (GlobalContainer $c) {
82
      return new $c->buddyClass($c);
83
    };
84
85
    $gc->unitModel = function (GlobalContainer $c) {
86
      return new \V2Unit\V2UnitModel($c);
87
    };
88 1
  }
89
90
}
91