Skip to content

Commit 1f91152

Browse files
committed
minor #86 [AI Store] Remove webmozart/assert library (Spomky)
This PR was merged into the main branch. Discussion ---------- [AI Store] Remove `webmozart/assert` library | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | none | License | MIT Hi, I am not sure w need the `webmozart/assert` dependency for just one verification. Let me squash this PR before any action (I am not with my usual setup at the moment). Regards. Commits ------- 317c35c refactor: replace Webmozart assertions with native PHP exceptions for input validation
2 parents 2e7ac31 + 317c35c commit 1f91152

File tree

20 files changed

+71
-75
lines changed

20 files changed

+71
-75
lines changed

src/platform/composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@
3232
"symfony/property-info": "^6.4 || ^7.1",
3333
"symfony/serializer": "^6.4 || ^7.1",
3434
"symfony/type-info": "^7.2.3",
35-
"symfony/uid": "^6.4 || ^7.1",
36-
"webmozart/assert": "^1.11"
35+
"symfony/uid": "^6.4 || ^7.1"
3736
},
3837
"require-dev": {
3938
"async-aws/bedrock-runtime": "^0.1.0",
4039
"codewithkyrian/transformers": "^0.5.3",
4140
"phpstan/phpstan": "^2.1.17",
4241
"phpstan/phpstan-symfony": "^2.0.6",
43-
"phpstan/phpstan-webmozart-assert": "^2.0.0",
4442
"phpunit/phpunit": "^11.5",
4543
"symfony/console": "^6.4 || ^7.1",
4644
"symfony/dotenv": "^6.4 || ^7.1",

src/platform/src/Bridge/Azure/OpenAI/EmbeddingsModelClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Symfony\AI\Platform\Bridge\Azure\OpenAI;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
15+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1516
use Symfony\AI\Platform\Model;
1617
use Symfony\AI\Platform\ModelClientInterface;
1718
use Symfony\Component\HttpClient\EventSourceHttpClient;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920
use Symfony\Contracts\HttpClient\ResponseInterface;
20-
use Webmozart\Assert\Assert;
2121

2222
/**
2323
* @author Christopher Hertel <[email protected]>
@@ -34,11 +34,11 @@ public function __construct(
3434
#[\SensitiveParameter] private string $apiKey,
3535
) {
3636
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
37-
Assert::notStartsWith($baseUrl, 'http://', 'The base URL must not contain the protocol.');
38-
Assert::notStartsWith($baseUrl, 'https://', 'The base URL must not contain the protocol.');
39-
Assert::stringNotEmpty($deployment, 'The deployment must not be empty.');
40-
Assert::stringNotEmpty($apiVersion, 'The API version must not be empty.');
41-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
37+
!str_starts_with($this->baseUrl, 'http://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
38+
!str_starts_with($this->baseUrl, 'https://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
39+
'' !== $deployment || throw new InvalidArgumentException('The deployment must not be empty.');
40+
'' !== $apiVersion || throw new InvalidArgumentException('The API version must not be empty.');
41+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
4242
}
4343

4444
public function supports(Model $model): bool

src/platform/src/Bridge/Azure/OpenAI/GPTModelClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Symfony\AI\Platform\Bridge\Azure\OpenAI;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
15+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1516
use Symfony\AI\Platform\Model;
1617
use Symfony\AI\Platform\ModelClientInterface;
1718
use Symfony\Component\HttpClient\EventSourceHttpClient;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920
use Symfony\Contracts\HttpClient\ResponseInterface;
20-
use Webmozart\Assert\Assert;
2121

2222
/**
2323
* @author Christopher Hertel <[email protected]>
@@ -34,11 +34,11 @@ public function __construct(
3434
#[\SensitiveParameter] private string $apiKey,
3535
) {
3636
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
37-
Assert::notStartsWith($baseUrl, 'http://', 'The base URL must not contain the protocol.');
38-
Assert::notStartsWith($baseUrl, 'https://', 'The base URL must not contain the protocol.');
39-
Assert::stringNotEmpty($deployment, 'The deployment must not be empty.');
40-
Assert::stringNotEmpty($apiVersion, 'The API version must not be empty.');
41-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
37+
!str_starts_with($this->baseUrl, 'http://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
38+
!str_starts_with($this->baseUrl, 'https://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
39+
'' !== $deployment || throw new InvalidArgumentException('The deployment must not be empty.');
40+
'' !== $apiVersion || throw new InvalidArgumentException('The API version must not be empty.');
41+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
4242
}
4343

4444
public function supports(Model $model): bool

src/platform/src/Bridge/Azure/OpenAI/WhisperModelClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\Whisper;
1515
use Symfony\AI\Platform\Bridge\OpenAI\Whisper\Task;
16+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1617
use Symfony\AI\Platform\Model;
1718
use Symfony\AI\Platform\ModelClientInterface;
1819
use Symfony\Component\HttpClient\EventSourceHttpClient;
1920
use Symfony\Contracts\HttpClient\HttpClientInterface;
2021
use Symfony\Contracts\HttpClient\ResponseInterface;
21-
use Webmozart\Assert\Assert;
2222

2323
/**
2424
* @author Christopher Hertel <[email protected]>
@@ -35,11 +35,11 @@ public function __construct(
3535
#[\SensitiveParameter] private string $apiKey,
3636
) {
3737
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
38-
Assert::notStartsWith($baseUrl, 'http://', 'The base URL must not contain the protocol.');
39-
Assert::notStartsWith($baseUrl, 'https://', 'The base URL must not contain the protocol.');
40-
Assert::stringNotEmpty($deployment, 'The deployment must not be empty.');
41-
Assert::stringNotEmpty($apiVersion, 'The API version must not be empty.');
42-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
38+
!str_starts_with($this->baseUrl, 'http://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
39+
!str_starts_with($this->baseUrl, 'https://') || throw new InvalidArgumentException('The base URL must not contain the protocol.');
40+
'' !== $deployment || throw new InvalidArgumentException('The deployment must not be empty.');
41+
'' !== $apiVersion || throw new InvalidArgumentException('The API version must not be empty.');
42+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
4343
}
4444

4545
public function supports(Model $model): bool

src/platform/src/Bridge/OpenAI/DallE/Base64Image.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\AI\Platform\Bridge\OpenAI\DallE;
1313

14-
use Webmozart\Assert\Assert;
14+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1515

1616
/**
1717
* @author Denis Zunke <[email protected]>
@@ -21,6 +21,6 @@
2121
public function __construct(
2222
public string $encodedImage,
2323
) {
24-
Assert::stringNotEmpty($encodedImage, 'The base64 encoded image generated must be given.');
24+
'' !== $encodedImage || throw new InvalidArgumentException('The base64 encoded image generated must be given.');
2525
}
2626
}

src/platform/src/Bridge/OpenAI/DallE/ModelClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
namespace Symfony\AI\Platform\Bridge\OpenAI\DallE;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\DallE;
15+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1516
use Symfony\AI\Platform\Exception\RuntimeException;
1617
use Symfony\AI\Platform\Model;
1718
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory;
1819
use Symfony\AI\Platform\Response\ResponseInterface as LlmResponse;
1920
use Symfony\AI\Platform\ResponseConverterInterface as PlatformResponseConverter;
2021
use Symfony\Contracts\HttpClient\HttpClientInterface;
2122
use Symfony\Contracts\HttpClient\ResponseInterface as HttpResponse;
22-
use Webmozart\Assert\Assert;
2323

2424
/**
2525
* @see https://platform.openai.com/docs/api-reference/images/create
@@ -33,8 +33,8 @@ public function __construct(
3333
#[\SensitiveParameter]
3434
private string $apiKey,
3535
) {
36-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
37-
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
36+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
37+
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
3838
}
3939

4040
public function supports(Model $model): bool

src/platform/src/Bridge/OpenAI/DallE/UrlImage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\AI\Platform\Bridge\OpenAI\DallE;
1313

14-
use Webmozart\Assert\Assert;
14+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1515

1616
/**
1717
* @author Denis Zunke <[email protected]>
@@ -21,6 +21,6 @@
2121
public function __construct(
2222
public string $url,
2323
) {
24-
Assert::stringNotEmpty($url, 'The image url must be given.');
24+
'' !== $url || throw new InvalidArgumentException('The image url must be given.');
2525
}
2626
}

src/platform/src/Bridge/OpenAI/Embeddings/ModelClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
namespace Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
15+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1516
use Symfony\AI\Platform\Model;
1617
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory;
1718
use Symfony\Contracts\HttpClient\HttpClientInterface;
1819
use Symfony\Contracts\HttpClient\ResponseInterface;
19-
use Webmozart\Assert\Assert;
2020

2121
/**
2222
* @author Christopher Hertel <[email protected]>
@@ -28,8 +28,8 @@ public function __construct(
2828
#[\SensitiveParameter]
2929
private string $apiKey,
3030
) {
31-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
32-
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
31+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
32+
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
3333
}
3434

3535
public function supports(Model $model): bool

src/platform/src/Bridge/OpenAI/GPT/ModelClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Symfony\AI\Platform\Bridge\OpenAI\GPT;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\GPT;
15+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1516
use Symfony\AI\Platform\Model;
1617
use Symfony\AI\Platform\ModelClientInterface as PlatformResponseFactory;
1718
use Symfony\Component\HttpClient\EventSourceHttpClient;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920
use Symfony\Contracts\HttpClient\ResponseInterface;
20-
use Webmozart\Assert\Assert;
2121

2222
/**
2323
* @author Christopher Hertel <[email protected]>
@@ -32,8 +32,8 @@ public function __construct(
3232
private string $apiKey,
3333
) {
3434
$this->httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
35-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
36-
Assert::startsWith($apiKey, 'sk-', 'The API key must start with "sk-".');
35+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
36+
str_starts_with($apiKey, 'sk-') || throw new InvalidArgumentException('The API key must start with "sk-".');
3737
}
3838

3939
public function supports(Model $model): bool

src/platform/src/Bridge/OpenAI/Whisper/ModelClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
namespace Symfony\AI\Platform\Bridge\OpenAI\Whisper;
1313

1414
use Symfony\AI\Platform\Bridge\OpenAI\Whisper;
15+
use Symfony\AI\Platform\Exception\InvalidArgumentException;
1516
use Symfony\AI\Platform\Model;
1617
use Symfony\AI\Platform\ModelClientInterface as BaseModelClient;
1718
use Symfony\Contracts\HttpClient\HttpClientInterface;
1819
use Symfony\Contracts\HttpClient\ResponseInterface;
19-
use Webmozart\Assert\Assert;
2020

2121
/**
2222
* @author Christopher Hertel <[email protected]>
@@ -28,7 +28,7 @@ public function __construct(
2828
#[\SensitiveParameter]
2929
private string $apiKey,
3030
) {
31-
Assert::stringNotEmpty($apiKey, 'The API key must not be empty.');
31+
'' !== $apiKey || throw new InvalidArgumentException('The API key must not be empty.');
3232
}
3333

3434
public function supports(Model $model): bool

0 commit comments

Comments
 (0)