Skip to content

Commit 11c6ca8

Browse files
committed
chore: lint, lower frame default for libcurl test
1 parent 7adf158 commit 11c6ca8

8 files changed

Lines changed: 55 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PostHog::init('phc_xxx', [
4747
],
4848
'error_tracking_include_source_context' => true,
4949
'error_tracking_context_lines' => 5,
50-
'error_tracking_max_frames' => 50,
50+
'error_tracking_max_frames' => 20,
5151
'error_tracking_context_provider' => static function (array $payload): array {
5252
return [
5353
'distinctId' => $_SESSION['user_id'] ?? null,

example.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
// phpcs:disable PSR1.Files.SideEffects
4+
35
// PostHog PHP library example
46
//
57
// This script demonstrates various PostHog PHP SDK capabilities including:
@@ -267,7 +269,11 @@ function flagDependencyExamples()
267269
[],
268270
true
269271
);
270-
echo "📊 Beta feature comparison - @example.com: " . json_encode($beta1) . ", regular: " . json_encode($beta2) . "\n";
272+
echo "📊 Beta feature comparison - @example.com: "
273+
. json_encode($beta1)
274+
. ", regular: "
275+
. json_encode($beta2)
276+
. "\n";
271277

272278
echo "\n🎯 Results Summary:\n";
273279
echo " - Flag dependencies evaluated locally: " . ($result1 != $result2 ? "✅ YES" : "❌ NO") . "\n";
@@ -302,7 +308,10 @@ function flagDependencyExamples()
302308
true
303309
);
304310
if ($dependentResult3 !== "breaking-bad") {
305-
echo " ❌ Something went wrong evaluating 'multivariate-root-flag' with pineapple@example.com. Expected 'breaking-bad', got '" . json_encode($dependentResult3) . "'\n";
311+
echo " ❌ Something went wrong evaluating 'multivariate-root-flag' with pineapple@example.com. "
312+
. "Expected 'breaking-bad', got '"
313+
. json_encode($dependentResult3)
314+
. "'\n";
306315
} else {
307316
echo "✅ 'multivariate-root-flag' with email pineapple@example.com succeeded\n";
308317
}
@@ -317,7 +326,10 @@ function flagDependencyExamples()
317326
true
318327
);
319328
if ($dependentResult4 !== "the-wire") {
320-
echo " ❌ Something went wrong evaluating multivariate-root-flag with mango@example.com. Expected 'the-wire', got '" . json_encode($dependentResult4) . "'\n";
329+
echo " ❌ Something went wrong evaluating multivariate-root-flag with mango@example.com. "
330+
. "Expected 'the-wire', got '"
331+
. json_encode($dependentResult4)
332+
. "'\n";
321333
} else {
322334
echo "✅ 'multivariate-root-flag' with email mango@example.com succeeded\n";
323335
}
@@ -491,7 +503,9 @@ function etagPollingExamples()
491503
if ($beforeEtag === $afterEtag && $beforeEtag !== null) {
492504
echo "No change (304 Not Modified) - $currentFlagCount flag(s)\n";
493505
} else {
494-
echo "🔄 Flags updated! New ETag: " . ($afterEtag ? substr($afterEtag, 0, 20) . "..." : "none") . " - $currentFlagCount flag(s)\n";
506+
echo "🔄 Flags updated! New ETag: "
507+
. ($afterEtag ? substr($afterEtag, 0, 20) . "..." : "none")
508+
. " - $currentFlagCount flag(s)\n";
495509
}
496510

497511
$iteration++;

lib/Client.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ public function capture(array $message)
163163
$flags = [];
164164

