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.
Completed
Push — master ( 61aacd...05f06e )
by Alexey
18:53
created

BBaseLogViewController::formatHeader()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
rs 8.7972
cc 4
eloc 15
nc 6
nop 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @author Alexey Tatarinov <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2016 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 */
8
Yii::import('backend.modules.product.modules.import.components.ImportHelper');
9
10
class BBaseLogViewController extends BController
11
{
12
  public $enabled = false;
13
14
  public $name = '';
15
16
  public $logDirPath = 'protected/runtime';
17
18
  public $logFileName = 'application.log';
19
20
  public $showBy = 200;
21
22
  public function actionIndex()
23
  {
24
    $logPath = $this->getBasePath().ImportHelper::wrapInSlash($this->logDirPath).$this->logFileName;
25
26
    if( file_exists($logPath) )
27
    {
28
      $log = $this->formatLog(file($logPath));
29
30
      $log = array_slice(array_reverse($log), 0, $this->showBy);
31
32
      $dataLog = implode('<br/>', $log);
33
    }
34
    else
35
    {
36
      $dataLog = "Нет данных";
37
    }
38
39
    $this->render('index', array('dataLog' => $dataLog));
40
  }
41
42
  protected function formatLog($log)
43
  {
44
    $blockList = array();
45
    $block = '';
46
    $blockStarted = false;
47
    foreach($log as $line)
48
    {
49
      if( preg_match('/^(\d\d\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d)(.*)/', $line) )
50
      {
51
        if( $blockStarted )
52
        {
53
          $block .= '</div>';
54
          $blockList[] = $block;
55
          $block = '';
56
          $blockStarted = false;
0 ignored issues
show
Unused Code introduced by
$blockStarted is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
        }
58
59
        $blockStarted = true;
60
        $block .= $this->formatHeader($line);
61
        $block .= '<div class="log-body" style="display: none; padding-left: 15px; line-height: 1.5;">';
62
      }
63
      else
64
      {
65
        $block .= $line.'<br/>';
66
      }
67
    }
68
69
    if( !empty($block) )
70
    {
71
      $block .= '</div>';
72
      $blockList[] = $block;
73
    }
74
75
    return $blockList;
76
  }
77
78
  protected function formatHeader($text)
79
  {
80
    if( preg_match('/\[error\]/', $text) )
81
      $color = 'ffa799';
82
    else if( preg_match('/\[info\]/', $text) )
83
      $color = 'f5f5ff';
84
    else
85
      $color = 'fcfbc0';
86
87
    $header = '<div class="log-header" style="cursor: pointer; color: black; background-color: #'.$color.'; line-height: 2; padding-left: 7px; margin-bottom: 3px;">';
88
    if( preg_match('/^(\d\d\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d)(.*)/', $text, $result) )
89
    {
90
      $header .= '<b>'.$result[1].'</b>';
91
      $header .= CHtml::encode($result[2]);
92
    }
93
    else
94
    {
95
      $header .= CHtml::encode($text);
96
    }
97
    $header .= '</div>';
98
99
    return $header;
100
  }
101
102
  protected function getBasePath()
103
  {
104
    return realpath(Yii::getPathOfAlias('frontend').'/..');
105
  }
106
}