Skip to content

Commit 2c6e0e0

Browse files
authored
Merge pull request #20 from silinternational/develop
Release 3.0.0
2 parents 3906403 + 200fe58 commit 2c6e0e0

File tree

9 files changed

+81
-19
lines changed

9 files changed

+81
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ composer.phar
22
/nbproject/
33
/vendor/
44
local.env
5+
composer.lock

.scrutinizer.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,24 @@ build_failure_conditions:
127127
- 'project.metric("scrutinizer.quality", < 6)'
128128

129129
build:
130-
environment:
131-
php: 7.0.6
132-
133-
dependencies:
134-
before:
135-
- composer install
130+
nodes:
131+
analysis:
132+
tests:
133+
override:
134+
- php-scrutinizer-run
136135

137-
tests:
138-
override:
139-
-
140-
command: ./vendor/bin/phpunit --process-isolation --whitelist src/ --coverage-clover /tmp/coverage.xml tests/
141-
coverage:
142-
file: /tmp/coverage.xml
143-
format: php-clover
136+
tests-and-coverage:
137+
environment:
138+
php: 7.4.28
139+
140+
dependencies:
141+
before:
142+
- composer install
143+
144+
tests:
145+
override:
146+
-
147+
command: ./vendor/bin/phpunit --process-isolation --whitelist src/ --coverage-clover /tmp/coverage.xml tests/
148+
coverage:
149+
file: /tmp/coverage.xml
150+
format: php-clover

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ php values of `true`, `false`, or `null` respectively
3939
* NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php `true`.
4040
`false` and `null` are handled similarly. Other value strings will have leading/trailing whitespace trimmed.
4141

42+
1. __getString__ - `public static function getString($varname, $default = null): ?string`
43+
44+
* searches the local environment for `$varname` and returns the corresponding trimmed value string
45+
* if `$varname` is not set or the value is empty (only whitespace), `getString` returns `$default` parameter
46+
47+
1. __getBoolean__ - `public static function getBoolean($varname, $default = null): ?bool`
48+
49+
* searches the local environment for `$varname` and returns the corresponding boolean value string
50+
* if `$varname` is not set or the value is empty (only whitespace), `getBoolean` returns `$default` parameter
51+
* if the value string corresponding to `$varname` is 'true', 'false' or 'null', `getBoolean` returns
52+
php values of `true`, `false`, or `null` respectively
53+
* if the value is not boolean, `getBoolean` returns `$default` parameter
54+
* NOTE: Any value string containing 'true' with any combination of case and/or leading/trailing whitespace still returns php `true`.
55+
`false` and `null` are handled similarly.
56+
4257
1. __getArray__ - `public static function getArray($varname, array $default = [])`
4358

4459
* searches the local environment for `$varname` and returns the corresponding value string with comma separated elements as a php array

ci-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
composer install
6+
./vendor/bin/phpunit --process-isolation tests/

codeship-services.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test:
2+
image: silintl/php7:7.4
3+
volumes:
4+
- ./:/data
5+
working_dir: /data
6+

codeship-steps.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- name: test
2+
service: test
3+
command: /data/ci-tests.sh

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
"psr-4": {"Sil\\PhpEnv\\": "src/"}
88
},
99
"require": {
10-
"php": ">=5.4"
10+
"php": "^7.4"
1111
},
1212
"require-dev": {
13-
"johnkary/phpunit-speedtrap": "1.*",
14-
"phpunit/phpunit": "^6.1"
13+
"phpunit/phpunit": "^9.0"
1514
}
1615
}

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '2'
22
services:
33
test:
4-
image: silintl/php7:latest
4+
image: silintl/php7:7.4
55
volumes:
66
- ./:/data
77
working_dir: /data

src/Env.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Sil\PhpEnv;
33

44
use Exception;
5-
use Sil\PhpEnv\EnvListNotAvailableException;
65

76
class Env
87
{
@@ -78,7 +77,33 @@ public static function get($varname, $default = null)
7877

7978
return $trimmedValue;
8079
}
81-
80+
81+
public static function getString(string $varName, ?string $default = null): ?string
82+
{
83+
$originalValue = \getenv($varName);
84+
if ($originalValue === false) {
85+
return $default;
86+
}
87+
88+
$trimmedValue = \trim($originalValue);
89+
if ($trimmedValue === '') {
90+
return $default;
91+
}
92+
93+
return $trimmedValue;
94+
}
95+
96+
97+
public static function getBoolean(string $varName, ?bool $default = null): ?bool
98+
{
99+
$value = self::get($varName, $default);
100+
if (is_bool($value)) {
101+
return $value;
102+
} else {
103+
return $default;
104+
}
105+
}
106+
82107
/**
83108
*
84109
* @param string $varname

0 commit comments

Comments
 (0)