Skip to content

Commit 5eb96d7

Browse files
authored
feat: PHP SDK (#9)
* docs: updating the year on the node pkg license * feat: pulling over the php sdk from https://github.com/readmeio/metrics-php * ci: directing the node workflow to only look at the node pkg * style: suppressing a TaintedInput Psalm warning for now * ci: pulling psalm taint analysis from ci for now
1 parent 7581fcd commit 5eb96d7

28 files changed

+1349
-13
lines changed

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ updates:
2222
commit-message:
2323
prefix: chore(deps)
2424
prefix-development: chore(deps-dev)
25+
26+
- package-ecosystem: composer
27+
directory: "/"
28+
schedule:
29+
interval: weekly
30+
open-pull-requests-limit: 10
31+
reviewers:
32+
- erunion
33+
labels:
34+
- scope:dependency
35+
commit-message:
36+
prefix: chore(deps)
37+
prefix-development: chore(deps-dev)

.github/workflows/nodejs.yml

+15-12
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
8+
defaults:
9+
run:
10+
working-directory: packages/node
911

1012
strategy:
1113
matrix:
1214
node-version: [10.x, 12.x, 14.x]
1315

1416
steps:
15-
- uses: actions/[email protected]
16-
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/[email protected]
18-
with:
19-
node-version: ${{ matrix.node-version }}
20-
- name: npm install and test
21-
run: |
22-
npm install
23-
npm test
24-
env:
25-
CI: true
17+
- uses: actions/[email protected]
18+
19+
- uses: actions/[email protected]
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
23+
- name: Run tests
24+
run: |
25+
npm install
26+
npm test
27+
env:
28+
CI: true

.github/workflows/php.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: php
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
defaults:
9+
run:
10+
working-directory: packages/php
11+
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
php: [7.2, 7.3, 7.4]
16+
laravel: [6.*, 7.*]
17+
dependency-version: [prefer-lowest, prefer-stable]
18+
include:
19+
- laravel: 7.*
20+
- laravel: 6.*
21+
22+
name: build (${{ matrix.php }} w/ Laravel ${{ matrix.laravel }} @${{ matrix.dependency-version }})
23+
24+
steps:
25+
- uses: actions/[email protected]
26+
27+
- name: Cache dependencies
28+
uses: actions/cache@v1
29+
with:
30+
path: ~/.composer/cache/files
31+
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
38+
- name: Install dependencies
39+
run: |
40+
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
41+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
42+
43+
- name: Check code standards
44+
run: composer run-script lint
45+
46+
- name: Execute static analysis
47+
run: composer run-script psalm
48+
49+
- name: Run tests
50+
run: composer run-script phpunit

packages/node/LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2018, Dom Harrington <[email protected]>
1+
Copyright (c) 2020, ReadMe
22

33
Permission to use, copy, modify, and/or distribute this software for any purpose
44
with or without fee is hereby granted, provided that the above copyright notice

packages/node/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Track your API metrics within ReadMe.
44

5+
[![npm](https://img.shields.io/npm/v/readmeio.svg)](https://npm.im/readmeio)
56
[![Build](https://github.com/readmeio/metrics-sdks/workflows/nodejs/badge.svg)](https://github.com/readmeio/metrics-sdks)
67

78
[![](https://d3vv6lp55qjaqc.cloudfront.net/items/1M3C3j0I0s0j3T362344/Untitled-2.png)](https://readme.io)

packages/php/.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tests/ export-ignore
2+
.gitattributes export-ignore
3+
.gitignore export-ignore
4+
phpcs.xml export-ignore
5+
phpunit.xml export-ignore
6+
psalm.xml export-ignore

packages/php/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
reports/
2+
vendor/
3+
.phpunit.*
4+
composer.lock

packages/php/LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2020, ReadMe
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose
4+
with or without fee is hereby granted, provided that the above copyright notice
5+
and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13+
THIS SOFTWARE.

packages/php/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# readme/metrics
2+
3+
Track your API metrics within ReadMe.
4+
5+
[![Packagist](https://img.shields.io/packagist/v/readme/metrics.svg)](https://packagist.org/packages/readme/metrics)
6+
[![Build](https://github.com/readmeio/metrics-sdks/workflows/php/badge.svg)](https://github.com/readmeio/metrics-sdks)
7+
8+
[![](https://d3vv6lp55qjaqc.cloudfront.net/items/1M3C3j0I0s0j3T362344/Untitled-2.png)](https://readme.io)
9+
10+
## Installation
11+
12+
```
13+
composer require readme/metrics
14+
```
15+
16+
## Usage
17+
18+
`readme/metrics` is currently targeted towards codebases utilizing the [Laravel](https://laravel.com/) framework. To get up and running, you'll need to do the following things:
19+
20+
1. Publish our config file into your `config/` directory:
21+
22+
```
23+
php artisan vendor:publish --provider="ReadMe\ServiceProvider"
24+
```
25+
26+
2. In `config/readme.php`, change `api_key` to the API key we provide to you in your ReadMe project on https://dash.readme.io.
27+
3. In that config file, you will also see a `group_handler` that will be set to `App\Handler\ReadMe::class`. This file will exist within `app\Handler` in your application and you should change the contents of its `constructGroup` function to return data that's relevant to your codebase and users. We've provided some simple defaults but you'll likely need to change them.
28+
29+
Once you've done all that, add `\ReadMe\Middleware::class` into your API middleware in `app/Http/Kernel.php` and API Metrics will start streaming to your ReadMe project!

packages/php/composer.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "readme/metrics",
3+
"description": "Track your API metrics within ReadMe.",
4+
"homepage": "https://readme.com/metrics",
5+
"license": "ISC",
6+
"authors": [
7+
{
8+
"name": "Jon Ursenbach",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"support": {
13+
"docs": "https://docs.readme.com/docs/sending-api-logs-to-readme",
14+
"issues": "https://github.com/readmeio/metrics-sdks/issues",
15+
"source": "https://github.com/readmeio/metrics-sdks"
16+
},
17+
"keywords": [
18+
"api-metrics",
19+
"readme"
20+
],
21+
"require": {
22+
"php": "^7.2",
23+
"illuminate/http": "^6.8 | ^7.0",
24+
"illuminate/support": "^6.8 | ^7.0",
25+
"guzzlehttp/guzzle": "^6.4",
26+
"ocramius/package-versions": "^1.4"
27+
},
28+
"require-dev": {
29+
"phpunit/phpunit": "^8.4",
30+
"squizlabs/php_codesniffer": "^3.5",
31+
"mockery/mockery": "^1.3",
32+
"vimeo/psalm": ">=3.10"
33+
},
34+
"extra": {
35+
"laravel": {
36+
"providers": [
37+
"ReadMe\\ServiceProvider"
38+
]
39+
}
40+
},
41+
"scripts": {
42+
"coverage": "phpunit --coverage-html reports/",
43+
"lint": "phpcs --standard=phpcs.xml src/ tests/",
44+
"lint:fix": "phpcbf --standard=phpcs.xml src/ tests/",
45+
"phpunit": "phpunit tests/",
46+
"psalm": "psalm",
47+
"psalm:taintAnalysis": "psalm --taint-analysis",
48+
"test": [
49+
"composer run lint",
50+
"composer run psalm",
51+
"composer run phpunit"
52+
]
53+
},
54+
"config": {
55+
"optimize-autoloader": true
56+
},
57+
"autoload": {
58+
"psr-4": {
59+
"ReadMe\\": "src/"
60+
}
61+
},
62+
"autoload-dev": {
63+
"psr-4": {
64+
"ReadMe\\Tests\\": "tests/"
65+
}
66+
}
67+
}

packages/php/phpcs.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<description>ReadMe coding standards</description>
4+
<rule ref="PSR2"/>
5+
6+
<!-- Require that strings be single quoted. -->
7+
<rule ref="Squiz.Strings.DoubleQuoteUsage" />
8+
</ruleset>

packages/php/phpunit.xml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit colors="true">
3+
<testsuites>
4+
<testsuite name="ReadMe Developer Metrics">
5+
<directory>./tests/</directory>
6+
</testsuite>
7+
</testsuites>
8+
9+
<filter>
10+
<whitelist>
11+
<directory>src/</directory>
12+
</whitelist>
13+
</filter>
14+
</phpunit>

packages/php/psalm.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
totallyTyped="true"
4+
errorLevel="2"
5+
resolveFromConfigFile="true"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xmlns="https://getpsalm.org/schema/config"
8+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
9+
>
10+
<projectFiles>
11+
<directory name="src" />
12+
<ignoreFiles>
13+
<directory name="vendor" />
14+
</ignoreFiles>
15+
</projectFiles>
16+
17+
<issueHandlers>
18+
<InvalidReturnType>
19+
<errorLevel type="suppress">
20+
<file name="src/handler.dist.php" />
21+
</errorLevel>
22+
</InvalidReturnType>
23+
</issueHandlers>
24+
</psalm>

packages/php/src/Handler.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace ReadMe;
3+
4+
use Illuminate\Http\Request;
5+
6+
interface Handler
7+
{
8+
public static function constructGroup(Request $request): array;
9+
}

0 commit comments

Comments
 (0)