Completed
Push — master ( 8d14cd...aab142 )
by Aimeos
01:56
created

src/Aimeos/Shop/Controller/AccountController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Controller
8
 */
9
10
11
namespace Aimeos\Shop\Controller;
12
13
use Aimeos\Shop\Facades\Shop;
14
use Illuminate\Routing\Controller;
15
use Illuminate\Support\Facades\Response;
16
17
18
/**
19
 * Aimeos controller for account related functionality.
20
 *
21
 * @package laravel
22
 * @subpackage Controller
23
 */
24
class AccountController extends Controller
25
{
26
	/**
27
	 * Returns the html for the "My account" page.
28
	 *
29
	 * @return \Illuminate\Http\Response Response object with output and headers
30
	 */
31
	public function indexAction()
32
	{
33
		$default = ['account/profile','account/subscription','account/history','account/favorite','account/watch','basket/mini','catalog/session'];
34
35
		foreach( app( 'config' )->get( 'shop.page.account-index', $default ) as $name )
36
		{
37
			$params['aiheader'][$name] = Shop::get( $name )->getHeader();
38
			$params['aibody'][$name] = Shop::get( $name )->getBody();
39
		}
40
41
		return Response::view('shop::account.index', $params);
0 ignored issues
show
The variable $params 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...
42
	}
43
44
45
	/**
46
	 * Returns the html for the "My account" download page.
47
	 *
48
	 * @return \Illuminate\Contracts\View\View View for rendering the output
49
	 */
50
	public function downloadAction()
51
	{
52
		$response = Shop::get( 'account/download' )->getView()->response();
53
		return Response::make( (string) $response->getBody(), $response->getStatusCode(), $response->getHeaders() );
54
	}
55
}