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 ( 39854f...c2caf1 )
by Alexey
17:19
created

OnFlyWidget::run()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9713
ccs 0
cts 18
cp 0
cc 3
eloc 15
nc 3
nop 0
crap 12
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
class OnFlyWidget extends CWidget
9
{
10
  const TYPE_INPUT = 'input';
11
12
  const TYPE_DROPDOWN = 'dropDown';
13
14
  /**
15
   * URL для AJAX запроса.
16
   *
17
   * @var string
18
   */
19
  public $ajaxUrl;
20
21
  /**
22
   * @var string $type тип (OnFlyWidget::TYPE_INPUT, OnFlyWidget::TYPE_DROPDOWN)
23
   */
24
  public $type;
25
26
  public $items = array();
27
28
  public $attribute;
29
30
  public $primaryKey;
31
32
  public $value;
33
34
  public $htmlOptions = array();
35
36
  public function init()
37
  {
38
    if( !isset($this->ajaxUrl, $this->attribute, $this->primaryKey) )
39
      throw new RequiredPropertiesException(__CLASS__, array('ajaxUrl', 'attribute', 'primaryKey', 'type'));
40
41
      self::registerOnFlyScripts();
42
  }
43
44
  public function run()
45
  {
46
    $htmlOptions = CMap::mergeArray($this->htmlOptions, array(
47
      'data-onflyedit' => implode('-', array($this->attribute, $this->primaryKey)),
48
      'data-ajax-url' => $this->ajaxUrl,
49
    ));
50
51
    switch($this->type)
52
    {
53
      case self::TYPE_INPUT;
54
        $htmlOptions['class'] = 'onfly-edit';
55
        $html = CHtml::tag('span', $htmlOptions, $this->value);
56
      break;
57
58
      case self::TYPE_DROPDOWN;
59
        $htmlOptions['class'] = 'onfly-edit-dropdown';
60
        $htmlOptions['style'] = 'margin-bottom: 0px; width: auto;';
61
62
        $html = CHtml::dropDownList('', $this->value, $this->items, $htmlOptions);
63
      break;
64
    }
65
66
    echo $html;
0 ignored issues
show
Bug introduced by
The variable $html does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
67
  }
68
69 1
  public static function registerOnFlyScripts()
70
  {
71 1
    $scriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__).'/js');
72 1
    Yii::app()->clientScript->registerScriptFile($scriptUrl.'/jquery.onFlyEdit.js', CClientScript::POS_END);
73 1
    Yii::app()->clientScript->registerScriptFile($scriptUrl.'/onFlyModule.js', CClientScript::POS_END);
74
  }
75
}