Skip to content

Commit

Permalink
Merge pull request #26 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 3.2.0 -- allow null as the default in getArray
  • Loading branch information
briskt authored Jul 17, 2024
2 parents d94efbd + 209e5fe commit 9a60ee2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.phar
.idea/
local.env
composer.lock
.idea/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ environment variable's value can be split into an array automatically.

## Build Status

![Unit Tests](https://github.com/silinternational/php-env/actions/workflows/tests.yml/badge.svg?branch=master)
![Unit Tests](https://github.com/silinternational/php-env/actions/workflows/test.yml/badge.svg?branch=master)

## Setup

Expand Down
11 changes: 6 additions & 5 deletions src/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ public static function requireEnv($varname)
}

/**
*
* @param string $varname
* @param array $default
* @return array
* Get an array of data from an environment variable containing comma-separated values.
*
* @param string $varname The name of the desired environment variable.
* @param array|null $default The default value to return if the environment variable is not set.
* @return array|null
*/
public static function getArray($varname, array $default = [])
public static function getArray(string $varname, ?array $default = []): ?array
{
$value = self::get($varname);

Expand Down
12 changes: 12 additions & 0 deletions tests/unit/EnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,18 @@ public function testGetArray_notFoundWithInvalidDefaultType()
// Assert
$this->fail("Should have thrown TypeError on default array.");
}

public function testGetArray_notFoundWithNullDefault()
{
// Arrange
$varname = 'TESTGETARRAY_NOTFOUNDWITHNULLDEFAULT';

// Act
$actual = Env::getArray($varname, null);

// Assert
$this->assertNull($actual);
}

public function testGetArrayFromPrefix_multiple()
{
Expand Down

0 comments on commit 9a60ee2

Please sign in to comment.