TextPicture::renderInternal()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 3
eloc 10
nc 4
nop 0
1
<?php
2
/**
3
 * Render text w/ picture element
4
 *
5
 * @author  Tim Lochmüller
6
 */
7
8
namespace FRUIT\Ink\Rendering;
9
10
/**
11
 * Render text w/ picture element
12
 */
13
class TextPicture extends AbstractRendering
14
{
15
16
    /**
17
     * Render the given element
18
     *
19
     * @return array
20
     */
21
    public function renderInternal()
22
    {
23
        $image = new Image();
24
        if (!($this->contentObject->data['imageorient'] & 24)) {
25
            $lines = $image->render($this->contentObject, $this->configuration);
26
            $lines[] = '';
27
        }
28
        $lines[] = $this->breakContent(strip_tags($this->parseBody($this->contentObject->data['bodytext'])));
0 ignored issues
show
Bug introduced by
The variable $lines 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...
29
        if ($this->contentObject->data['imageorient'] & 24) {
30
            $lines[] = '';
31
            $lines = array_merge($lines, $image->render($this->contentObject, $this->configuration));
32
        }
33
        return $lines;
34
    }
35
}
36