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
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/tests export-ignore
/vendor export-ignore

/LICENSE export-ignore
/Makefile export-ignore
/README.md export-ignore
/phpmd.xml export-ignore
/phpunit.xml export-ignore
/phpstan.neon.dist export-ignore
/infection.json.dist export-ignore

/.github export-ignore
/.gitignore export-ignore
/.gitattributes export-ignore
22 changes: 22 additions & 0 deletions .github/workflows/auto-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Auto assign issues

on:
issues:
types:
- opened

jobs:
run:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Assign issues
uses: gustavofreze/[email protected]
with:
assignees: '${{ secrets.ASSIGNEES }}'
github_token: '${{ secrets.GITHUB_TOKEN }}'
allow_self_assign: 'true'
allow_no_assignees: 'true'
assignment_options: 'ISSUE'
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
pull_request:

permissions:
contents: read

env:
PHP_VERSION: '8.3'

jobs:
auto-review:
name: Auto review
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}

- name: Install dependencies
run: composer update --no-progress --optimize-autoloader

- name: Run review
run: composer review

tests:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use PHP ${{ env.PHP_VERSION }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.PHP_VERSION }}

- name: Install dependencies
run: composer update --no-progress --optimize-autoloader

- name: Run tests
run: composer tests
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea

/vendor/
/report
*.lock
.phpunit.*
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3

.PHONY: configure test test-file test-no-coverage review show-reports clean

configure:
@${DOCKER_RUN} composer update --optimize-autoloader

test:
@${DOCKER_RUN} composer tests

test-file:
@${DOCKER_RUN} composer tests-file-no-coverage ${FILE}

test-no-coverage:
@${DOCKER_RUN} composer tests-no-coverage

review:
@${DOCKER_RUN} composer review

show-reports:
@sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html

clean:
@sudo chown -R ${USER}:${USER} ${PWD}
@rm -rf report vendor .phpunit.cache .lock
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,89 @@
# environment-variable
Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and validation handling.
# Environment variable

[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

* [Overview](#overview)
* [Installation](#installation)
* [How to use](#how-to-use)
* [License](#license)
* [Contributing](#contributing)

<div id='overview'></div>

## Overview

Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and
validation handling.

<div id='installation'></div>

## Installation

```bash
composer require tiny-blocks/environment-variable
```

<div id='how-to-use'></div>

## How to use

### Creating an environment variable

To create and work with environment variables, use the `from` method to get an instance of the environment variable.

```php
EnvironmentVariable::from(name: 'MY_VAR');
```

### Conversions

Once you have an instance of the environment variable, you can convert its value into various types.

#### Convert to string

To convert the environment variable to a string.

```php
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toString();
```

#### Convert to integer

To convert the environment variable to an integer.

```php
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toInteger();
```

#### Convert to boolean

To convert the environment variable to a boolean.

```php
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->toBoolean();
```

### Check if the environment variable has a value

Checks if the environment variable has a value. Values like `false`, `0`, and `-1` are valid and non-empty.

```php
$environmentVariable = EnvironmentVariable::from(name: 'MY_VAR');
$environmentVariable->hasValue();
```

<div id='license'></div>

## License

Environment variable is licensed under [MIT](LICENSE).

<div id='contributing'></div>

## Contributing

Please follow the [contributing guidelines](https://github.com/tiny-blocks/tiny-blocks/blob/main/CONTRIBUTING.md) to
contribute to the project.
72 changes: 72 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "tiny-blocks/environment-variable",
"type": "library",
"license": "MIT",
"homepage": "https://github.com/tiny-blocks/environment-variable",
"description": "Provides a simple and flexible solution for managing environment variables, with easy access, type conversions, and validation handling.",
"prefer-stable": true,
"minimum-stability": "stable",
"keywords": [
"psr",
"env",
"tiny-blocks",
"environment-variable"
],
"authors": [
{
"name": "Gustavo Freze de Araujo Santos",
"homepage": "https://github.com/gustavofreze"
}
],
"support": {
"issues": "https://github.com/tiny-blocks/environment-variable/issues",
"source": "https://github.com/tiny-blocks/environment-variable"
},
"autoload": {
"psr-4": {
"TinyBlocks\\EnvironmentVariable\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"TinyBlocks\\EnvironmentVariable\\": "tests/"
}
},
"require": {
"php": "^8.3"
},
"require-dev": {
"phpmd/phpmd": "^2.15",
"phpunit/phpunit": "^11",
"phpstan/phpstan": "^1",
"dg/bypass-finals": "^1.8",
"infection/infection": "^0",
"squizlabs/php_codesniffer": "^3"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true
}
},
"scripts": {
"test": "phpunit --configuration phpunit.xml tests",
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit",
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
"mutation-test": "infection --only-covered --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage",
"test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests",
"review": [
"@phpcs",
"@phpmd",
"@phpstan"
],
"tests": [
"@test",
"@mutation-test"
],
"tests-no-coverage": [
"@test-no-coverage"
]
}
}
23 changes: 23 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"logs": {
"text": "report/infection/logs/infection-text.log",
"summary": "report/infection/logs/infection-summary.log"
},
"tmpDir": "report/infection/",
"minMsi": 100,
"timeout": 30,
"source": {
"directories": [
"src"
]
},
"phpUnit": {
"configDir": "",
"customPath": "./vendor/bin/phpunit"
},
"mutators": {
"@default": true
},
"minCoveredMsi": 100,
"testFramework": "phpunit"
}
59 changes: 59 additions & 0 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0"?>
<ruleset name="PHPMD Custom rules"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>PHPMD Custom rules</description>

<rule ref="rulesets/cleancode.xml/ElseExpression"/>
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>

<rule ref="rulesets/codesize.xml/TooManyFields"/>
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"/>

<rule ref="rulesets/controversial.xml/Superglobals"/>
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>

<rule ref="rulesets/design.xml/GotoStatement"/>
<rule ref="rulesets/design.xml/ExitExpression"/>
<rule ref="rulesets/design.xml/EvalExpression"/>
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<rule ref="rulesets/design.xml/DevelopmentCodeFragment"/>

<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="25"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="minimum" value="2"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<property name="minimum" value="2"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>

<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
</ruleset>
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
paths:
- src
level: 9
tmpDir: report/phpstan
reportUnmatchedIgnoredErrors: false
Loading
Loading