Skip to content

Commit

Permalink
make helper method static
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Aug 14, 2023
1 parent 86a4917 commit 8a055f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
7 changes: 4 additions & 3 deletions dart/lib/src/protocol/sentry_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ class SentryRequest {
_headers = headers != null ? Map.from(headers) : null,
// Look for a 'Set-Cookie' header (case insensitive) if not given.
cookies = cookies ??
IterableUtils(headers?.entries)
.firstWhereOrNull((e) => e.key.toLowerCase() == 'cookie')
?.value,
IterableUtils.firstWhereOrNull(
headers?.entries,
(MapEntry<String, String> e) => e.key.toLowerCase() == 'cookie',
)?.value,
_env = env != null ? Map.from(env) : null,
_other = other != null ? Map.from(other) : null;

Expand Down
8 changes: 5 additions & 3 deletions dart/lib/src/protocol/sentry_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class SentryResponse {
_headers = headers != null ? Map.from(headers) : null,
// Look for a 'Set-Cookie' header (case insensitive) if not given.
cookies = cookies ??
IterableUtils(headers?.entries)
.firstWhereOrNull((e) => e.key.toLowerCase() == 'set-cookie')
?.value;
IterableUtils.firstWhereOrNull(
headers?.entries,
(MapEntry<String, String> e) =>
e.key.toLowerCase() == 'set-cookie',
)?.value;

/// Deserializes a [SentryResponse] from JSON [Map].
factory SentryResponse.fromJson(Map<String, dynamic> json) {
Expand Down
12 changes: 5 additions & 7 deletions dart/lib/src/utils/iterable_utils.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'package:meta/meta.dart';

@internal
class IterableUtils<T> {
IterableUtils(this.iterable);

Iterable<T>? iterable;

T? firstWhereOrNull(bool Function(T item) test) {
final iterable = this.iterable;
class IterableUtils {
static T? firstWhereOrNull<T>(
Iterable<T>? iterable,
bool Function(T item) test,
) {
if (iterable == null) {
return null;
}
Expand Down
7 changes: 4 additions & 3 deletions dart/test/sentry_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1427,9 +1427,10 @@ void main() {
await sut.captureEvent(fakeEvent, hint: hint);

final capturedEnvelope = (fixture.transport).envelopes.first;
final attachmentItem = IterableUtils(capturedEnvelope.items)
.firstWhereOrNull(
(element) => element.header.type == SentryItemType.attachment);
final attachmentItem = IterableUtils.firstWhereOrNull(
capturedEnvelope.items,
(SentryEnvelopeItem e) => e.header.type == SentryItemType.attachment,
);
expect(attachmentItem?.header.attachmentType,
SentryAttachment.typeAttachmentDefault);
});
Expand Down

0 comments on commit 8a055f7

Please sign in to comment.