Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Extend/Core/Arch/FrontAppController.php (1 issue)

1
<?php
2
3
namespace Extend\Core\Arch;
4
5
use Apps\ActiveRecord\App as AppRecord;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\Controller;
8
use Ffcms\Core\Exception\ForbiddenException;
9
use Ffcms\Core\Helper\Type\Any;
10
use Ffcms\Core\Helper\Type\Obj;
11
use Ffcms\Core\Helper\Type\Str;
12
13
/**
14
 * Class FrontAppController. Extended controller for front applications.
15
 * This controller allow to control off/on status of controller application and support fast configuration usage.
16
 * @package Extend\Core\Arch
17
 */
18
class FrontAppController extends Controller
19
{
20
    // information about application from table apps
21
    public $application;
22
    private $configs;
23
24
    /**
25
     * FrontAppController constructor. Check if app is enabled in database
26
     * @throws ForbiddenException
27
     */
28
    public function __construct()
29
    {
30
        if (!$this->isEnabled()) {
31
            throw new ForbiddenException(__('This application is disabled or not installed!'));
32
        }
33
34
        // add localizations
35
        App::$Translate->append(App::$Alias->currentViewPath . '/I18n/' . App::$Request->getLanguage() . '.php');
36
        parent::__construct();
37
    }
38
39
    /**
40
     * Check is current instance of application is enabled and can be executed
41
     * @return bool
42
     */
43
    public function isEnabled(): bool
44
    {
45
        $appName = App::$Request->getController();
46
        // if app class extend current class we can get origin name
47
        $nativeName = Str::lastIn(get_class($this), '\\', true);
48
        // check if this controller is enabled
49
        $this->application = AppRecord::getItem('app', [$appName, $nativeName]);
0 ignored issues
show
Are you sure the assignment to $this->application is correct as Apps\ActiveRecord\App::g...$appName, $nativeName)) targeting Apps\ActiveRecord\App::getItem() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
50
51
        // not exist? false
52
        if (!$this->application) {
53
            return false;
54
        }
55
56
        // check if disabled (0 = enabled, anything else = on)
57
        return !(bool)$this->application->disabled;
58
    }
59
60
    /**
61
     * Get current application configs as array
62
     * @return array|null
63
     */
64
    public function getConfigs(): ?array
65
    {
66
        if ($this->configs !== null) {
67
            return $this->configs;
68
        }
69
70
        $configs = (array)$this->application->configs;
71
        foreach ($configs as $cfg => $value) {
72
            if (Any::isInt($value)) {
73
                $configs[$cfg] = $value;
74
            }
75
        }
76
        $this->configs = $configs;
77
78
        return $this->configs;
79
    }
80
}
81