Skip to content

Commit

Permalink
Use PHP 7.4 Syntax, Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chthomas committed May 2, 2020
1 parent 4bdd20c commit b125e42
Show file tree
Hide file tree
Showing 112 changed files with 3,263 additions and 3,471 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.phar
/vendor/
/coverage/
.idea

19 changes: 19 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build:
environment:
php:
version: '7.4.5'
nodes:
my-tests:
environment:
php:
version: '7.4.5'
cache:
disabled: true

dependencies:
override:
- composer install --ignore-platform-reqs --no-interaction

build_failure_conditions:
- 'elements.rating(<= B).new.exists' # No new classes/methods with a rating of C or worse allowed
- 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ notifications:
language: php

php:
- '7.1'
- '7.2'
- '7.4'

install:
- composer install

before_script:
- mkdir -p build/logs

script:
- make
- mkdir -p build/logs
- vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml

after_success:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;'
- travis_retry php vendor/bin/php-coveralls -v
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
.PHONY: dependencies, unit-tests, test-coverage, style-check, dependency-check, static-analysis, style-fix
build:
@make dependencies && make dependency-check && make static-analysis && make style-check && make unit-tests

dependencies:
@composer install

dependency-check:
@vendor/bin/composer-require-checker check ./composer.json

unit-tests:
@vendor/bin/phpunit --bootstrap=./tests/bootstrap.php ./tests
@vendor/bin/phpunit --bootstrap=./tests/bootstrap.php --testsuite Unit

test-coverage:
@vendor/bin/phpunit --coverage-html ./coverage

style-check:
@vendor/bin/phpcs --standard=PSR2 ./src/* ./tests/*
@vendor/bin/phpcs --standard=PSR12 ./src/* ./tests/*

coverage:
@vendor/bin/phpunit --coverage-html ./tests/coverage
dependency-check:
@vendor/bin/composer-require-checker check -vvv ./composer.json

static-analysis:
@vendor/bin/phpstan analyze --level=max ./src
@vendor/bin/phpstan analyze

style-fix:
@vendor/bin/phpcbf --standard=PSR2 ./src ./tests
@vendor/bin/phpcbf --standard=PSR12 ./src ./tests
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![Total Downloads](https://poser.pugx.org/remotelyliving/doorkeeper/downloads)](https://packagist.org/packages/remotelyliving/doorkeeper)
[![Coverage Status](https://coveralls.io/repos/github/remotelyliving/doorkeeper/badge.svg?branch=master)](https://coveralls.io/github/remotelyliving/doorkeeper?branch=master)
[![License](https://poser.pugx.org/remotelyliving/doorkeeper/license)](https://packagist.org/packages/remotelyliving/doorkeeper)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/remotelyliving/doorkeeper/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/remotelyliving/doorkeeper/?branch=master)

# Doorkeeper: a dynamic feature toggle

Expand Down Expand Up @@ -32,17 +33,17 @@ by changing that configuration.
// Requestors are the actor requesting access to a new feature
// They have several forms of identity you can initialize them
$requestor = ( new Requestor() )
->withUserId($logged_in_user->id)
->withRequest($psr7_request_interface)
->withUserId($user->getId())
->withRequest($request)
->withIpAddress('127.0.0.1')
->withEnvironment('STAGE')
->withStringHash('someArbitraryThingMaybeFromTheQueryString');

// A Feature Set has Features that have Rules
$feature_set = $feature_set_repository->getSet();
$featureSet = $reatureSetRepository->getSet();

// Doorkeper takes in a Feature Set and an audit log if you want to log access results
$doorkeeper = new Doorkeeper($feature_set, $logger);
$doorkeeper = new Doorkeeper($featureSet, $logger);

// Set an app instance bound requestor here or pass one to Doorkeeper::grantsAccessToRequestor('feature', $requestor) later
$doorkeeper->setRequestor($requestor);
Expand All @@ -51,16 +52,16 @@ $doorkeeper->setRequestor($requestor);
### Usage

```php
if ($doorkeeper->grantsAccessTo('some.new.feature') {
if ($doorkeeper->grantsAccessTo('some.new.feature')) {
return $this->doNewFeatureStuff();
}

// If you want to bypass the instance Requestor that was set and create another use Doorkeeper::grantsAccessToRequestor()
// This is useful for more stateful applications

$other_requestor = (new Requestor)->withUserId($user_id);
$otherRequestor = (new Requestor()))->withUserId(123);

if ($doorkeeper->grantsAccessToRequestor('some.new.feature', $other_requestor)) {
if ($doorkeeper->grantsAccessToRequestor('some.new.feature', $otherRequestor)) {
return $this->doNewFeatureStuff();
}
```
Expand Down Expand Up @@ -126,13 +127,13 @@ Rules can be dependant on other rules for any other feature.

```php
// create a time range
$time_before_rule->addPrerequisite($time_after_rule);
$timeBeforeRule->addPrerequisite($timeAfterRule);

// create a user id rule only for prod
$user_id_rule->addPrerequisite($prod_environment_rule);
$userIdRule->addPrerequisite($prodEnvironmentRule);

// add another prereq
$user_id_rule->addPrerequisite($ip_address_rulle);
$userIdRule->addPrerequisite($ipAddressRule);

// etc.
```
Expand Down Expand Up @@ -193,7 +194,7 @@ Checkout that factory method to see the schema of the array that needs to be pas
How you choose to persist Features is up to you. But there are two things you're responsible for if using the `Features\SetRepository`

1. Clearing the cache when any member of a Feature Set is changed via `SetRepository::deleteFeatureSet()`
2. Providing a service that can provide a hydrated Feature Set to the `get('some.new.feature', $feature_set_provider)` method
2. Providing a service that can provide a hydrated Feature Set to the `get('some.new.feature', $featureSetProvider)` method

Doorkeeper also has a runtime cache that caches answers in memory to help as well.
For persistent applications you'll need to call `Doorkeeper::flushRuntimeCache()`
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
}
],
"require": {
"php": ">=7.0.0",
"php": ">=7.4",
"psr/cache": "^1.0",
"psr/log": "^1.0",
"psr/http-message": "^1.0",
"ramsey/uuid": "^3.8",
"ext-json": "*",
"ext-filter": "*",
"ramsey/uuid": "^3.8"
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
"squizlabs/php_codesniffer": "~3.0",
"php-coveralls/php-coveralls": "~1.0",
"phpstan/phpstan": "~0.10.2",
"maglnet/composer-require-checker": "~1.0"
"phpunit/phpunit": "^9.0",
"squizlabs/php_codesniffer": "^3.0",
"php-coveralls/php-coveralls": "^2.0",
"phpstan/phpstan": "^0.12.19",
"maglnet/composer-require-checker": "^2.1"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit b125e42

Please sign in to comment.