Skip to content

Commit

Permalink
Moving to Github Action and removing support for old php versions (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebeaudoin authored Mar 14, 2022
1 parent 41aeb78 commit c45d21a
Show file tree
Hide file tree
Showing 25 changed files with 283 additions and 142 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Api Response Tests

on: [push, pull_request]

jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-20.04]
php: [7.4, 8.0, 8.1]

name: PHP ${{ matrix.php }} on ${{ matrix.os }}

steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: phpunit

- name: Download dependencies
uses: ramsey/composer-install@v2

- name: Run Tests
run: composer test -- --coverage-text
46 changes: 46 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on: [ pull_request ]
name: Static analysis

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-20.04

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: apcu, redis
coverage: none
tools: phpstan:1.4.10

- name: Download dependencies
uses: ramsey/composer-install@v1

- name: PHPStan
run: phpstan analyze

psalm:
name: Psalm
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: apcu, redis
coverage: none
tools: vimeo/psalm:4.22.0

- name: Download dependencies
uses: ramsey/composer-install@v1

- name: Psalm
run: psalm --no-progress --output-format=github
32 changes: 32 additions & 0 deletions .github/workflows/style-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Api Response Style Checks

on: [push, pull_request]

jobs:
style:
runs-on: ubuntu-latest
name: Api Response Style Checks
steps:

- name: Checkout Code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Cache Dependencies
id: composer-cache-style
uses: actions/cache@v2
with:
path: vendor
key: ubuntu-composer-cache-style-${{ hashFiles('**/composer.lock') }}
restore-keys: ubuntu-php-style

- name: Install Dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest

- name: Check Coding Style
run: vendor/bin/phpcs src/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
build
vendor
composer.lock
Expand Down
22 changes: 0 additions & 22 deletions .scrutinizer.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

29 changes: 5 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

[![Latest Version](https://img.shields.io/github/release/ellipsesynergie/api-response.svg?style=flat-square)](https://github.com/ellipsesynergie/api-response/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/ellipsesynergie/api-response.svg?style=flat-square)](https://travis-ci.org/ellipsesynergie/api-response)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/ellipsesynergie/api-response.svg?style=flat-square)](https://scrutinizer-ci.com/g/ellipsesynergie/api-response/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/ellipsesynergie/api-response.svg?style=flat-square)](https://scrutinizer-ci.com/g/ellipsesynergie/api-response)
![Api Response Tests](https://github.com/ellipsesynergie/api-response/actions/workflows/run-test.yml/badge.svg)
[![Total Downloads](https://img.shields.io/packagist/dt/ellipsesynergie/api-response.svg?style=flat-square)](https://packagist.org/packages/ellipsesynergie/api-response)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/4d91348d-221b-4ee8-97cc-3e26383092c5/mini.png)](https://insight.sensiolabs.com/projects/4d91348d-221b-4ee8-97cc-3e26383092c5)

Simple package to handle response properly in your API. This package uses [Fractal](https://github.com/thephpleague/fractal)
and is based on [Build APIs You Won't Hate](https://leanpub.com/build-apis-you-wont-hate) book.
Expand All @@ -21,34 +18,18 @@ $ composer require ellipsesynergie/api-response

## Requirements

The following versions of PHP are supported by this version.
The following versions of PHP are supported by this version:

* PHP 5.6
* PHP 7.0
* PHP 7.1
* PHP 7.2
>= PHP 7.4

### Install in Laravel 4

Unfortunately, since the release 0.9.0, Laravel 4 is no longer supported because `league/[email protected]` no longer support this version.
However, you can use the version `0.8.*` if you need to use it inside Laravel 4.

### Install in Laravel 5
### Install in Laravel
Add this following service provider to your `config/app.php` file.

```php
EllipseSynergie\ApiResponse\Laravel\ResponseServiceProvider::class
```

### Install in Lumen 5

Register this service provider to your `bootstrap/app.php` file.

```php
$app->register('EllipseSynergie\ApiResponse\Laravel\LumenServiceProvider');
```

### Install in Lumen 5.4+
### Install in Lumen

Because of the request object change ([see reference](https://laravel-news.com/request-object-changes-in-lumen-5-4)) you can no longer access `Request` object properly in Service provider. To be convenient, we have created a middleware to be used for parsing the `include` parameter.

Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
"league/fractal": "~0.20"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"mockery/mockery": "~0.9",
"illuminate/contracts": "~5.0",
"illuminate/http": "~5.0"
"phpunit/phpunit": "~9.0",
"mockery/mockery": "~1.0",
"illuminate/contracts": "~8.0",
"illuminate/http": "~8.0",
"phpstan/phpstan": "^1.4",
"vimeo/psalm": "^4.22",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand All @@ -38,7 +41,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.17-dev"
"dev-master": "0.21-dev"
}
},
"scripts": {
Expand Down
13 changes: 13 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<ruleset name="PSR12">
<description>PSR12</description>
<rule ref="PSR12">
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing"/>
</rule>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="150"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
</ruleset>
17 changes: 17 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:
ignoreErrors:
-
message: "#^Function response not found\\.$#"
count: 1
path: src/Laravel/Response.php

-
message: "#^Parameter \\#1 \\$message of method EllipseSynergie\\\\ApiResponse\\\\AbstractResponse\\:\\:errorWrongArgs\\(\\) expects string, array given\\.$#"
count: 1
path: src/Laravel/Response.php

-
message: "#^Call to static method macro\\(\\) on an unknown class Response\\.$#"
count: 1
path: src/Laravel/ResponseServiceProvider.php

8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- ./phpstan-baseline.neon

parameters:
level: 5
reportUnmatchedIgnoredErrors: false
paths:
- src
27 changes: 10 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<file>src/Laravel/ResponseServiceProvider.php</file>
<file>src/Laravel/LumenServiceProvider.php</file>
<file>src/Testing/Laravel/AddTestingSupportForInclude.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>src/Laravel/ResponseServiceProvider.php</file>
<file>src/Laravel/LumenServiceProvider.php</file>
<file>src/Testing/Laravel/AddTestingSupportForInclude.php</file>
</exclude>
</coverage>
</phpunit>
24 changes: 24 additions & 0 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.22.0@fc2c6ab4d5fa5d644d8617089f012f3bb84b8703">
<file src="src/Laravel/LumenServiceProvider.php">
<UndefinedInterfaceMethod occurrences="1">
<code>$this-&gt;app</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Laravel/Response.php">
<InvalidArgument occurrences="1">
<code>$validator-&gt;getMessageBag()-&gt;toArray()</code>
</InvalidArgument>
<UndefinedFunction occurrences="1">
<code>response()</code>
</UndefinedFunction>
</file>
<file src="src/Laravel/ResponseServiceProvider.php">
<UndefinedClass occurrences="1">
<code>\Response</code>
</UndefinedClass>
<UndefinedInterfaceMethod occurrences="1">
<code>$this-&gt;app</code>
</UndefinedInterfaceMethod>
</file>
</files>
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="5"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm.baseline.xml"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
Loading

0 comments on commit c45d21a

Please sign in to comment.