Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 98a9506

Browse files
authored
Merge pull request #8 from mimmi20/master
upgrade to Monolog 3
2 parents 657ecb6 + 4e7c66a commit 98a9506

File tree

9 files changed

+203
-120
lines changed

9 files changed

+203
-120
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ Thumbs.db
4747
vendor/
4848
composer.lock
4949

50+
# cache files
51+
.phpunit.result.cache

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
}
2525
},
2626
"require": {
27-
"php": ">=7.2",
27+
"php": "^8.1",
2828
"ext-curl": "*",
2929
"ext-json": "*",
30-
"monolog/monolog": "^1.22|^2.0"
30+
"monolog/monolog": "^3.1"
3131
},
3232
"require-dev": {
33-
"phpstan/phpstan": "^0.12.87",
33+
"phpstan/phpstan": "^1.8",
3434
"phpunit/phpunit": "^9.5"
3535
},
3636
"suggest": {

phpstan.neon

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
parameters:
2-
# level: there are 9 levels (0 is the loosest and 8/max is the strictest)
3-
# 0: basic checks, unknown classes, unknown functions, unknown methods called on $this, wrong number of arguments passed to those methods and functions, always undefined variables
4-
# 1: possibly undefined variables, unknown magic methods and properties on classes with __call and __get
5-
# 2: unknown methods checked on all expressions (not just $this), validating PHPDocs
6-
# 3: return types, types assigned to properties
7-
# 4: basic dead code checking - always false instanceof and other type checks, dead else branches, unreachable code after return; etc.
8-
# 5: checking types of arguments passed to methods and functions
9-
# 6: report missing typehints
10-
# 7: report partially wrong union types - if you call a method that only exists on some types in a union type, level 7 starts to report that; other possibly incorrect situations
11-
# 8/max: report calling methods and accessing properties on nullable types
12-
level: 8
13-
paths:
14-
- src
15-
# TRUE: it doesn’t require typehints for properties if the types can be inferred from constructor injection
16-
inferPrivatePropertyTypeFromConstructor: true
17-
18-
# FALSE: using level 6 to report missing typehints when array instead of int[] is fine
19-
checkMissingIterableValueType: false
20-
21-
# FALSE: disable this strict approach to generics by setting
22-
checkGenericClassInNonGenericObjectType: false
2+
level: max
3+
parallel:
4+
maximumNumberOfProcesses: 1
5+
processTimeout: 200.0
6+
paths:
7+
- src
8+
- tests
9+
scanFiles:
10+
- %currentWorkingDirectory%/vendor/autoload.php
11+
inferPrivatePropertyTypeFromConstructor: true
12+
checkGenericClassInNonGenericObjectType: false
13+
checkMissingIterableValueType: false
14+
treatPhpDocTypesAsCertain: false
15+
exceptions:
16+
implicitThrows: false
17+
checkedExceptionRegexes:
18+
- '#Exception#'
19+
- '#Throwable#'
20+
check:
21+
missingCheckedExceptionInThrows: true
22+
tooWideThrowType: true
23+
# ignoreErrors:
24+
# - '~MockObject~'

phpunit.xml.dist

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" bootstrap="tests/bootstrap.php" stopOnFailure="true">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
7-
</coverage>
2+
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
6+
backupGlobals="false"
7+
backupStaticAttributes="false"
8+
beStrictAboutChangesToGlobalState="true"
9+
beStrictAboutCoversAnnotation="false"
10+
beStrictAboutOutputDuringTests="true"
11+
beStrictAboutTestsThatDoNotTestAnything="true"
12+
beStrictAboutTodoAnnotatedTests="true"
13+
beStrictAboutResourceUsageDuringSmallTests="true"
14+
convertDeprecationsToExceptions="true"
15+
failOnEmptyTestSuite="true"
16+
failOnIncomplete="true"
17+
failOnRisky="false"
18+
failOnSkipped="false"
19+
failOnWarning="true"
20+
verbose="false"
21+
bootstrap="vendor/autoload.php"
22+
enforceTimeLimit="false"
23+
executionOrder="default"
24+
resolveDependencies="true"
25+
colors="true"
26+
>
27+
<php>
28+
<ini name="date.timezone" value="UTC"/>
29+
<env name="TEST_WEBHOOK_DSN" value="https://webhook2/uuid@uuid/IncomingWebhook/id/uuid"/>
30+
</php>
31+
832
<testsuites>
933
<testsuite name="MicrosoftTeamsNotifier Test">
1034
<directory>tests/</directory>
1135
</testsuite>
1236
</testsuites>
13-
<php>
14-
<env name="TEST_WEBHOOK_DSN" value="https://webhook2/uuid@uuid/IncomingWebhook/id/uuid"/>
15-
</php>
37+
38+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
39+
<include>
40+
<directory suffix=".php">src/</directory>
41+
</include>
42+
<report>
43+
<text outputFile="php://stdout" showUncoveredFiles="true" showOnlySummary="false"/>
44+
</report>
45+
</coverage>
1646
</phpunit>

src/Handler/MicrosoftTeamsHandler.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@
1414
use Monolog\Formatter\FormatterInterface;
1515
use Monolog\Formatter\LineFormatter;
1616
use Monolog\Handler\AbstractProcessingHandler;
17+
use Monolog\Level;
1718
use Monolog\Logger;
19+
use Monolog\LogRecord;
20+
use Psr\Log\LogLevel;
1821

1922
class MicrosoftTeamsHandler extends AbstractProcessingHandler
2023
{
2124
/**
2225
* MicrosoftTeams Webhook DSN
2326
* @var string
2427
*/
25-
private $webhookDsn;
28+
private string $webhookDsn;
2629

2730
/**
2831
* Instance of the MicrosoftTeamsRecord
2932
* @var MicrosoftTeamsRecord
3033
*/
31-
private $microsoftTeamsRecord;
34+
private MicrosoftTeamsRecord $microsoftTeamsRecord;
3235

3336
/**
3437
* Format of the message
3538
* @var string|null
3639
*/
37-
private $format;
40+
private ?string $format;
3841

3942
/**
40-
* MicrosoftTeamsHandler constructor.
4143
* @param string $webhookDsn
44+
* @param int|string|Level $level
4245
* @param string $title
4346
* @param string $subject
4447
* @param string|null $emoji
4548
* @param string|null $color
4649
* @param string|null $format
47-
* @param mixed $level
4850
* @param bool $bubble
51+
*
52+
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
4953
*/
5054
public function __construct(
5155
string $webhookDsn,
52-
$level = Logger::DEBUG,
56+
int|string|Level $level = Level::Debug,
5357
string $title = 'Message',
5458
string $subject = 'Date',
5559
?string $emoji = null,
@@ -90,12 +94,15 @@ public function getMicrosoftTeamsRecord(): MicrosoftTeamsRecord
9094
}
9195

9296
/**
93-
* {@inheritdoc}
97+
* Writes the (already formatted) record down to the log of the implementing handler
98+
*
99+
* @throws \RuntimeException
94100
*/
95-
protected function write(array $record): void
101+
protected function write(LogRecord $record): void
96102
{
97103
$postData = $this->microsoftTeamsRecord->setData($record)->getData();
98104
$dataString = json_encode($postData);
105+
99106
$ch = curl_init();
100107

101108
curl_setopt($ch, CURLOPT_URL, $this->webhookDsn);
@@ -109,21 +116,24 @@ protected function write(array $record): void
109116
}
110117

111118
/**
112-
* @param mixed $ch
119+
* @param \CurlHandle $ch
113120
* @param int $repeat
114121
* @return bool|string
122+
* @throws \RuntimeException
115123
*/
116-
public static function execute($ch, int $repeat = 3)
124+
public static function execute(\CurlHandle $ch, int $repeat = 3): bool|string
117125
{
118126
while ($repeat--) {
119127
$response = curl_exec($ch);
120128

121129
if (false === $response) {
122-
if(!$repeat){
130+
if (!$repeat) {
123131
$errno = curl_errno($ch);
124132
$error = curl_error($ch);
133+
125134
throw new \RuntimeException(sprintf('Curl error %d: %s', $errno, $error));
126135
}
136+
127137
continue;
128138
}
129139

0 commit comments

Comments
 (0)