Test Failed
Push — master ( 9287ab...2f3843 )
by Georgi
03:56
created

Controller::view()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 6
nop 4
dl 0
loc 25
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Epesi\Core;
4
5
use Illuminate\Routing\Controller as BaseController;
6
use Epesi\Core\System\SystemCore;
7
use Epesi\Core\System\Modules\ModuleManager;
8
use Epesi\Core\Layout\LayoutView;
9
use Illuminate\Support\Facades\File;
10
11
class Controller extends BaseController
12
{
13
    public function index()
14
    {
15
    	return SystemCore::isInstalled()? redirect('home'): redirect('install');
16
    }
17
    
18
    public function install(UI $ui)
19
    {
20
    	// make sure the installation information is fresh
21
    	ModuleManager::clearCache();
22
    	
23
    	if (SystemCore::isInstalled()) return redirect('home');
24
    	
25
    	$ui->title = __(':epesi > Installation', ['epesi' => config('epesi.app.title')]);
0 ignored issues
show
Documentation Bug introduced by
It seems like __(':epesi > Installatio...ig('epesi.app.title'))) can also be of type array. However, the property $title is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
26
    	
27
    	$ui->initLayout('Centered');
28
    	
29
    	$ui->layout->set('logo', url('logo'));
30
    	$ui->layout->template->setHTML('copyright', config('epesi.app.copyright'));
31
    	
32
    	$ui->add(new \Epesi\Core\System\SystemInstallWizard());
33
    	
34
    	return $ui->response();
35
    }
36
    
37
    public function home()
38
    {
39
    	return redirect(SystemCore::isInstalled()? \Epesi\Core\HomePage\Models\HomePage::pathOfUser(): 'install');
40
    }
41
    
42
    public function logo()
43
    { 
44
    	$logoFile = \Epesi\Core\System\Logo\LogoSettings::getLogoFile();
45
46
    	return response(File::get($logoFile), 200, ['Content-type' => File::mimeType($logoFile)])->setMaxAge(604800)->setPublic();
47
    }
48
    
49
    public function view(UI $ui, $module, $method = 'body', $args = [])
50
    {
51
    	$ui->initLayout(new LayoutView());
0 ignored issues
show
Bug introduced by
new Epesi\Core\Layout\LayoutView() of type Epesi\Core\Layout\LayoutView is incompatible with the type array|atk4\ui\Layout\Generic|string expected by parameter $seed of atk4\ui\App::initLayout(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
    	$ui->initLayout(/** @scrutinizer ignore-type */ new LayoutView());
Loading history...
52
    	
53
    	$alias = explode(':', $module);
54
    	
55
    	$moduleAlias = $alias[0];
56
    	$viewAlias = $alias[1]?? null;
57
    	
58
    	$view = null;
59
    	if ($module = ModuleManager::getClass($moduleAlias, true)) {
60
    		$viewClass = $module::view($viewAlias);
61
62
    		if (class_exists($viewClass)) {
63
    			$view = new $viewClass();
64
    		}
65
    	}
66
67
    	if (! $view) abort(404);
68
    	
69
    	$ui->add($view)->displayModuleContent($method, $args);
70
    	
71
    	$ui->setLocation($view->location());
72
    	
73
    	return $ui->response();
74
    }
75
}
76