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 ( 4e3b80...57ffd6 )
by Alexey
08:08
created

BPagination::setItemCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Dmitriy Ostashev <[email protected]>
4
 * @property string $actionUrl
5
 */
6
class BPagination extends CPagination
7
{
8
  const MAX_PAGE_SIZE = PHP_INT_MAX;
9
10
  /**
11
   * Массив элементов, используемых для вывода
12
   * в форме вариантов отображения элементов страниц
13
   * @var array
14
   */
15
  public $pageSizeList = [10 => 10, 50 => 50, 100 => 100, 500 => 500, 1000 => 1000, 5000 => 5000, self::MAX_PAGE_SIZE => 'Все'];
16
17
  /** @var  int Идентефикатор переменной кол-ва элементов на странице */
18
  public $pageSizeVar;
19
20
  /** @var  string Url сабмита формы - выбора кол-ва элементов на странице */
21
  protected $_actionUrl;
22
23
  protected $_pageSize = self::DEFAULT_PAGE_SIZE;
24
25
  protected $_itemCount = 0;
26
27 7
  public function getPageSize()
0 ignored issues
show
Coding Style introduced by
getPageSize uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
  {
29 7
    if( !empty($_GET[$this->pageSizeVar]) )
30 7
      $this->_pageSize = $_GET[$this->pageSizeVar];
31
32 7
    return (int)$this->_pageSize === 0 ? self::DEFAULT_PAGE_SIZE : $this->_pageSize;
33
  }
34
35
  /**
36
   * @param $val
37
   */
38
  public function setActionUrl($val)
39
  {
40
    $this->_actionUrl = $val;
41
  }
42
43
  /**
44
   * @return string
45
   */
46 1
  public function getActionUrl()
0 ignored issues
show
Coding Style introduced by
getActionUrl uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
47
  {
48 1
    if( $this->_actionUrl === null )
49 1
    {
50 1
      $route = Yii::app()->controller instanceof CController ? Yii::app()->controller->route : '';
0 ignored issues
show
Bug introduced by
The class CController does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51 1
      $params = $_GET;
52 1
      unset($params[$this->pageSizeVar], $params['ajax']);
53 1
      $this->_actionUrl = Yii::app()->createUrl($route, $params);
54 1
    }
55
56 1
    return $this->_actionUrl;
57
  }
58
59
  /**
60
   * @return integer number of pages
61
   */
62
  public function getPageCount()
63
  {
64
    return (int)(($this->_itemCount + $this->_pageSize - 1) / $this->_pageSize);
65
  }
66
67
  /**
68
   * @param integer $value total number of items.
69
   */
70 10
  public function setItemCount($value)
71
  {
72 10
    if( ($this->_itemCount = $value) < 0 )
73 10
      $this->_itemCount = 0;
74 10
  }
75
76
  /**
77
   * Создание формы для отображения вариантов количества элементов
78
   * @return string of form
79
   */
80 1
  public function getPageSizeForm()
81
  {
82 1
    $formProperties = ['class' => 'page-size'];
83
84 1
    $form = CHtml::beginForm($this->actionUrl, 'get', $formProperties);
85 1
    $form .= CHtml::tag('span', ['class' => 'page-size-title'], 'Отображать по: ');
86 1
    $form .= CHtml::dropDownList($this->pageSizeVar, $this->getPageSize(), $this->pageSizeList);
87 1
    $form .= CHtml::endForm();
88
89
    $formChangeHandler = <<<JS
90 1
$('body').on('change', '.{$formProperties['class']} select', function(){
91
  if ( window.History.enabled ) {
92
      var url = $(this).parents('form').attr('action').split('?');
93
      var params = url[1] === undefined ? [] : $.deparam.querystring('?'+url[1]);
94
      params[$(this).attr('id')] = $(this).val();
95
      window.History.pushState(null, document.title, decodeURIComponent($.param.querystring(url[0], params)));
96
  } else {
97 1
      $(this).parents('.{$formProperties['class']}').submit();
98
  }
99 1
});
100 1
JS;
101 1
    Yii::app()->getClientScript()->registerScript('pageSizeChangeHandler', $formChangeHandler, CClientScript::POS_READY);
102
103 1
    return $form;
104
  }
105
}