Completed
Push — master ( d713a5...b9b397 )
by Christoph
19s queued 13s
created

Application::setInitialState()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
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\InitialState\DsnProvider;
29
use OCA\Sentry\Listener\CustomCspListener;
30
use OCA\Sentry\Reporter\ISentryReporter;
31
use OCA\Sentry\Reporter\RecursionAwareReporter;
32
use OCA\Sentry\Reporter\SentryReporterAdapter;
33
use OCP\AppFramework\App;
34
use OCP\AppFramework\Bootstrap\IBootContext;
35
use OCP\AppFramework\Bootstrap\IBootstrap;
36
use OCP\AppFramework\Bootstrap\IRegistrationContext;
37
use OCP\AppFramework\Http\ContentSecurityPolicy;
38
use OCP\EventDispatcher\IEventDispatcher;
39
use OCP\IConfig;
40
use OCP\IInitialStateService;
41
use OCP\Security\CSP\AddContentSecurityPolicyEvent;
42
use OCP\Support\CrashReport\IRegistry;
43
use OCP\Support\CrashReport\IReporter;
44
use OCP\Util;
45
use Psr\Container\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Container\ContainerInterface 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...
46
use function parse_url;
47
use function Sentry\init as initSentry;
48
49
class Application extends App implements IBootstrap {
50
51
	public function __construct(array $urlParams = []) {
52
		parent::__construct('sentry', $urlParams);
53
	}
54
55
	public function register(IRegistrationContext $context): void {
56
		// Register the autoloader
57
		include_once __DIR__ . '/../../vendor/autoload.php';
58
59
		// Wire the interface to our decorator and implementation
60
		$context->registerService(ISentryReporter::class, function (ContainerInterface $c) {
61
			/** @var Config $config */
62
			$config = $c->get(Config::class);
63
			/** @var SentryReporterAdapter $inner */
64
			$inner = $c->get(SentryReporterAdapter::class);
65
66
			// Now it's time to connect Sentry
67
			$dsn = $config->getDsn();
0 ignored issues
show
Deprecated Code introduced by
The function OCA\Sentry\Config::getDsn() has been deprecated. ( Ignorable by Annotation )

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

67
			$dsn = /** @scrutinizer ignore-deprecated */ $config->getDsn();
Loading history...
68
			if ($dsn !== null) {
69
				initSentry([
70
					'dsn' => $dsn,
71
					'release' => $config->getServerVersion(),
72
				]);
73
			}
74
75
			return new RecursionAwareReporter($inner);
76
		});
77
		$context->registerCrashReporter(ISentryReporter::class);
78
		$context->registerEventListener(AddContentSecurityPolicyEvent::class, CustomCspListener::class);
79
		$context->registerInitialStateProvider(DsnProvider::class);
80
	}
81
82
	public function boot(IBootContext $context): void {
83
		Util::addScript('sentry', 'sentry');
84
	}
85
86
}
87