Alias   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 36 8
1
<?php
2
3
namespace Ffcms\Core;
4
5
use Ffcms\Core\Helper\Type\Arr;
6
use Ffcms\Core\Helper\Type\Str;
7
8
/**
9
 * Class Alias - fast alias for core property's
10
 * @package Ffcms\Core
11
 */
12
class Alias
13
{
14
15
    /**
16
     * Absolute path to current view folder
17
     * @var string
18
     */
19
    public $currentViewPath;
20
21
    /**
22
     * Return full URL of current view folder
23
     * @var string
24
     */
25
    public $currentViewUrl;
26
27
    /**
28
     * Current app basic domain address, obtained from request
29
     * @var string
30
     */
31
    public $baseDomain;
32
33
    /**
34
     * Current app basic URL without language path
35
     * @var string
36
     */
37
    public $baseUrlNoLang;
38
39
    /**
40
     * Current app basic URL address, obtained from request
41
     * @var string
42
     */
43
    public $baseUrl;
44
45
    /**
46
     * Current app basic URL without any changes in pathway(lang-defined, etc)
47
     * @var string
48
     */
49
    public $scriptUrl;
50
51
    /**
52
     * Alias constructor. Build alias properties for system data to provide fast-access from apps and other places.
53
     */
54
    public function __construct()
55
    {
56
        // make alias for view pathway
57
        $this->currentViewPath = App::$View->getCurrentPath();
58
59
        // make alias for baseUrl, script url and domain
60
        $this->baseDomain = App::$Request->getHttpHost();
61
        if (Str::likeEmpty($this->baseDomain)) {
62
            $this->baseDomain = App::$Properties->get('baseDomain');
0 ignored issues
show
Documentation Bug introduced by
It seems like Ffcms\Core\App::Properties->get('baseDomain') can also be of type false. However, the property $baseDomain 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...
63
        }
64
        // build script url
65
        $this->scriptUrl = App::$Request->getScheme() . '://' . $this->baseDomain;
66
        if (App::$Properties->get('basePath') !== '/') {
67
            $this->scriptUrl .= rtrim(App::$Properties->get('basePath'), '/');
0 ignored issues
show
Bug introduced by
It seems like Ffcms\Core\App::Properties->get('basePath') can also be of type false; however, parameter $str of rtrim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

67
            $this->scriptUrl .= rtrim(/** @scrutinizer ignore-type */ App::$Properties->get('basePath'), '/');
Loading history...
68
        }
69
        // build base url (with current used interface path slug)
70
        $this->baseUrl = $this->scriptUrl;
71
        if (App::$Request->getInterfaceSlug() !== null) {
0 ignored issues
show
introduced by
The condition Ffcms\Core\App::Request-...nterfaceSlug() !== null is always true.
Loading history...
72
            $this->baseUrl .= App::$Request->getInterfaceSlug();
73
        }
74
75
        $this->baseUrlNoLang = $this->baseUrl;
76
        if (App::$Request->languageInPath() && App::$Request->getLanguage() !== null) {
77
            $this->baseUrl .= '/' . App::$Request->getLanguage();
78
        }
79
80
        // @todo: add cron initiation from user if enabled -> move to layout
81
        //if ((bool)App::$Properties->get('userCron') && env_name === 'Front') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
82
        //    $this->addPlainCode('js', 'if(Math.random() > 0.8) { $.get("' . $this->scriptUrl . '/cron.php?rand=" + Math.random()); }');
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83
        //}
0 ignored issues
show
Unused Code Comprehensibility introduced by
100% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
84
85
        $themeAll = App::$Properties->get('theme');
86
        if (!isset($themeAll[env_name]) || Str::length($themeAll[env_name]) < 1) {
0 ignored issues
show
Bug introduced by
The constant Ffcms\Core\env_name was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
87
            $themeAll[env_name] = 'default';
88
        }
89
        $this->currentViewUrl = $this->scriptUrl . '/Apps/View/' . env_name . '/' . $themeAll[env_name];
90
    }
91
}
92