Completed
Push — work-fleets ( ec9dc8...d7065d )
by SuperNova.WS
06:07
created

classSupernova::init_global_objects()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 10
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 10
b 0
f 0
nc 4
nop 0
dl 0
loc 17
rs 9.4285
ccs 0
cts 10
cp 0
crap 12
1
<?php
2
3
use Vector\Vector;
4
5
use Common\GlobalContainer;
6
7
class classSupernova {
8
  /**
9
   * @var GlobalContainer $gc
10
   */
11
  public static $gc;
12
13
  /**
14
   * @var array $sn_mvc
15
   */
16
  public static $sn_mvc = array();
17
18
  /**
19
   * @var array $functions
20
   */
21
  public static $functions = array();
22
23
  /**
24
   * @var array[] $design
25
   */
26
  public static $design = array(
27
    'bbcodes' => array(),
28
    'smiles'  => array(),
29
  );
30
31
  /**
32
   * Основная БД для доступа к данным
33
   *
34
   * @var db_mysql $db
35
   */
36
  public static $db;
37
  public static $db_name = '';
38
  /**
39
   * @var \DBAL\DbTransaction $transaction
40
   */
41
  public static $transaction;
42
43
  /**
44
   * Настройки из файла конфигурации
45
   *
46
   * @var string $cache_prefix
47
   */
48
  public static $cache_prefix = '';
49
  public static $sn_secret_word = '';
50
51
  /**
52
   * Конфигурация игры
53
   *
54
   * @var classConfig $config
55
   */
56
  public static $config;
57
58
  /**
59
   * External cache
60
   *
61
   * @var classCache $cache
62
   */
63
  public static $cache;
64
65
  /**
66
   * @var core_auth $auth
67
   */
68
  public static $auth = null;
69
70
71
  public static $user = array();
72
  /**
73
   * @var userOptions $user_options
74
   */
75
  public static $user_options;
76
77
  /**
78
   * @var debug $debug
79
   */
80
  public static $debug = null;
81
82
  public static $options = array();
83
84
  public static function log_file($message, $spaces = 0) {
85
    if (self::$debug) {
86
      self::$debug->log_file($message, $spaces);
87
    }
88
  }
89
90
  public static function init_0_prepare() {
91
    static::$gc = new GlobalContainer();
92
  }
93
94
  public static function init_3_load_config_file() {
95
    $dbsettings = array();
96
    require(SN_ROOT_PHYSICAL . "config" . DOT_PHP_EX);
97
    self::$cache_prefix = !empty($dbsettings['cache_prefix']) ? $dbsettings['cache_prefix'] : $dbsettings['prefix'];
98
    self::$db_name = $dbsettings['name'];
99
    self::$sn_secret_word = $dbsettings['secretword'];
100
    unset($dbsettings);
101
  }
102
103
  public static function init_global_objects() {
104
    self::$debug = self::$gc->debug;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$gc->debug can also be of type object<Closure>. However, the property $debug is declared as type object<debug>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
105
    self::$db = self::$gc->db;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$gc->db can also be of type object<Closure>. However, the property $db is declared as type object<db_mysql>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
106
    self::$user_options = new userOptions(0);
107
108
    // Initializing global 'cacher' object
109
    self::$cache = self::$gc->cache;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$gc->cache can also be of type object<Closure>. However, the property $cache is declared as type object<classCache>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
110
111
    empty(static::$cache->tables) ? sys_refresh_tablelist() : false;
112
    empty(static::$cache->tables) ? die('DB error - cannot find any table. Halting...') : false;
113
114
    // Initializing global "config" object
115
    static::$config = self::$gc->config;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$gc->config can also be of type object<Closure>. However, the property $config is declared as type object<classConfig>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
116
117
    // Initializing statics
118
    Vector::_staticInit(static::$config);
0 ignored issues
show
Bug introduced by
It seems like static::$config can also be of type object<Closure>; however, Vector\Vector::_staticInit() does only seem to accept object<classConfig>, 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...
119
  }
120
121
  public static function init_debug_state() {
122
    if ($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) {
123
      define('BE_DEBUG', true);
124
    }
125
    // define('DEBUG_SQL_ONLINE', true); // Полный дамп запросов в рил-тайме. Подойдет любое значение
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
126
    define('DEBUG_SQL_ERROR', true); // Выводить в сообщении об ошибке так же полный дамп запросов за сессию. Подойдет любое значение
127
    define('DEBUG_SQL_COMMENT_LONG', true); // Добавлять SQL запрос длинные комментарии. Не зависим от всех остальных параметров. Подойдет любое значение
128
    define('DEBUG_SQL_COMMENT', true); // Добавлять комментарии прямо в SQL запрос. Подойдет любое значение
129
    // Включаем нужные настройки
130
    defined('DEBUG_SQL_ONLINE') && !defined('DEBUG_SQL_ERROR') ? define('DEBUG_SQL_ERROR', true) : false;
131
    defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
132
    defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
133
134
    if (defined('BE_DEBUG') || static::$config->debug) {
135
      @define('BE_DEBUG', true);
136
      @ini_set('display_errors', 1);
137
      @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
138
    } else {
139
      @define('BE_DEBUG', false);
140
      @ini_set('display_errors', 0);
141
    }
142
143
  }
144
145
}
146