Skip to content

Commit fd454b1

Browse files
author
Stephan Wentz
committed
feat: Create alernative factory with options array, raise dependencies
1 parent 01d6b31 commit fd454b1

File tree

8 files changed

+81
-47
lines changed

8 files changed

+81
-47
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
matrix:
1919
dependencies: ["lowest", "highest"]
2020
php-version:
21-
- "8.2"
2221
- "8.3"
22+
- "8.4"
2323

2424
steps:
2525
- name: "Checkout"

.github/workflows/code_coverage.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: shivammathur/setup-php@master
1616
with:
17-
php-version: 8.3
17+
php-version: 8.4
1818
coverage: xdebug
1919
- name: Load dependencies from cache
2020
id: composer-cache
@@ -23,9 +23,9 @@ jobs:
2323
- uses: actions/cache@v4
2424
with:
2525
path: ${{ steps.composer-cache.outputs.dir }}
26-
key: ${{ runner.os }}-php8.3-composer-${{ hashFiles('**/composer.json') }}
26+
key: ${{ runner.os }}-php8.4-composer-${{ hashFiles('**/composer.json') }}
2727
restore-keys: |
28-
${{ runner.os }}-php8.3-composer-
28+
${{ runner.os }}-php8.4-composer-
2929
3030
- run: composer install --prefer-dist --no-progress --no-suggest
3131
- run: php vendor/bin/phpunit --coverage-clover build/logs/clover.xml

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ services:
3232
foo: bar
3333
$logger: '@logger'
3434

35+
# or
36+
37+
Sentry\State\HubInterface:
38+
factory: ['@Brainbits\MonologSentry\SentryFactory', 'createFromOptions']
39+
arguments:
40+
$options:
41+
dsn: '%env(SENTRY_DSN)%'
42+
environment: '%env(SENTRY_ENVIRONMENT)%'
43+
inAppInclude: ['%kernel.project_dir%/src']
44+
inAppExclude: ['%kernel.cache_dir%', '%kernel.project_dir%/vendor']
45+
prefixes: ['%kernel.project_dir%']
46+
release: 'web-%app_version%'
47+
tags:
48+
foo: bar
49+
logger: '@logger'
50+
3551
Controlling\Sentry\Sentry\SentryHandler: ~
3652

3753
Controlling\Sentry\EventListener\SentryConsoleListener: ~
@@ -62,4 +78,4 @@ when@prod:
6278
sentry_handler:
6379
type: service
6480
id: 'Brainbits\MonologSentry\SentryHandler'
65-
```
81+
```

