Skip to content

Commit a276c9a

Browse files
feat: use $_ENV aware getenv helper
1 parent 69c476a commit a276c9a

File tree

89 files changed

+195
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+195
-89
lines changed

src/Client.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ public function __construct(
367367
?string $baseUrl = null,
368368
RequestOptions|array|null $requestOptions = null,
369369
) {
370-
$this->apiKey = (string) ($apiKey ?? getenv('INCREASE_API_KEY'));
370+
$this->apiKey = (string) ($apiKey ?? Util::getenv('INCREASE_API_KEY'));
371371

372-
$baseUrl ??= getenv('INCREASE_BASE_URL') ?: 'https://api.increase.com';
372+
$baseUrl ??= Util::getenv(
373+
'INCREASE_BASE_URL'
374+
) ?: 'https://api.increase.com';
373375

374376
$options = RequestOptions::parse(
375377
RequestOptions::with(

src/Core/Util.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ final class Util
2525

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

28+
public static function getenv(string $key): ?string
29+
{
30+
if (array_key_exists($key, array: $_ENV)) {
31+
if (!is_string($value = $_ENV[$key])) {
32+
throw new \InvalidArgumentException;
33+
}
34+
35+
return $value;
36+
}
37+
38+
if (is_string($value = getenv($key))) {
39+
return $value;
40+
}
41+
42+
return null;
43+
}
44+
2845
/**
2946
* @return array<string,mixed>
3047
*/

tests/Services/ACHPrenotificationsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Increase\ACHPrenotifications\ACHPrenotification;
66
use Increase\Client;
7+
use Increase\Core\Util;
78
use Increase\Page;
89
use PHPUnit\Framework\Attributes\CoversNothing;
910
use PHPUnit\Framework\Attributes\Test;
@@ -21,7 +22,7 @@ protected function setUp(): void
2122
{
2223
parent::setUp();
2324

24-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
25+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2526
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2627

2728
$this->client = $client;

tests/Services/ACHTransfersTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Increase\ACHTransfers\ACHTransfer;
66
use Increase\Client;
7+
use Increase\Core\Util;
78
use Increase\Page;
89
use PHPUnit\Framework\Attributes\CoversNothing;
910
use PHPUnit\Framework\Attributes\Test;
@@ -21,7 +22,7 @@ protected function setUp(): void
2122
{
2223
parent::setUp();
2324

24-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
25+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2526
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2627

2728
$this->client = $client;

tests/Services/AccountNumbersTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Increase\AccountNumbers\AccountNumber;
66
use Increase\Client;
7+
use Increase\Core\Util;
78
use Increase\Page;
89
use PHPUnit\Framework\Attributes\CoversNothing;
910
use PHPUnit\Framework\Attributes\Test;
@@ -21,7 +22,7 @@ protected function setUp(): void
2122
{
2223
parent::setUp();
2324

24-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
25+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2526
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2627

2728
$this->client = $client;

tests/Services/AccountStatementsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Increase\AccountStatements\AccountStatement;
66
use Increase\Client;
7+
use Increase\Core\Util;
78
use Increase\Page;
89
use PHPUnit\Framework\Attributes\CoversNothing;
910
use PHPUnit\Framework\Attributes\Test;
@@ -21,7 +22,7 @@ protected function setUp(): void
2122
{
2223
parent::setUp();
2324

24-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
25+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2526
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2627

2728
$this->client = $client;

tests/Services/AccountTransfersTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Increase\AccountTransfers\AccountTransfer;
66
use Increase\Client;
7+
use Increase\Core\Util;
78
use Increase\Page;
89
use PHPUnit\Framework\Attributes\CoversNothing;
910
use PHPUnit\Framework\Attributes\Test;
@@ -21,7 +22,7 @@ protected function setUp(): void
2122
{
2223
parent::setUp();
2324

24-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
25+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2526
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2627

2728
$this->client = $client;

tests/Services/AccountsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Increase\Accounts\Account;
66
use Increase\Accounts\BalanceLookup;
77
use Increase\Client;
8+
use Increase\Core\Util;
89
use Increase\Page;
910
use PHPUnit\Framework\Attributes\CoversNothing;
1011
use PHPUnit\Framework\Attributes\Test;
@@ -22,7 +23,7 @@ protected function setUp(): void
2223
{
2324
parent::setUp();
2425

25-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
26+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2627
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2728

2829
$this->client = $client;

tests/Services/BookkeepingAccountsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Increase\BookkeepingAccounts\BookkeepingAccount;
66
use Increase\BookkeepingAccounts\BookkeepingBalanceLookup;
77
use Increase\Client;
8+
use Increase\Core\Util;
89
use Increase\Page;
910
use PHPUnit\Framework\Attributes\CoversNothing;
1011
use PHPUnit\Framework\Attributes\Test;
@@ -22,7 +23,7 @@ protected function setUp(): void
2223
{
2324
parent::setUp();
2425

25-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
26+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2627
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2728

2829
$this->client = $client;

tests/Services/BookkeepingEntriesTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Increase\BookkeepingEntries\BookkeepingEntry;
66
use Increase\Client;
7+
use Increase\Core\Util;
78
use Increase\Page;
89
use PHPUnit\Framework\Attributes\CoversNothing;
910
use PHPUnit\Framework\Attributes\Test;
@@ -21,7 +22,7 @@ protected function setUp(): void
2122
{
2223
parent::setUp();
2324

24-
$testUrl = getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
25+
$testUrl = Util::getenv('TEST_API_BASE_URL') ?: 'http://127.0.0.1:4010';
2526
$client = new Client(apiKey: 'My API Key', baseUrl: $testUrl);
2627

2728
$this->client = $client;

0 commit comments

Comments
 (0)