Test Failed
Push — trunk ( db071f...8d464a )
by SuperNova.WS
06:33
created

SnBootstrap::install_benchmark()   D

Complexity

Conditions 10
Paths 1

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 20
nc 1
nop 0
dl 0
loc 30
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

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
 * Created by Gorlum 11.06.2017 9:58
4
 */
5
6
namespace Core;
7
8
9
use \classSupernova;
10
11
class SnBootstrap {
12
13
  public static function install_benchmark() {
14
    register_shutdown_function(function () {
15
      if(defined('IN_AJAX')) {
16
        return;
17
      }
18
19
      global $user, $locale_cache_statistic;
20
21
      $now = microtime(true);
22
      $totalTime = round($now - SN_TIME_MICRO, 6);
23
      $executionTime = round(SN_TIME_RENDER_START - SN_TIME_MICRO, 6);
24
      $displayTime = round($now - SN_TIME_RENDER_START, 6);
25
26
      $otherTime = defined('SN_TIME_RENDER_START') ? " (exec: {$executionTime}, display: {$displayTime})" : '';
27
28
      print('<div id="benchmark" class="benchmark"><hr>Benchmark ' . $totalTime . 's' . $otherTime . ', memory: ' . number_format(memory_get_usage() - SN_MEM_START) .
29
        (!empty($locale_cache_statistic['misses']) ? ', LOCALE MISSED' : '') .
30
        (class_exists('classSupernova') && is_object(classSupernova::$db) ? ', DB time: ' . round(classSupernova::$db->time_mysql_total, 6) . 's' : '') .
31
        '</div>');
32
      if($user['authlevel'] >= 2 && file_exists(SN_ROOT_PHYSICAL . 'badqrys.txt') && @filesize(SN_ROOT_PHYSICAL . 'badqrys.txt') > 0) {
33
        echo '<a href="badqrys.txt" target="_blank" style="color:red">', 'HACK ALERT!', '</a>';
34
      }
35
36
      if(!empty($locale_cache_statistic['misses'])) {
37
        print('<!--');
38
        pdump($locale_cache_statistic);
39
        print('-->');
40
      }
41
    });
42
  }
43
44
  public static function init_debug_state() {
45
    if($_SERVER['SERVER_NAME'] == 'localhost' && !defined('BE_DEBUG')) {
46
      define('BE_DEBUG', true);
47
    }
48
    // 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...
49
    define('DEBUG_SQL_ERROR', true); // Выводить в сообщении об ошибке так же полный дамп запросов за сессию. Подойдет любое значение
50
    define('DEBUG_SQL_COMMENT_LONG', true); // Добавлять SQL запрос длинные комментарии. Не зависим от всех остальных параметров. Подойдет любое значение
51
    define('DEBUG_SQL_COMMENT', true); // Добавлять комментарии прямо в SQL запрос. Подойдет любое значение
52
    // Включаем нужные настройки
53
    defined('DEBUG_SQL_ONLINE') && !defined('DEBUG_SQL_ERROR') ? define('DEBUG_SQL_ERROR', true) : false;
54
    defined('DEBUG_SQL_ERROR') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
55
    defined('DEBUG_SQL_COMMENT_LONG') && !defined('DEBUG_SQL_COMMENT') ? define('DEBUG_SQL_COMMENT', true) : false;
56
57
    if(defined('BE_DEBUG') || classSupernova::$config->debug) {
0 ignored issues
show
Documentation introduced by
The property debug does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
58
      @define('BE_DEBUG', true);
59
      @ini_set('display_errors', 1);
60
      @error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
61
    } else {
62
      @define('BE_DEBUG', false);
63
      @ini_set('display_errors', 0);
64
    }
65
66
  }
67
68
  /**
69
   * @param \classConfig $config
70
   */
71
  public static function performUpdate(&$config) {
72
    $update_file = SN_ROOT_PHYSICAL . "includes/update.php";
73
    if(
74
      !file_exists($update_file)
75
      ||
76
      (
77
        filemtime($update_file) <= $config->db_loadItem('var_db_update')
78
        &&
79
        $config->db_loadItem('db_version') >= DB_VERSION
80
      )
81
    ) {
82
      return;
83
    }
84
85
    if(defined('IN_ADMIN')) {
86
      sn_db_transaction_start(); // Для защиты от двойного запуска апдейта - начинаем транзакцию. Так запись в базе будет блокирована
87
      if(SN_TIME_NOW >= $config->db_loadItem('var_db_update_end')) {
88
        $config->db_saveItem('var_db_update_end', SN_TIME_NOW + ($config->upd_lock_time ? $config->upd_lock_time : 300));
0 ignored issues
show
Documentation introduced by
The property upd_lock_time does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
89
        sn_db_transaction_commit();
90
91
        require_once($update_file);
92
93
        $current_time = time();
94
        $config->db_saveItem('var_db_update', $current_time);
95
        $config->db_saveItem('var_db_update_end', $current_time);
96
      } elseif(filemtime($update_file) > $config->var_db_update) {
0 ignored issues
show
Documentation introduced by
The property var_db_update does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
97
        $timeout = $config->var_db_update_end - SN_TIME_NOW;
0 ignored issues
show
Documentation introduced by
The property var_db_update_end does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
98
        die(
99
        "Обновляется база данных. Рассчетное время окончания - {$timeout} секунд (время обновления может увеличиваться). Пожалуйста, подождите...<br />
100
        Obnovljaetsja baza dannyh. Rasschetnoe vremya okonchanija - {$timeout} secund. Pozhalujsta, podozhdute...<br />
101
        Database update in progress. Estimated update time {$timeout} seconds (can increase depending on update process). Please wait..."
102
        );
103
      }
104
      sn_db_transaction_rollback();
105
    } else {
106
      die(
107
      'Происходит обновление сервера - пожалуйста, подождите...<br />
108
      Proishodit obnovlenie servera - pozhalujsta, podozhdute...<br />
109
      Server upgrading now - please wait...<br />
110
      <a href="admin/overview.php">Admin link</a>'
111
      );
112
    }
113
  }
114
115
}
116