Skip to content

Commit c3893be

Browse files
chore: require PHPStan and Rector 2 (#230)
* Require PHPStan and Rector 2 * fix * fix: phpstan 2.0 issues (#231) --------- Co-authored-by: Christopher Hertel <[email protected]>
1 parent a978452 commit c3893be

File tree

7 files changed

+33
-34
lines changed

7 files changed

+33
-34
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
"codewithkyrian/chromadb-php": "^0.2.1 || ^0.3",
3333
"mongodb/mongodb": "^1.21",
3434
"php-cs-fixer/shim": "^3.70",
35-
"phpstan/phpstan": "^1.12",
36-
"phpstan/phpstan-webmozart-assert": "^1.2",
35+
"phpstan/phpstan": "^2.0",
36+
"phpstan/phpstan-webmozart-assert": "^2.0",
3737
"phpunit/phpunit": "^11.5",
3838
"probots-io/pinecone-php": "^1.0",
39-
"rector/rector": "^1.2",
39+
"rector/rector": "^2.0",
4040
"symfony/console": "^6.4 || ^7.1",
4141
"symfony/css-selector": "^6.4 || ^7.1",
4242
"symfony/dom-crawler": "^6.4 || ^7.1",

phpstan.dist.neon

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ parameters:
77
- examples/
88
- src/
99
- tests/
10+
treatPhpDocTypesAsCertain: false
1011
ignoreErrors:
1112
-
1213
message: '#no value type specified in iterable type array#'

rector.php

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
77
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitSelfCallRector;
88
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
9+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
910
use Rector\PHPUnit\Set\PHPUnitSetList;
1011

1112
return RectorConfig::configure()
@@ -25,6 +26,7 @@
2526
])
2627
->withImportNames(importNames: true, importShortClasses: false)
2728
->withSkip([
29+
AssertCountWithZeroToAssertEmptyRector::class,
2830
ClosureToArrowFunctionRector::class,
2931
PreferPHPUnitThisCallRector::class,
3032
])

src/Bridge/Meta/LlamaPromptConverter.php

+22-25
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,39 @@ public function convertMessage(UserMessage|SystemMessage|AssistantMessage $messa
5050
ASSISTANT);
5151
}
5252

53-
if ($message instanceof UserMessage) {
54-
$count = count($message->content);
55-
56-
$contentParts = [];
57-
if ($count > 1) {
58-
foreach ($message->content as $value) {
59-
if ($value instanceof Text) {
60-
$contentParts[] = $value->text;
61-
}
62-
63-
if ($value instanceof Image) {
64-
$contentParts[] = $value->url;
65-
}
66-
}
67-
} elseif (1 === $count) {
68-
$value = $message->content[0];
53+
// Handling of UserMessage
54+
$count = count($message->content);
55+
56+
$contentParts = [];
57+
if ($count > 1) {
58+
foreach ($message->content as $value) {
6959
if ($value instanceof Text) {
7060
$contentParts[] = $value->text;
7161
}
7262

7363
if ($value instanceof Image) {
7464
$contentParts[] = $value->url;
7565
}
76-
} else {
77-
throw new RuntimeException('Unsupported message type.');
66+
}
67+
} elseif (1 === $count) {
68+
$value = $message->content[0];
69+
if ($value instanceof Text) {
70+
$contentParts[] = $value->text;
7871
}
7972

80-
$content = implode(PHP_EOL, $contentParts);
73+
if ($value instanceof Image) {
74+
$contentParts[] = $value->url;
75+
}
76+
} else {
77+
throw new RuntimeException('Unsupported message type.');
78+
}
8179

82-
return trim(<<<USER
83-
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
80+
$content = implode(PHP_EOL, $contentParts);
8481

85-
{$content}<|eot_id|>
86-
USER);
87-
}
82+
return trim(<<<USER
83+
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
8884
89-
throw new RuntimeException('Unsupported message type.'); // @phpstan-ignore-line
85+
{$content}<|eot_id|>
86+
USER);
9087
}
9188
}

src/Bridge/MongoDB/Store.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ public function query(Vector $vector, array $options = [], ?float $minScore = nu
146146
*/
147147
public function initialize(array $options = []): void
148148
{
149-
try {
150-
if ([] !== $options && !array_key_exists('fields', $options)) {
151-
throw new InvalidArgumentException('The only supported option is "fields"');
152-
}
149+
if ([] !== $options && !array_key_exists('fields', $options)) {
150+
throw new InvalidArgumentException('The only supported option is "fields"');
151+
}
153152

153+
try {
154154
$this->getCollection()->createSearchIndex(
155155
[
156156
'fields' => array_merge([

src/Chain/ToolBox/Attribute/ToolParameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final readonly class ToolParameter
1111
{
1212
/**
13-
* @param string[]|null $enum
13+
* @param list<int|string>|null $enum
1414
* @param string|int|string[]|null $const
1515
*/
1616
public function __construct(

tests/Bridge/OpenAI/Embeddings/ResponseConverterTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function itConvertsAResponseToAVectorResponse(): void
3131
$vectorResponse = (new ResponseConverter())->convert($response);
3232
$convertedContent = $vectorResponse->getContent();
3333

34-
self::assertIsArray($convertedContent);
3534
self::assertCount(2, $convertedContent);
3635

3736
self::assertSame([0.3, 0.4, 0.4], $convertedContent[0]->getData());

0 commit comments

Comments
 (0)