BitrixMainProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 18
c 3
b 0
f 0
dl 0
loc 50
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A initGlobalObjects() 0 24 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PrettyBx\Support\Providers;
6
7
use PrettyBx\Support\Base\AbstractServiceProvider;
8
use PrettyBx\Support\Contracts\ConfigurationContract;
9
use PrettyBx\Support\Config\Manager as ConfigManager;
10
11
class BitrixMainProvider extends AbstractServiceProvider
12
{
13
    /**
14
     * @var array $singletons
15
     */
16
    protected $singletons = [
17
        '\Bitrix\Main\Loader',
18
        ConfigurationContract::class => ConfigManager::class,
19
    ];
20
21
    /**
22
     * @inheritDoc
23
     */
24
    public function register(): void
25
    {
26
        parent::register();
27
28
        $this->initGlobalObjects();
29
    }
30
31
    /**
32
     * Initializes global variables
33
     *
34
     * @access	protected
35
     * @return	void
36
     */
37
    protected function initGlobalObjects(): void
38
    {
39
        container()->singleton('CMain', function () {
40
            if (empty($GLOBALS['APPLICATION'])) {
41
                throw new \RuntimeException('Bitrix is not initialized');
42
            }
43
44
            return $GLOBALS['APPLICATION'];
45
        });
46
47
        container()->singleton('CUser', function () {
48
            if (empty($GLOBALS['USER'])) {
49
                throw new \RuntimeException('Bitrix is not initialized');
50
            }
51
52
            return $GLOBALS['USER'];
53
        });
54
55
        container()->singleton('\Bitrix\Main\Application', function () {
56
            return \Bitrix\Main\Application::getInstance();
0 ignored issues
show
Bug introduced by
The type Bitrix\Main\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
57
        });
58
59
        container()->singleton('\Bitrix\Main\EventManager', function () {
60
            return \Bitrix\Main\EventManager::getInstance();
0 ignored issues
show
Bug introduced by
The type Bitrix\Main\EventManager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
        });
62
    }
63
}
64