From 4e36e2e86e02806738a1921f3c9106d7be001e41 Mon Sep 17 00:00:00 2001 From: Frugan <7957714+frugan-dev@users.noreply.github.com> Date: Tue, 7 Apr 2026 11:02:37 +0200 Subject: [PATCH] fix: fix getBool when environment variable is empty (#44) * ci: enhance semantic-release * chore: update .gitignore * docs: typo * fix: fix getBool when environment variable is empty * test: restore composer_normalize task in grumphp --- .github/SUPPORT.md | 16 ++++ .github/dependabot.yml | 4 +- .github/labeler.yml | 2 +- .github/workflows/main.yml | 6 +- .github/workflows/release.yml | 3 + .gitignore | 20 ++++- .releaserc.json | 2 + README.md | 2 +- composer.json | 159 +++++++++++++++++----------------- grumphp.yml.dist | 3 +- src/Environment.php | 4 + tests/EnvironmentTest.php | 5 ++ 12 files changed, 137 insertions(+), 89 deletions(-) diff --git a/.github/SUPPORT.md b/.github/SUPPORT.md index e69de29..9304061 100644 --- a/.github/SUPPORT.md +++ b/.github/SUPPORT.md @@ -0,0 +1,16 @@ +# Support + +## Getting Help + +- 📖 Read the [documentation](../README.md) +- 💬 Start a [discussion](https://github.com/wp-spaghetti/wp-env/discussions) +- 🐛 Report bugs via [issues](https://github.com/wp-spaghetti/wp-env/issues) + +## Community + +- Follow [@frugan-dev](https://github.com/frugan-dev) for updates +- Star ⭐ the project if you find it useful + +## Commercial Support + +For commercial support or consulting: dev@frugan.it diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b542ced..eb3afb2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,7 +11,7 @@ updates: assignees: - "frugan-dev" commit-message: - prefix: "chore" + prefix: "deps" include: "scope" labels: - "dependencies" @@ -27,7 +27,7 @@ updates: assignees: - "frugan-dev" commit-message: - prefix: "chore" + prefix: "ci" include: "scope" labels: - "dependencies" diff --git a/.github/labeler.yml b/.github/labeler.yml index 4da8a23..598ab5b 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -12,7 +12,7 @@ - any: ['.github/**'] 'area: dependencies': -- any: ['composer.json', 'composer.lock'] +- any: ['composer*.json', 'composer*.lock'] 'area: config': - any: ['*.php', '*.json', '*.xml', '*.yml', '*.yaml'] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6e76f51..14e6a2e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: mbstring, intl + extensions: mbstring, intl, :redis coverage: xdebug - name: Get composer cache directory @@ -117,7 +117,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.4' - extensions: mbstring, intl + extensions: mbstring, intl, :redis - name: Install dependencies run: composer install --prefer-dist --no-progress @@ -143,7 +143,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.4' - extensions: mbstring, intl + extensions: mbstring, intl, :redis - name: Install dependencies run: composer install --prefer-dist --no-progress diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 76ba77b..1a8ec9e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,8 +41,11 @@ jobs: # https://github.com/semantic-release/commit-analyzer/issues/65 # https://github.com/romap0/semantic-release-unsquash/issues/7 extra_plugins: | + @semantic-release/commit-analyzer@latest + @semantic-release/release-notes-generator@latest @semantic-release/changelog@latest @semantic-release/git@latest + @semantic-release/github@latest conventional-changelog-conventionalcommits@latest env: # Use the token with bypass permissions diff --git a/.gitignore b/.gitignore index 3c10f33..0efd9e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,23 @@ +# Cache .phpunit.cache/ .psalm/ -vendor/ + +# Dependencies +/vendor/ +/venv/ composer.lock composer.develop.* + +# OS files +.DS_Store +Thumbs.db + +# IDE +.idea/ +.vscode/ +*.swo +*.swp +*~ + +# Other +/.claude* diff --git a/.releaserc.json b/.releaserc.json index fe239f2..0c7ada1 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -7,6 +7,8 @@ } ], "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", [ "@semantic-release/changelog", { diff --git a/README.md b/README.md index eb6a677..6b4d2ef 100644 --- a/README.md +++ b/README.md @@ -619,5 +619,5 @@ See [CONTRIBUTING](.github/CONTRIBUTING.md) for detailed guidelines. ## License -(ɔ) Copyleft 2025 [Frugan](https://frugan.it). +(ɔ) Copyleft 2026 [Frugan](https://frugan.it). [GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/), see [LICENSE](LICENSE) file. diff --git a/composer.json b/composer.json index fa9de0c..cb3dd22 100644 --- a/composer.json +++ b/composer.json @@ -1,82 +1,83 @@ { - "name": "wp-spaghetti/wp-env", - "description": "A comprehensive WordPress environment management utility with Docker detection, typed getters, and secure configuration handling", - "license": "GPL-3.0-or-later", - "type": "library", - "keywords": [ - "wordpress", - "environment", - "configuration", - "docker", - "env", - "config", - "bedrock" - ], - "authors": [ - { - "name": "Frugan", - "email": "dev@frugan.it", - "homepage": "https://github.com/frugan-dev", - "role": "Developer" - } - ], - "homepage": "https://github.com/wp-spaghetti/wp-env", - "support": { - "issues": "https://github.com/wp-spaghetti/wp-env/issues", - "source": "https://github.com/wp-spaghetti/wp-env", - "docs": "https://github.com/wp-spaghetti/wp-env#readme" - }, - "funding": [ - { - "type": "custom", - "url": "https://buymeacoff.ee/frugan" - } - ], - "require": { - "php": ">=8.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.86", - "php-parallel-lint/php-parallel-lint": "^1.4", - "phpro/grumphp-shim": "^2.0", - "phpstan/phpstan": "^1.12|^2.1", - "phpunit/phpunit": "^9.0|^10.0|^11.0|^12.0", - "povils/phpmnd": "^3.6", - "rector/rector": "^1.2|^2.1", - "roave/security-advisories": "dev-latest", - "squizlabs/php_codesniffer": "^3.13 || ^4.0", - "vimeo/psalm": "^5.26|^6.13" - }, - "suggest": { - "oscarotero/env": "For .env file support in modern WordPress setups like Bedrock" - }, - "autoload": { - "psr-4": { - "WpSpaghetti\\WpEnv\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "WpSpaghetti\\WpEnv\\Tests\\": "tests/" - } - }, - "config": { - "allow-plugins": { - "ergebnis/composer-normalize": true, - "phpro/grumphp-shim": true - }, - "optimize-autoloader": true, - "sort-packages": true - }, - "scripts": { - "analysis": "@check --tasks=phpstan", - "check": "@php -d max_execution_time=0 -d memory_limit=-1 -f ./vendor/bin/grumphp -- run", - "ci": "@check --no-interaction", - "lint": "@check --tasks=phpcsfixer,phplint,rector", - "quality": "@check --tasks=phpmnd,phpparser", - "rector": "@php -d max_execution_time=0 -d memory_limit=-1 -f ./vendor/bin/rector -- process --ansi --clear-cache", - "security": "@check --tasks=securitychecker_roave", - "test": "@check --tasks=phpunit", - "test:coverage": "@php -d max_execution_time=0 -d memory_limit=-1 ./vendor/bin/phpunit --coverage-clover=coverage.xml" + "name": "wp-spaghetti/wp-env", + "description": "A comprehensive WordPress environment management utility with Docker detection, typed getters, and secure configuration handling", + "license": "GPL-3.0-or-later", + "type": "library", + "keywords": [ + "wordpress", + "environment", + "configuration", + "docker", + "env", + "config", + "bedrock" + ], + "authors": [ + { + "name": "Frugan", + "email": "dev@frugan.it", + "homepage": "https://github.com/frugan-dev", + "role": "Developer" + } + ], + "homepage": "https://github.com/wp-spaghetti/wp-env", + "support": { + "issues": "https://github.com/wp-spaghetti/wp-env/issues", + "source": "https://github.com/wp-spaghetti/wp-env", + "docs": "https://github.com/wp-spaghetti/wp-env#readme" + }, + "funding": [ + { + "type": "custom", + "url": "https://buymeacoff.ee/frugan" + } + ], + "require": { + "php": ">=8.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.50", + "friendsofphp/php-cs-fixer": "^3.86", + "php-parallel-lint/php-parallel-lint": "^1.4", + "phpro/grumphp-shim": "^2.0", + "phpstan/phpstan": "^1.12 || ^2.1", + "phpunit/phpunit": "^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0", + "povils/phpmnd": "^3.6", + "rector/rector": "^1.2 || ^2.1", + "roave/security-advisories": "dev-latest", + "squizlabs/php_codesniffer": "^3.13 || ^4.0", + "vimeo/psalm": "^5.26 || ^6.13" + }, + "suggest": { + "oscarotero/env": "For .env file support in modern WordPress setups like Bedrock" + }, + "autoload": { + "psr-4": { + "WpSpaghetti\\WpEnv\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "WpSpaghetti\\WpEnv\\Tests\\": "tests/" + } + }, + "config": { + "allow-plugins": { + "ergebnis/composer-normalize": true, + "phpro/grumphp-shim": true + }, + "optimize-autoloader": true, + "sort-packages": true + }, + "scripts": { + "analysis": "@grumphp --tasks=phpstan", + "ci": "@grumphp --no-interaction", + "grumphp": "@php -d max_execution_time=0 -d memory_limit=-1 -f ./vendor/bin/grumphp -- run", + "lint": "@grumphp --tasks=phpcsfixer,phplint,rector", + "quality": "@grumphp --tasks=phpmnd,phpparser", + "rector": "@php -d max_execution_time=0 -d memory_limit=-1 -f ./vendor/bin/rector -- process --ansi --clear-cache", + "security": "@grumphp --tasks=securitychecker_roave", + "test": "@grumphp --tasks=phpunit", + "test:coverage": "@php -d max_execution_time=0 -d memory_limit=-1 ./vendor/bin/phpunit --coverage-clover=coverage.xml" + } } diff --git a/grumphp.yml.dist b/grumphp.yml.dist index b79acbc..2d6f01a 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -7,8 +7,7 @@ grumphp: composer: ~ # Composer normalize - standardize composer.json format - #FIXME - Temporarily disabled for PHP 8.4 compatibility - #composer_normalize: ~ + composer_normalize: ~ # File size check - prevent overly large files file_size: diff --git a/src/Environment.php b/src/Environment.php index 34a5772..d125768 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -136,6 +136,10 @@ public static function getBool(string $key, bool $default = false): bool if (\is_string($value)) { $value = strtolower(trim($value)); + if ('' === $value) { + return $default; + } + return \in_array($value, ['1', 'true', 'on', 'yes', 'enabled'], true); } diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index 6cf5c0f..b2ba83d 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -64,6 +64,11 @@ public function testBasicGet(): void public function testGetBool(): void { + // Test empty string falls back to default + set_mock_env_var('EMPTY_BOOL_TEST', ''); + self::assertTrue(Environment::getBool('EMPTY_BOOL_TEST', true)); + self::assertFalse(Environment::getBool('EMPTY_BOOL_TEST', false)); + // Test various truthy values set_mock_constant('BOOL_TRUE_TEST', true); set_mock_constant('STRING_TRUE_TEST', 'true');