Skip to content

Commit 4f715ff

Browse files
committed
DevFlag is here
0 parents  commit 4f715ff

16 files changed

+8198
-0
lines changed

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[composer.json]
18+
indent_size = 4
19+
indent_style = space

.github/workflows/build_php81.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Build and test [PHP8.1]
2+
on:
3+
pull_request:
4+
branches:
5+
- 'main'
6+
types: [ opened, synchronize, reopened, ready_for_review ]
7+
push:
8+
branches:
9+
- 'main'
10+
11+
jobs:
12+
build_php81:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
if: success()
17+
18+
- name: Setup PHP with coverage driver
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.1'
22+
coverage: pcov
23+
24+
- name: Setup
25+
if: success()
26+
run: |
27+
php -v
28+
composer install --no-interaction
29+
30+
- name: PHPUnit tests with coverage
31+
if: success()
32+
run: |
33+
composer test-coverage
34+
35+
- name: upload coverage to codecov.io
36+
uses: codecov/codecov-action@v1
37+
with:
38+
token: ${{ secrets.CODECOV_TOKEN }}
39+
file: ./coverage.xml

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/composer.phar
2+
/vendor
3+
/.idea
4+
/.idea/*
5+
.env
6+
.phpunit*
7+
.php-cs-fixer.cache
8+
.phpunit.result.cache

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 ShipSaaS & Seth Phat
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Laravel DevFlag / FeatureFlag - ShipSaaS
2+
3+
[![Build and test [PHP8.1]](https://github.com/shipsaas/dev-flag/actions/workflows/build_php81.yml/badge.svg)](https://github.com/shipsaas/dev-flag/actions/workflows/build_php81.yml)
4+
[![codecov](https://codecov.io/gh/shipsaas/dev-flag/branch/main/graph/badge.svg?token=4WAI95PDUT)](https://codecov.io/gh/shipsaas/dev-flag)
5+
6+
DevFlag (aka Feature Flag) enabling your Application Development to follow the CI/CD best practices.
7+
8+
## Support
9+
- PHP 8.0 & PHP 8.1
10+
- Laravel 9.x
11+
12+
## Install
13+
14+
```bash
15+
composer require shipsaas/dev-flag
16+
```
17+
18+
Then hit this to get the `devflag.php` to your codebase:
19+
20+
```bash
21+
php artisan vendor:publish --tag=devflag
22+
```
23+
24+
## Deep dive
25+
26+
### Problems
27+
28+
IRL projects, definitely there would be PRs that contains a lot of changes (thousands of lines, 50+ files).
29+
For those PRs, even you have 10 people to review, they still won't cover everything 100%. Simply because it is too much.
30+
31+
Everybody loves small PRs and that is the undeniable fact. But how can we achieve it?
32+
33+
Welcome to DevFlag!
34+
35+
### Solutions
36+
DevFlag aka Feature Flag will help you to achieve that. Not only the tool, but also require a bit of your critical thinking.
37+
38+
Before starting development, you need to ensure:
39+
40+
- The scope, the changes that you will do (aka Technical Breakdown)
41+
- This is the most important phase, you need to finalize the:
42+
- Schema changes: avoid updating too much
43+
- Code
44+
- Create a DevFlag
45+
- Start the development
46+
47+
48+
## Usage
49+
50+
### Add a new Flag
51+
52+
Open the `app/devflag.php`, prepare your application's environments. Add your flag into all envs:
53+
54+
```php
55+
return [
56+
'local' => [
57+
'useNewFeature' => true,
58+
],
59+
'testing' => [
60+
'useNewFeature' => true,
61+
],
62+
'staging' => [
63+
'useNewFeature' => false,
64+
],
65+
'production' => [
66+
'useNewFeature' => false,
67+
],
68+
];
69+
```
70+
71+
### Check
72+
73+
Func-way:
74+
75+
```php
76+
$useNewFeature = useDevFlag('useNewFeature');
77+
78+
if (!$useNewFeature) {
79+
return null;
80+
}
81+
82+
// doing awesome things
83+
84+
```
85+
86+
OOP/DI-way:
87+
88+
```php
89+
use ShipSaaS\DevFlag\Contracts\DevFlagInterface;
90+
91+
public function __construct(private DevFlagInterface $devFlag) {}
92+
93+
public function transfer(): mixed
94+
{
95+
if (!$this->devFlag->can('useNewFeature')) {
96+
return null;
97+
}
98+
99+
// handle new things
100+
}
101+
```
102+
103+
## IRL Use cases
104+
105+
Check out WIKI: https://github.com/shipsaas/dev-flag/wiki
106+
107+
## Contribution rules
108+
- Follow PSR-1 & PSR-12 coding conventions
109+
- TDD is a must
110+
111+
Feel free to open a PR 😉
112+
113+
## Maintainer
114+
- Seth Phat

composer.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "shipsaas/dev-flag",
3+
"type": "library",
4+
"description": "Dev Flag implementation for Laravel Applications",
5+
"keywords": [
6+
"laravel devflag",
7+
"laravel feature flag",
8+
"laravel devflag ci/cd best practices with ShipSaaS"
9+
],
10+
"authors": [
11+
{
12+
"name": "Seth Phat",
13+
"email": "[email protected]",
14+
"homepage": "https://github.com/sethsandaru",
15+
"role": "Tech Lead"
16+
}
17+
],
18+
"license": "MIT",
19+
"require": {
20+
"php": "^8.0|^8.1",
21+
"laravel/framework": "^9"
22+
},
23+
"require-dev": {
24+
"fakerphp/faker": "^v1.20.0",
25+
"mockery/mockery": "^1.5.1",
26+
"phpunit/phpunit": "^9.5.25",
27+
"orchestra/testbench": "^7",
28+
"phpunit/php-code-coverage": "^9.2.17",
29+
"symfony/console": "^6.0.9",
30+
"symfony/error-handler": "^6.0",
31+
"symfony/finder": "^6.0",
32+
"symfony/http-foundation": "^6.0",
33+
"symfony/http-kernel": "^6.0",
34+
"symfony/mailer": "^6.0",
35+
"symfony/mime": "^6.0",
36+
"symfony/process": "^6.0",
37+
"symfony/routing": "^6.0",
38+
"symfony/uid": "^6.0",
39+
"symfony/var-dumper": "^6.0"
40+
},
41+
"extra": {
42+
"laravel": {
43+
"providers": [
44+
"ShipSaaS\\DevFlag\\DevFlagServiceProvider"
45+
],
46+
"alias": {
47+
"DevFlag": "\\ShipSaaS\\DevFlag\\Facade"
48+
}
49+
}
50+
},
51+
"autoload": {
52+
"psr-4": {
53+
"ShipSaaS\\DevFlag\\": "src/"
54+
},
55+
"files": [
56+
"src/Functions/functions.php"
57+
]
58+
},
59+
"autoload-dev": {
60+
"psr-4": {
61+
"ShipSaaS\\DevFlag\\Tests\\": "tests/"
62+
}
63+
},
64+
"scripts": {
65+
"test-coverage": [
66+
"@php vendor/bin/phpunit --coverage-clover coverage.xml"
67+
]
68+
},
69+
"minimum-stability": "dev",
70+
"prefer-stable": true
71+
}

0 commit comments

Comments
 (0)