composer.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,30 @@
44
"description": "brainbits sentry",
55
"license": "proprietary",
66
"require": {
7-
"php": "^8.2",
7+
"php": "^8.3",
88
"ext-iconv": "*",
99
"bgalati/monolog-sentry-handler": "^2.1",
1010
"jean85/pretty-package-versions": "^2.0",
1111
"monolog/monolog": "^3.0",
1212
"nyholm/psr7": "^1.2.1",
13-
"psr/log": "^1.1|^2.0|^3.0",
13+
"psr/log": "^3.0",
1414
"sentry/sentry": "^4.6.1",
15-
"symfony/config": "^6.4|^7.0",
16-
"symfony/dependency-injection": "^6.4|^7.0",
17-
"symfony/http-client": "^6.4|^7.0",
18-
"symfony/http-kernel": "^6.4|^7.0",
19-
"symfony/yaml": "^6.4|^7.0"
15+
"symfony/config": "^7.0",
16+
"symfony/dependency-injection": "^7.0",
17+
"symfony/http-client": "^7.0",
18+
"symfony/http-kernel": "^7.0",
19+
"symfony/yaml": "^7.0"
2020
},
2121
"require-dev": {
22-
"brainbits/phpcs-standard": "^7.0.1",
22+
"brainbits/phpcs-standard": "^8.0",
2323
"ergebnis/phpstan-rules": "^2.2",
2424
"nyholm/nsa": "^1.3",
25-
"phpstan/phpstan": "^1.10.59",
26-
"phpstan/phpstan-phpunit": "^1.3.16",
27-
"phpunit/phpunit": "^11.0.4",
28-
"symfony/console": "^6.4|^7.0.4",
29-
"symfony/messenger": "^6.4|^7.0.4",
30-
"symfony/security-bundle": "^6.4|^7.0.4",
31-
"thecodingmachine/phpstan-strict-rules": "^1.0"
25+
"phpstan/phpstan": "^2.0",
26+
"phpstan/phpstan-phpunit": "^2.0",
27+
"phpunit/phpunit": "^12.0",
28+
"symfony/console": "^7.0.4",
29+
"symfony/messenger": "^7.0.4",
30+
"symfony/security-bundle": "^7.0.4"
3231
},
3332
"suggest": {
3433
"symfony/console": "For the console listener",

phpstan.neon.dist

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ parameters:
33
paths:
44
- src
55
- tests
6-
ignoreErrors:
7-
- '#Method Brainbits\\MonologSentry\\SentryFactory::create\(\) has parameter .* with null as default value#'
86
inferPrivatePropertyTypeFromConstructor: true
97
excludePaths:
10-
- src/Kernel.php
11-
- src/Sentry/SentryHandler.php
12-
- tests/Sentry/SentryHandlerTest.php
8+
- src/SentryHandler.php
139
ergebnis:
10+
noParameterWithNullDefaultValue:
11+
enabled: false
1412
noParameterWithNullableTypeDeclaration:
1513
enabled: false
1614
noExtends:
@@ -23,4 +21,3 @@ includes:
2321
- vendor/ergebnis/phpstan-rules/rules.neon
2422
- vendor/phpstan/phpstan-phpunit/extension.neon
2523
- vendor/phpstan/phpstan-phpunit/rules.neon
26-
- vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

src/SentryFactory.php

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function __construct(
2828
}
2929

3030
/**
31-
* @param string[] $inAppInclude
32-
* @param string[] $inAppExclude
33-
* @param string[] $prefixes
34-
* @param mixed[] $tags
31+
* @param string[] $inAppInclude
32+
* @param string[] $inAppExclude
33+
* @param string[] $prefixes
34+
* @param array<string, mixed> $tags
3535
*/
3636
public function create(
3737
string|null $dsn,
@@ -42,21 +42,45 @@ public function create(
4242
array|null $prefixes = null,
4343
array|null $tags = null,
4444
): HubInterface {
45-
$clientBuilder = ClientBuilder::create([
46-
'dsn' => $dsn ?: null,
47-
'environment' => $environment, // I.e.: staging, testing, production, etc.
48-
'in_app_include' => $inAppInclude ?? [],
49-
'in_app_exclude' => $inAppExclude ?? [],
50-
'prefixes' => $prefixes ?? [],
51-
'release' => $release,
52-
'attach_stacktrace' => false,
53-
'default_integrations' => false,
54-
'integrations' => [
55-
new RequestIntegration(),
56-
new EnvironmentIntegration(),
57-
new FrameContextifierIntegration($this->logger),
45+
return $this->createFromArray(
46+
[
47+
'dsn' => $dsn ?: null,
48+
'environment' => $environment, // I.e.: staging, testing, production, etc.
49+
'in_app_include' => $inAppInclude ?? [],
50+
'in_app_exclude' => $inAppExclude ?? [],
51+
'prefixes' => $prefixes ?? [],
52+
'release' => $release,
53+
'attach_stacktrace' => false,
54+
'default_integrations' => false,
55+
'integrations' => [
56+
new RequestIntegration(),
57+
new EnvironmentIntegration(),
58+
new FrameContextifierIntegration($this->logger),
59+
],
5860
],
59-
]);
61+
$tags,
62+
);
63+
}
64+
65+
/**
66+
* @param array<string, mixed> $options
67+
* @param array<string, mixed> $tags
68+
*/
69+
public function createFromArray(array $options, array|null $tags = null): HubInterface
70+
{
71+
$options['dsn'] ??= null;
72+
$options['in_app_include'] ??= [];
73+
$options['in_app_exclude'] ??= [];
74+
$options['prefixes'] ??= [];
75+
$options['attach_stacktrace'] ??= false;
76+
$options['default_integrations'] ??= false;
77+
$options['integrations'] ??= [
78+
new RequestIntegration(),
79+
new EnvironmentIntegration(),
80+
new FrameContextifierIntegration($this->logger),
81+
];
82+
83+
$clientBuilder = ClientBuilder::create($options);
6084

6185
$clientBuilder->setLogger($this->logger);
6286

tests/EventListener/HubExpections.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private function expectHubIsConfiguredWithValues(
3030
): void {
3131
$hub->expects($this->atLeastOnce())
3232
->method('configureScope')
33-
->with($this->callback(function ($closure) use ($propertyName, $value) {
33+
->with($this->callback(function (callable $closure) use ($propertyName, $value) {
3434
$scope = new Scope();
3535
$closure($scope);
3636

tests/SentryFactoryTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Sentry\Client;
1313
use Sentry\Dsn;
1414
use Sentry\HttpClient\HttpClient;
15-
use Sentry\Options;
1615
use Sentry\SentrySdk;
1716
use Sentry\State\Layer;
1817
use Sentry\Transport\HttpTransport;
@@ -103,7 +102,6 @@ public function testMinimalParameters(): void
103102
self::assertInstanceOf(HttpTransport::class, $transport);
104103

105104
$options = $client->getOptions();
106-
self::assertInstanceOf(Options::class, $options);
107105

108106
self::assertNull($options->getDsn());
109107

0 commit comments

Comments
 (0)