165165
if (count($this->featureFlags) != 0) {
166-
# Local evaluation is enabled, flags are loaded, so try and get all flags we can without going to the server
166+
// Local evaluation is enabled, flags are loaded, so try and get all flags
167+
// we can without going to the server.
167168
$flags = $this->getAllFlags($message["distinct_id"], $message["groups"], [], [], true);
168169
} else {
169170
$flags = $this->fetchFeatureVariants($message["distinct_id"], $message["groups"]);
@@ -194,8 +195,11 @@ public function capture(array $message)
194195
* @param array $additionalProperties Extra properties merged into the event
195196
* @return bool whether the capture call succeeded
196197
*/
197-
public function captureException(\Throwable|string $exception, ?string $distinctId = null, array $additionalProperties = []): bool
198-
{
198+
public function captureException(
199+
\Throwable|string $exception,
200+
?string $distinctId = null,
201+
array $additionalProperties = []
202+
): bool {
199203
$noDistinctIdProvided = $distinctId === null;
200204
if ($noDistinctIdProvided) {
201205
$distinctId = Uuid::v4();

lib/ExceptionCapture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class ExceptionCapture
1010

1111
private static bool $includeSourceContext = true;
1212
private static int $contextLines = 5;
13-
private static int $maxFrames = 50;
13+
private static int $maxFrames = 20;
1414

1515
public static function configure(array $options = []): void
1616
{
1717
self::$includeSourceContext = (bool) ($options['error_tracking_include_source_context'] ?? true);
1818
self::$contextLines = max(0, (int) ($options['error_tracking_context_lines'] ?? 5));
19-
self::$maxFrames = max(0, (int) ($options['error_tracking_max_frames'] ?? 50));
19+
self::$maxFrames = max(0, (int) ($options['error_tracking_max_frames'] ?? 20));
2020
}
2121

2222
/**

lib/PostHog.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ public static function init(
6565
* @return bool
6666
* @throws Exception
6767
*/
68-
public static function captureException(\Throwable|string $exception, ?string $distinctId = null, array $additionalProperties = []): bool
69-
{
68+
public static function captureException(
69+
\Throwable|string $exception,
70+
?string $distinctId = null,
71+
array $additionalProperties = []
72+
): bool {
7073
self::checkClient();
7174
return self::$client->captureException($exception, $distinctId, $additionalProperties);
7275
}

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
stopOnSkipped="false"
1212
stopOnRisky="false"
1313
cacheDirectory=".phpunit.cache"
14+
bootstrap="test/error_log_mock.php"
1415
>
1516
<coverage includeUncoveredFiles="true">
1617
<report>

test/ErrorTrackingRegistrarTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace PostHog\Test;
44

5-
require_once 'test/error_log_mock.php';
6-
75
use PHPUnit\Framework\TestCase;
86
use PostHog\Client;
97
use PostHog\ErrorTrackingRegistrar;
8+
use PostHog\ExceptionCapture;
109

1110
class ErrorTrackingRegistrarTest extends TestCase
1211
{
@@ -18,6 +17,7 @@ class ErrorTrackingRegistrarTest extends TestCase
1817
public function setUp(): void
1918
{
2019
date_default_timezone_set("UTC");
20+
ExceptionCapture::configure([]);
2121
ErrorTrackingRegistrar::resetForTests();
2222

2323
global $errorMessages;
@@ -104,7 +104,12 @@ public function testExceptionHandlerCapturesFlushesAndChainsPreviousHandler(): v
104104
$previousCalls = 0;
105105
$receivedException = null;
106106

107-
$previousExceptionHandler = static function (\Throwable $exception) use (&$previousCalls, &$receivedException): void {
107+
$previousExceptionHandler = static function (
108+
\Throwable $exception
109+
) use (
110+
&$previousCalls,
111+
&$receivedException
112+
): void {
108113
$previousCalls++;
109114
$receivedException = $exception;
110115
};
@@ -161,7 +166,12 @@ public function testExceptionHandlerRethrowsWhenNoPreviousHandlerExists(): void
161166
public function testErrorHandlerCapturesNonFatalErrorsWithoutRegistrarFrames(): void
162167
{
163168
$previousCalls = 0;
164-
$previousErrorHandler = static function (int $errno, string $message, string $file, int $line) use (&$previousCalls): bool {
169+
$previousErrorHandler = static function (
170+
int $errno,
171+
string $message,
172+
string $file,
173+
int $line
174+
) use (&$previousCalls): bool {
165175
$previousCalls++;
166176
return true;
167177
};
@@ -206,7 +216,12 @@ public function testErrorHandlerCapturesNonFatalErrorsWithoutRegistrarFrames():
206216
public function testErrorHandlerRespectsRuntimeSuppression(): void
207217
{
208218
$previousCalls = 0;
209-
$previousErrorHandler = static function (int $errno, string $message, string $file, int $line) use (&$previousCalls): bool {
219+
$previousErrorHandler = static function (
220+
int $errno,
221+
string $message,
222+
string $file,
223+
int $line
224+
) use (&$previousCalls): bool {
210225
$previousCalls++;
211226
return true;
212227
};

test/ExceptionCaptureTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace PostHog\Test;
44

5-
require_once 'test/error_log_mock.php';
6-
75
use Exception;
86
use PHPUnit\Framework\TestCase;
97
use PostHog\Client;
@@ -22,6 +20,7 @@ class ExceptionCaptureTest extends TestCase
2220
public function setUp(): void
2321
{
2422
date_default_timezone_set("UTC");
23+
ExceptionCapture::configure([]);
2524
$this->httpClient = new MockedHttpClient("app.posthog.com");
2625
$this->client = new Client(
2726
self::FAKE_API_KEY,

0 commit comments

Comments
 (0)