Skip to content

Commit

Permalink
refactor: Merge upstream (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypkhantc authored Jul 5, 2023
1 parent b1028ae commit 3302d22
Show file tree
Hide file tree
Showing 22 changed files with 264 additions and 2,460 deletions.
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.github export-ignore
/art export-ignore
/docs export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/.releaserc.yml export-ignore
/CONTRIBUTING.md export-ignore
/phpstan.neon export-ignore
/phpunit.xml export-ignore
/README.md export-ignore
/UPGRADING.md export-ignore
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
workflow_run:
workflows: ["Tests"]
types:
- completed
branches:
- master
- next
- next-major
- beta
- alpha

jobs:
release:
name: Release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Create a release
uses: cycjimmy/semantic-release-action@v3
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
76 changes: 49 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
name: Tests

on:
push:
pull_request:
on: [push, pull_request]

jobs:
test:
name: Tests & PHPStan on PHP ${{ matrix.php }}

phpunit:
name: PHPUnit on PHP v${{ matrix.php }}
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [7.4, 8.0, 8.1]
php: [ 8.1, 8.2 ]

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -31,7 +27,7 @@ jobs:

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
Expand All @@ -41,45 +37,71 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Execute tests
- name: Execute phpunit
run: composer test -- --colors=always

# Those should usually be a separate job, but as GitHub Actions currently does not support any form of sharing
# steps or an image between them, extracting those to a separate job would mean a full blown copy-paste of this one.
- name: Install dependencies
run: composer install --prefer-dist --no-progress --working-dir=tools/phpstan
php-cs-fixer:
name: php-cs-fixer
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run phpstan
run: composer phpstan
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: none

code-style:
name: Code style
- 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-
runs-on: ubuntu-latest
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Execute php-cs-fixer
run: composer cs-fix -- --dry-run --diff --using-cache=no

phpstan:
name: PHPStan on PHP v${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [ 8.1, 8.2 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: dom, curl, libxml, mbstring, zip
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

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

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress --working-dir=tools/php-cs-fixer
run: composer install --prefer-dist --no-progress

- name: Run php-cs-fixer
run: composer cs-fix -- --dry-run --diff --using-cache=no --diff-format udiff
- name: Execute phpstan
run: composer phpstan
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

# Build/coverage
/build
/coverage

# Cache
.php_cs.cache
.php-cs-fixer.cache
.phpunit.cache
**/.phpunit.result.cache

# Temporary
Expand Down
18 changes: 18 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

require __DIR__ . '/vendor/kubawerlos/php-cs-fixer-custom-fixers/bootstrap.php';
require __DIR__ . '/vendor/tenantcloud/php-cs-fixer-rule-sets/bootstrap.php';

use PhpCsFixer\Finder;
use TenantCloud\PhpCsFixer\Config;

$finder = Finder::create()
->in(__DIR__)
->exclude('build')
->exclude('tmp')
->exclude('vendor')
->name('*.php')
->notName('_*.php')
->ignoreVCS(true);

return Config::make()->setFinder($finder);
16 changes: 0 additions & 16 deletions .php_cs

This file was deleted.

6 changes: 6 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins:
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/changelog'
- '@semantic-release/git'
- '@semantic-release/github'
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Commands

Here are some of the commands that you'll need:
- install dependencies: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer install`
- run tests with phpunit: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer test`
- reformat using php-cs-fixer: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer cs-fix`
- analyse with phpstan: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer phpstan`
81 changes: 43 additions & 38 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
{
"name": "tenantcloud/data-transfer-objects",
"description": "PHP data transfer objects",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
{
"name": "Team Tenantcloud",
"email": "[email protected]"
}
],
"require": {
"php": ">=7.4 || ^8.0",
"ext-json": "*",
"illuminate/support": "^8.0 || ^9.0",
"spatie/macroable": "1.0.1",
"tenantcloud/php-standard": "1.2 || ^1.4 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"orchestra/testbench": "^6.0 || ^7.0",
"friendsofphp/php-cs-fixer": "~2.18.2",
"tenantcloud/php-cs-fixer-rule-sets": "~1.1.0"
},
"autoload": {
"psr-0": {
"": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"cs-fix": "./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v --show-progress=estimating",
"phpstan": "./tools/phpstan/vendor/bin/phpstan analyse"
}
"name": "tenantcloud/data-transfer-objects",
"description": "PHP data transfer objects",
"license": "MIT",
"require": {
"php": ">=8.1",
"ext-json": "*",
"illuminate/support": "^9.0|^10.0",
"spatie/macroable": "1.0.1",
"tenantcloud/php-standard": "1.2 || ^1.4 || ^2.0"
},
"require-dev": {
"pestphp/pest": "^1.0|^2.8",
"orchestra/testbench": "^7.0|^8.5",
"php-cs-fixer/shim": "~3.19.2",
"tenantcloud/php-cs-fixer-rule-sets": "~3.0.0",
"phpstan/phpstan": "~1.10.21",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpstan/phpstan-mockery": "^1.1"
},
"autoload": {
"psr-4": {
"TenantCloud\\DataTransferObjects\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"test": "vendor/bin/pest",
"coverage": "XDEBUG_MODE=coverage vendor/bin/pest --coverage-html coverage",
"cs-fix": "vendor/bin/php-cs-fixer fix -v --show-progress=dots",
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2G"
},
"minimum-stability": "stable",
"prefer-stable": true,
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
includes:
- tools/phpstan/vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
- vendor/phpstan/phpstan-mockery/extension.neon

parameters:
level: 1
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
colors="true"
>
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
<directory>./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<coverage/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ abstract class CamelDataTransferObject implements Arrayable
{
use IsDataTransferObject;

/**
* {@inheritdoc}
*/
protected function methodToKey(string $key): string
{
return lcfirst($key);
}

/**
* {@inheritdoc}
*/
protected function keyToMethod(string $key): string
{
return ucfirst($key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ abstract class DataTransferObject implements Arrayable, JsonSerializable
{
use IsDataTransferObject;

/**
* {@inheritdoc}
*/
protected function methodToKey(string $key): string
{
return Str::snake($key);
}

/**
* {@inheritdoc}
*/
protected function keyToMethod(string $key): string
{
return Str::studly($key);
Expand Down
File renamed without changes.
Loading

0 comments on commit 3302d22

Please sign in to comment.