Passed
Push — master ( 32f84c...1188a0 )
by Artem
03:38 queued 13s
created

BitrixMainProvider::initGlobalObjects()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PrettyBx\Support\Providers;
6
7
use PrettyBx\Support\Base\AbstractServiceProvider;
8
9
class BitrixMainProvider extends AbstractServiceProvider
10
{
11
    /**
12
     * @var array $singletons
13
     */
14
    protected $singletons = [
15
        \Bitrix\Main\Loader::class,
0 ignored issues
show
Bug introduced by
The type Bitrix\Main\Loader 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...
16
    ];
17
18
    /**
19
     * @inheritDoc
20
     */
21
    public function register(): void
22
    {
23
        parent::register();
24
25
        $this->initGlobalObjects();
26
    }
27
28
    /**
29
     * Initializes global variables
30
     *
31
     * @access	protected
32
     * @return	void
33
     */
34
    protected function initGlobalObjects(): void
35
    {
36
        container()->singleton('CMain', function () {
37
            if (empty($GLOBALS['APPLICATION'])) {
38
                throw new \RuntimeException('Bitrix is not initialized');
39
            }
40
41
            return $GLOBALS['APPLICATION'];
42
        });
43
44
        container()->singleton('CUser', function () {
45
            if (empty($GLOBALS['USER'])) {
46
                throw new \RuntimeException('Bitrix is not initialized');
47
            }
48
49
            return $GLOBALS['USER'];
50
        });
51
    }
52
}
53