Controller   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
c 0
b 0
f 0
dl 0
loc 61
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A home() 0 3 2
A logo() 0 5 1
A index() 0 3 2
A install() 0 17 2
A view() 0 23 4
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
use atk4\ui\Layout;
11
12
class Controller extends BaseController
13
{
14
    public function index()
15
    {
16
    	return SystemCore::isInstalled()? redirect('home'): redirect('install');
17
    }
18
    
19
    public function install(UI $ui)
20
    {
21
    	// make sure the installation information is fresh
22
    	ModuleManager::clearCache();
23
    	
24
    	if (SystemCore::isInstalled()) return redirect('home');
25
    	
26
    	$ui->title = __(':epesi > Installation', ['epesi' => config('epesi.ui.title')]);
0 ignored issues
show
Documentation Bug introduced by
It seems like __(':epesi > Installatio...fig('epesi.ui.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...
27
    	
28
    	$ui->initLayout(new Layout\Centered());
29
    	
30
    	$ui->layout->set('logo', url('logo'));
31
    	$ui->layout->template->dangerouslySetHTML('copyright', config('epesi.ui.copyright'));
32
    	
33
    	$ui->add(new System\SystemInstallWizard());
34
    	
35
    	return $ui->response();
36
    }
37
    
38
    public function home()
39
    {
40
    	return redirect(SystemCore::isInstalled()? HomePage\Model\HomePage::pathOfUser(): 'install');
41
    }
42
    
43
    public function logo()
44
    { 
45
    	$logoFile = \Epesi\Core\System\Logo\LogoSettings::getLogoFile();
46
47
    	return response(File::get($logoFile), 200, ['Content-type' => File::mimeType($logoFile)])->setMaxAge(604800)->setPublic();
48
    }
49
    
50
    public function view(UI $ui, $module, $method = 'body', $args = [])
51
    {
52
    	$ui->initLayout(new LayoutView());
53
    	
54
    	$alias = explode(':', $module);
55
    	
56
    	$moduleAlias = $alias[0];
57
    	$viewAlias = $alias[1]?? null;
58
    	
59
    	$view = null;
60
    	if ($module = ModuleManager::getClass($moduleAlias, true)) {
61
    		$viewClass = $module::view($viewAlias);
62
63
    		if (class_exists($viewClass)) {
64
    			$view = [$viewClass];
65
    		}
66
    	}
67
68
    	if (! $view) abort(404);
69
    	
70
    	$location = $ui->add($view)->displayModuleContent($method, $args)->location();
0 ignored issues
show
Bug introduced by
The method displayModuleContent() does not exist on atk4\ui\AbstractView. It seems like you code against a sub-type of atk4\ui\AbstractView such as Epesi\Core\System\Modules\ModuleView. ( Ignorable by Annotation )

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

70
    	$location = $ui->add($view)->/** @scrutinizer ignore-call */ displayModuleContent($method, $args)->location();
Loading history...
71
    	
72
    	return $ui->setLocation($location)->response();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $ui->setLocation($location) targeting Epesi\Core\UI::setLocation() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
73
    }
74
}
75