Completed
Push — master ( 3207da...7dc2aa )
by Song
03:07
created

Modal::display()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 35
rs 9.36
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Displayers;
4
5
class Modal extends AbstractDisplayer
6
{
7
    public function display($callback = null)
8
    {
9
        if (func_num_args() == 2) {
10
            list($title, $callback) = func_get_args();
11
        } elseif (func_num_args() == 1) {
12
            $title = $this->trans('title');
13
        }
14
15
        $callback = $callback->bindTo($this->row);
16
17
        $html = call_user_func_array($callback, [$this->row]);
18
19
        $key = $this->getKey();
20
21
        return <<<EOT
22
<span class="grid-expand" data-toggle="modal" data-target="#grid-modal-{$key}">
23
   <a href="javascript:void(0)"><i class="fa fa-angle-double-down"></i>&nbsp;&nbsp;{$this->value}</a>
24
</span>
25
26
<div class="modal fade" id="grid-modal-{$key}" tabindex="-1" role="dialog">
27
  <div class="modal-dialog modal-lg" role="document">
28
    <div class="modal-content">
29
      <div class="modal-header">
30
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
31
        <h4 class="modal-title">{$title}</h4>
0 ignored issues
show
Bug introduced by
The variable $title 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...
32
      </div>
33
      <div class="modal-body">
34
        {$html}
35
      </div>
36
    </div>
37
  </div>
38
</div>
39
40
EOT;
41
    }
42
}