GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ConsoleFileLogger::log()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 3
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2015 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 */
8
Yii::import('frontend.share.formatters.*');
9
10
class ConsoleFileLogger extends CFileLogRoute
11
{
12
  public $showLog = true;
13
14
  private $timers = array();
15
16
  /**
17
   * @var CFileLogRoute $logger
18
   */
19
  private $logger;
20
21
  public function __construct($fileName)
22
  {
23
    $this->logger = new CLogger();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \CLogger() of type object<CLogger> is incompatible with the declared type object<CFileLogRoute> of property $logger.

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...
24
    $this->logger->autoFlush = 20;
25
    $this->logger->attachEventHandler('onFlush', array($this, 'onFlush'));
26
27
    $this->setLogFile($fileName);
28
    $this->init();
29
  }
30
31
  /**
32
   * @param string $message
33
   * @param bool $writeNow
34
   * @param bool $writeMemoryUsage
35
   */
36 View Code Duplication
  public function log($message, $writeNow = false, $writeMemoryUsage = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
  {
38
    if( $writeMemoryUsage )
39
      $this->addMemoryUsage($message);
40
41
    $this->logger->log($message, 'info', 'console');
42
43
    if( $writeNow )
44
      $this->flush();
45
46
    if( $this->showLog )
47
      echo $message.PHP_EOL;
48
  }
49
50
  /**
51
   * @param string $message
52
   * @param bool $writeNow
53
   * @param bool $writeMemoryUsage
54
   */
55 View Code Duplication
  public function warning($message, $writeNow = false, $writeMemoryUsage = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
  {
57
    if( $writeMemoryUsage )
58
      $this->addMemoryUsage($message);
59
60
    $this->logger->log($message, 'warning', 'console');
61
62
    if( $writeNow )
63
      $this->flush();
64
65
    if( $this->showLog )
66
      echo $message.PHP_EOL;
67
  }
68
69
  /**
70
   * @param string $message
71
   * @param bool $writeNow
72
   * @param bool $writeMemoryUsage
73
   */
74 View Code Duplication
  public function error($message, $writeNow = true, $writeMemoryUsage = true)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
  {
76
    if( $writeMemoryUsage )
77
      $this->addMemoryUsage($message);
78
79
    $this->logger->log($message, 'error', 'console');
80
81
    if( $writeNow )
82
      $this->flush();
83
84
    if( $this->showLog )
85
      echo $message.PHP_EOL;
86
  }
87
88
  /**
89
   * Сохраняет лог в файл с очисткой сообщений из памяти
90
   */
91
  public function flush()
92
  {
93
    $this->logger->flush();
94
  }
95
96
  public function __destruct()
97
  {
98
    $this->logger->flush();
99
  }
100
101
  /**
102
   * Сохраняет лог в файл, сообщения остаются в памяти при прямом вызове метода
103
   */
104
  public function onFlush()
105
  {
106
    $this->collectLogs($this->logger, true);
107
  }
108
109
  public function addMemoryUsage(&$message)
110
  {
111
    $message .= PHP_EOL.'Использовано памяти: '.Yii::app()->format->formatSize(memory_get_usage());
112
    $message .= ', пик: '.Yii::app()->format->formatSize(memory_get_peak_usage());
113
    $load = sys_getloadavg();
114
    $message .= sprintf(", la: %.2f,  %.2f, %.2f", $load[0], $load[1], $load[2]).PHP_EOL;
115
  }
116
117
  public function formatTime($time)
118
  {
119
    return sprintf("%d мин. %d с.", $time / 60, $time % 60);
120
  }
121
122
  public function startTimer($timerId)
123
  {
124
    if( isset($this->timers[$timerId]) )
125
      throw new Exception("Таймер в с ".$timerId." уже создан");
126
127
    $this->timers[$timerId] = microtime(true);
128
  }
129
130
  public function finishTimer($timerId, $message = '')
131
  {
132
    if( !isset($this->timers[$timerId]) )
133
      throw new Exception("Таймер в с ".$timerId."  не был создан");
134
135
    $time = microtime(true) - $this->timers[$timerId];
136
137
    $message .= $this->formatTime($time);
138
139
    return $message;
140
  }
141
}