Skip to content

Commit

Permalink
Ability to add custom HTTP client / Remove Monolog (#42)
Browse files Browse the repository at this point in the history
* Make Guzzle optional, remove Monolog, set up phpstan & php-cs-fixer

* Update php-ci.yml

* Update .gitattributes

* Update composer.json

* Fixup log generation

* Fixup client comments

* Use PHPUnit 9 / More php cs rule options

* Update php-ci.yml

* Add CC UA header check in tests
  • Loading branch information
z4kn4fein authored Sep 28, 2023
1 parent 4619220 commit d4937f5
Show file tree
Hide file tree
Showing 56 changed files with 1,820 additions and 1,299 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
/.sonarcloud.properties export-ignore
/CONTRIBUTING.md export-ignore
/DEPLOY.md export-ignore
/phpcs.xml export-ignore
/phpunit.xml export-ignore
/.php-cs-fixer.php export-ignore
/phpstan.neon export-ignore
73 changes: 69 additions & 4 deletions .github/workflows/php-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
schedule:
- cron: '0 0 * * *'
push:
branches: [ master ]
branches: [ '*' ]
pull_request:
branches: [ master ]

Expand Down Expand Up @@ -43,12 +43,14 @@ jobs:
- name: Execute tests
run: vendor/bin/phpunit

coverage:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -76,5 +78,68 @@ jobs:
- name: Execute coverage
run: vendor/bin/phpunit --coverage-clover clover.xml

- name: Upload coverage report
run: bash <(curl -s https://codecov.io/bash)
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
files: ./clover.xml

php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
ini-values: 'memory_limit=-1'

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: |
composer self-update
composer install --prefer-dist --no-progress --no-suggest --no-plugins
- run: vendor/bin/php-cs-fixer fix --ansi --diff --dry-run

phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
ini-values: 'memory_limit=-1'

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: |
composer self-update
composer install --prefer-dist --no-progress --no-suggest --no-plugins
- run: vendor/bin/phpstan analyse --ansi
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/vendor
composer.lock
.idea/

.DS_Store

.phpunit.result.cache

.php-cs-fixer.cache
/samples/consolesample/vendor
24 changes: 24 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

$config = (new PhpCsFixer\Config())
->setRules([
'@PhpCsFixer' => true,
'@PSR2' => true,
'php_unit_internal_class' => false,
'php_unit_test_class_requires_covers' => false,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => false,
],
])
->setUsingCache(true)
->setFinder($finder)
;

return $config;
14 changes: 9 additions & 5 deletions DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
```
2. Make sure the code is properly formatted.
```bash
./vendor/bin/phpcs
vendor/bin/php-cs-fixer fix --ansi --diff --dry-run
```
> If it shows formatting errors, then you can fix them with the `./vendor/bin/phpcbf` command
3. Run tests
> If it shows formatting errors, then you can fix them with the `vendor/bin/php-cs-fixer fix --ansi` command
3. Make sure the static analyzer doesn't show errors.
```bash
vendor/bin/phpstan analyse --ansi
```
4. Run tests
```bash
vendor/bin/phpunit tests
```
4. Set `SDK_VERSION` constant in `ConfigCatClient.php`
5. Commit & Push
5. Set `SDK_VERSION` constant in `ConfigCatClient.php`
6. Commit & Push
## Publish
- Via git tag
1. Create a new version tag.
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
"guzzlehttp/guzzle": "^6.3|^7.0",
"psr/log": "^2.0|^3.0",
"ext-json": "*",
"monolog/monolog": "^2.0|^3.0",
"z4kn4fein/php-semver": "^2.0"
"z4kn4fein/php-semver": "^2.0",
"psr/http-client": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~7.0|^8",
"phpunit/phpunit": "^9",
"illuminate/cache": "^9.0",
"psr/simple-cache": "^3.0",
"psr/cache": "^1.0",
"squizlabs/php_codesniffer": "^3.7"
"phpstan/phpstan": "^1.0",
"friendsofphp/php-cs-fixer": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
20 changes: 0 additions & 20 deletions phpcs.xml

This file was deleted.

9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
level: 8
paths:
- src
ignoreErrors:
-
message: '#PHPDoc tag \@throws with type Psr\\Cache\\InvalidArgumentException is not subtype of Throwable#'
path: src/Cache/Psr6Cache.php
count: 2
36 changes: 13 additions & 23 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="ConfigCat Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="ConfigCat Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 4 additions & 3 deletions src/Attributes/Config.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

declare(strict_types=1);

namespace ConfigCat\Attributes;

/**
* Represents the root JSON keys of a ConfigCat configuration file.
* @package ConfigCat
*/
class Config
{
public const PREFERENCES = "p";
public const ENTRIES = "f";
public const PREFERENCES = 'p';
public const ENTRIES = 'f';
}
9 changes: 5 additions & 4 deletions src/Attributes/PercentageAttributes.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

declare(strict_types=1);

namespace ConfigCat\Attributes;

/**
* Represents the JSON keys of a ConfigCat percentage rule.
* @package ConfigCat
*/
class PercentageAttributes
{
public const VALUE = "v";
public const PERCENTAGE = "p";
public const VARIATION_ID = "i";
public const VALUE = 'v';
public const PERCENTAGE = 'p';
public const VARIATION_ID = 'i';
}
7 changes: 4 additions & 3 deletions src/Attributes/Preferences.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

declare(strict_types=1);

namespace ConfigCat\Attributes;

/**
* Represents the JSON keys of the Preferences section in the ConfigCat configuration file.
* @package ConfigCat
*/
class Preferences
{
public const BASE_URL = "u";
public const REDIRECT = "r";
public const BASE_URL = 'u';
public const REDIRECT = 'r';
}
13 changes: 7 additions & 6 deletions src/Attributes/RolloutAttributes.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php

declare(strict_types=1);

namespace ConfigCat\Attributes;

/**
* Represents the JSON keys of a ConfigCat roll-out rule.
* @package ConfigCat
*/
class RolloutAttributes
{
public const VALUE = "v";
public const COMPARISON_ATTRIBUTE = "a";
public const COMPARATOR = "t";
public const COMPARISON_VALUE = "c";
public const VARIATION_ID = "i";
public const VALUE = 'v';
public const COMPARISON_ATTRIBUTE = 'a';
public const COMPARATOR = 't';
public const COMPARISON_VALUE = 'c';
public const VARIATION_ID = 'i';
}
13 changes: 7 additions & 6 deletions src/Attributes/SettingAttributes.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php

declare(strict_types=1);

namespace ConfigCat\Attributes;

/**
* Represents the JSON keys of a ConfigCat setting.
* @package ConfigCat
*/
class SettingAttributes
{
public const VALUE = "v";
public const TYPE = "t";
public const ROLLOUT_PERCENTAGE_ITEMS = "p";
public const ROLLOUT_RULES = "r";
public const VARIATION_ID = "i";
public const VALUE = 'v';
public const TYPE = 't';
public const ROLLOUT_PERCENTAGE_ITEMS = 'p';
public const ROLLOUT_RULES = 'r';
public const VARIATION_ID = 'i';
}
Loading

0 comments on commit d4937f5

Please sign in to comment.