Passed
Pull Request — master (#207)
by Christoph
03:35
created

Application   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A setInitialState() 0 5 1
A __construct() 0 2 1
A register() 0 8 1
A initSentry() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author Christoph Wurst <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\Sentry\AppInfo;
26
27
use OCA\Sentry\Config;
28
use OCA\Sentry\Reporter\RecursionAwareReporter;
29
use OCA\Sentry\Reporter\SentryReporterAdapter;
30
use OCP\AppFramework\App;
31
use OCP\AppFramework\Bootstrap\IBootContext;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Bootstrap\IBootContext 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...
32
use OCP\AppFramework\Bootstrap\IBootstrap;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Bootstrap\IBootstrap 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...
33
use OCP\AppFramework\Bootstrap\IRegistrationContext;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Bootstrap\IRegistrationContext 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...
34
use OCP\IConfig;
35
use OCP\IContainer;
36
use OCP\IInitialStateService;
37
use function Sentry\init as initSentry;
38
39
class Application extends App implements IBootstrap {
40
41
	public const APP_ID = 'sentry';
42
43
	public function __construct() {
44
		parent::__construct(self::APP_ID, []);
45
	}
46
47
	public function register(IRegistrationContext $context): void {
48
		$context->registerCrashReporter(RecursionAwareReporter::class);
49
50
		$context->registerService(RecursionAwareReporter::class, function (IContainer $c) {
51
			/** @var SentryReporterAdapter $reporter */
52
			$reporter = $c->query(SentryReporterAdapter::class);
53
54
			return new RecursionAwareReporter($reporter);
55
		});
56
	}
57
58
	public function boot(IBootContext $context): void {
59
		/*$this->initSentry(
60
			$context->getAppContainer()->query(IConfig::class),
61
			$context->getAppContainer()->query(Config::class)
62
		);*/
63
		$this->setInitialState(
64
			$context->getAppContainer()->query(IInitialStateService::class),
65
			$context->getAppContainer()->query(Config::class)
66
		);
67
	}
68
69
	private function setInitialState(IInitialStateService $stateService,
70
									 Config $config): void {
71
		$stateService->provideLazyInitialState('sentry', 'dsn', function () use ($config) {
72
			return [
73
				'dsn' => $config->getDsn(),
74
			];
75
		});
76
	}
77
78
	private function initSentry(IConfig $sysConfig,
79
								Config $config) {
80
		$dsn = $config->getDsn();
81
82
		if ($dsn === null) {
83
			return;
84
		}
85
86
		initSentry([
87
			'dsn' => $dsn,
88
			'release' => $sysConfig->getSystemValue('version', '0.0.0'),
89
		]);
90
	}
91
92
}
93