Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

ini_set('memory_limit', -1);

return (new Config)
->setParallelConfig(ParallelConfigFactory::detect())
->setFinder(Finder::create()->in([__DIR__.'/src', __DIR__.'/tests']))
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.4.0"
".": "0.5.0"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.5.0 (2026-02-03)

Full Changelog: [v0.4.0...v0.5.0](https://github.com/moderation-api/sdk-php/compare/v0.4.0...v0.5.0)

### Features

* use `$_ENV` aware getenv helper ([74f3ced](https://github.com/moderation-api/sdk-php/commit/74f3ced21bafe42f2be6ced3dcaedb5768eddf9f))


### Chores

* **internal:** php cs fixer should not be memory limited ([d6b7284](https://github.com/moderation-api/sdk-php/commit/d6b7284ff014ceac8dbac28c8a46aad5da2a3ffe))

## 0.4.0 (2026-01-31)

Full Changelog: [v0.3.0...v0.4.0](https://github.com/moderation-api/sdk-php/compare/v0.3.0...v0.4.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The REST API documentation can be found on [docs.moderationapi.com](https://docs
<!-- x-release-please-start-version -->

```
composer require "moderation-api/sdk-php 0.4.0"
composer require "moderation-api/sdk-php 0.5.0"
```

<!-- x-release-please-end -->
Expand Down
6 changes: 4 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public function __construct(
?string $baseUrl = null,
RequestOptions|array|null $requestOptions = null,
) {
$this->secretKey = (string) ($secretKey ?? getenv('MODAPI_SECRET_KEY'));
$this->secretKey = (string) ($secretKey ?? Util::getenv(
'MODAPI_SECRET_KEY'
));

$baseUrl ??= getenv(
$baseUrl ??= Util::getenv(
'MODERATION_API_BASE_URL'
) ?: 'https://api.moderationapi.com/v1';

Expand Down
17 changes: 17 additions & 0 deletions src/Core/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ final class Util

public const JSONL_CONTENT_TYPE = '/^application\/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)/';

public static function getenv(string $key): ?string
{
if (array_key_exists($key, array: $_ENV)) {
if (!is_string($value = $_ENV[$key])) {
throw new \InvalidArgumentException;
}

return $value;
}

if (is_string($value = getenv($key))) {
return $value;
}

return null;
}

/**
* @return array<string,mixed>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
namespace ModerationAPI;

// x-release-please-start-version
const VERSION = '0.4.0';
const VERSION = '0.5.0';
// x-release-please-end
3 changes: 2 additions & 1 deletion tests/Services/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ModerationAPI\Account\AccountListResponse;
use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand All @@ -21,7 +22,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/Actions/ExecuteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ModerationAPI\Actions\Execute\ExecuteExecuteByIDResponse;
use ModerationAPI\Actions\Execute\ExecuteExecuteResponse;
use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand All @@ -22,7 +23,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/ActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ModerationAPI\Actions\ActionNewResponse;
use ModerationAPI\Actions\ActionUpdateResponse;
use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand All @@ -24,7 +25,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ModerationAPI\Auth\AuthGetResponse;
use ModerationAPI\Auth\AuthNewResponse;
use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand All @@ -22,7 +23,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/AuthorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ModerationAPI\Authors\AuthorNewResponse;
use ModerationAPI\Authors\AuthorUpdateResponse;
use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand All @@ -25,7 +26,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/ContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ModerationAPI\Client;
use ModerationAPI\Content\ContentSubmitResponse;
use ModerationAPI\Core\Util;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand All @@ -21,7 +22,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/Queue/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Services\Queue;

use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use ModerationAPI\Queue\Items\ItemListResponse;
use ModerationAPI\Queue\Items\ItemResolveResponse;
use ModerationAPI\Queue\Items\ItemUnresolveResponse;
Expand All @@ -23,7 +24,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Services;

use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use ModerationAPI\Queue\QueueGetResponse;
use ModerationAPI\Queue\QueueGetStatsResponse;
use PHPUnit\Framework\Attributes\CoversNothing;
Expand All @@ -22,7 +23,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/Wordlist/WordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Services\Wordlist;

use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use ModerationAPI\Wordlist\Words\WordAddResponse;
use ModerationAPI\Wordlist\Words\WordRemoveResponse;
use PHPUnit\Framework\Attributes\CoversNothing;
Expand All @@ -22,7 +23,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down
3 changes: 2 additions & 1 deletion tests/Services/WordlistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Services;

use ModerationAPI\Client;
use ModerationAPI\Core\Util;
use ModerationAPI\Wordlist\WordlistGetEmbeddingStatusResponse;
use ModerationAPI\Wordlist\WordlistGetResponse;
use ModerationAPI\Wordlist\WordlistUpdateResponse;
Expand All @@ -23,7 +24,7 @@ protected function setUp(): void
{
parent::setUp();

$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
$client = new Client(secretKey: 'My Secret Key', baseUrl: $testUrl);

$this->client = $client;
Expand Down