Skip to content

Commit

Permalink
update library standards and increase minimum php version
Browse files Browse the repository at this point in the history
code-style (PSR) check with phpcs
add interface for the client
update phpunit version and tests
use github actions
  • Loading branch information
Jeroeny committed Oct 31, 2021
1 parent c6290ef commit 272e3b1
Show file tree
Hide file tree
Showing 33 changed files with 404 additions and 360 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/tests/ export-ignore
/.gitignore export-ignore
/.gitattributes export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on: [ push ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
- name: PHPUnit Tests
uses: php-actions/phpunit@v3
with:
bootstrap: vendor/autoload.php
configuration: phpunit.xml.dist
args: --coverage-text
codestyle:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
- run: vendor/bin/phpcs
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor
composer.lock
/vendor
/composer.lock
/.phpcs-cache
/.phpunit.result.cache
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ To use the Statsd Service Provider, you must register the provider when bootstra

```php
$statsd = new League\StatsD\Client();
$statsd->configure(array(
$statsd->configure([
'host' => '127.0.0.1',
'port' => 8125,
'namespace' => 'example'
));
]);
```

OR

```php
$statsd1 = StatsD\Client::instance('server1')->configure(array(...));
$statsd2 = StatsD\Client::instance('server2')->configure(array(...));
$statsd1 = StatsD\Client::instance('server1')->configure([...]);
$statsd2 = StatsD\Client::instance('server2')->configure([...]);
```

The StatsD client wait for `ini_get('default_socket_timeout')` seconds when opening the socket by default. To reduce
Expand All @@ -65,10 +65,10 @@ If omitted, this option defaults to `true`.
```php
$statsd->increment('web.pageview');
$statsd->decrement('storage.remaining');
$statsd->increment(array(
$statsd->increment([
'first.metric',
'second.metric'
), 2);
], 2);
$statsd->increment('web.clicks', 1, 0.5);
```

Expand Down Expand Up @@ -112,18 +112,18 @@ $statsd->time('api.dbcall', function () {

***Attention!** That functionality support of tags in Datadog format!*

You may configure it for all the metrics sending by the client.
You may configure it for all the metrics sending by the client.

```php
$statsd->configure(array(
'tags' => array('some_general_tag' => 'value')
));
$statsd->configure([
'tags' => ['some_general_tag' => 'value']
]);
```

Or you may send it for a single metric.

```php
$statsd->increment('web.clicks', 1, 1, array('host' => $_SERVER['HTTP_HOST']));
$statsd->increment('web.clicks', 1, 1, ['host' => $_SERVER['HTTP_HOST']]);
```

## Framework integration
Expand All @@ -136,19 +136,19 @@ integrate it quickly with the most popular ones via included adapters.
Find the `providers` key in your `app/config/app.php` and register the Statsd Service Provider.

```php
'providers' => array(
'providers' => [
// ...
'League\StatsD\Laravel\Provider\StatsdServiceProvider',
)
]
```

Find the `aliases` key in your `app/config/app.php` and add the Statsd Facade Alias.

```php
'aliases' => array(
'aliases' => [
// ...
'Statsd' => 'League\StatsD\Laravel\Facade\StatsdFacade',
)
]
```
### Laravel 5.x

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
"role": "Developer"
}
],
"require": {
"php": ">=7.4"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.5"
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions docs/Getting Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Creating a new instance within your application is very easy.

```php
$statsd = new League\StatsD\Client();
$statsd->configure(array(
$statsd->configure([
'host' => 'localhost',
'port' => 8125,
'namespace' => 'ns1'
));
]);
```

**Note** The namespace is optional, but recommended.
Expand Down
20 changes: 20 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset
name="PHPCS Coding Standards"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="colors" />
<arg name="cache" value=".phpcs-cache"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<rule ref="PSR12"/>

<file>src</file>
<file>tests</file>

</ruleset>
18 changes: 12 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" bootstrap="vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>

<testsuites>
<testsuite name="League StatsD Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

</phpunit>
Loading

0 comments on commit 272e3b1

Please sign in to comment.