diff --git a/.editorconfig b/.editorconfig index 7af4007..4974ddc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,4 +12,4 @@ insert_final_newline = true trim_trailing_whitespace = true [*.md] -trim_trailing_whitespace = false \ No newline at end of file +trim_trailing_whitespace = false diff --git a/.github/template-sync.json b/.github/template-sync.json new file mode 100644 index 0000000..adb088a --- /dev/null +++ b/.github/template-sync.json @@ -0,0 +1,8 @@ +{ + "repositories": [ + { + "url": "https://github.com/tenantcloud/php-package-skeleton", + "branch": "sync" + } + ] +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4586539..a48876e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release on: workflow_run: - workflows: ["Tests"] + workflows: ['Tests'] types: - completed branches: @@ -18,17 +18,17 @@ jobs: runs-on: ubuntu-latest if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 + - 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 }} + - 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 }} diff --git a/.github/workflows/template-sync.yml b/.github/workflows/template-sync.yml new file mode 100644 index 0000000..5892379 --- /dev/null +++ b/.github/workflows/template-sync.yml @@ -0,0 +1,62 @@ +name: Template sync + +on: + workflow_dispatch: + schedule: + - cron: '*/5 * * * *' + +jobs: + sync: + name: Sync + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Sync from template + id: sync_from_template + uses: tenantcloud/template-sync@v1.0.0-alpha.9 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Reformat + uses: actionsx/prettier@v2 + with: + args: --write . + + - name: Generate token to read from source repo + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.PACKAGE_SYNC_APP_ID }} + private_key: ${{ secrets.PACKAGE_SYNC_PRIVATE_KEY }} + + - name: Create PR + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ steps.generate_token.outputs.token }} + committer: 'package-sync[bot] <165811605+package-sync[bot]@users.noreply.github.com>' + branch: 'template-sync' + delete-branch: true + title: 'chore: Sync changes from the template' + commit-message: 'chore: Sync changes from the template' + body: ${{ steps.sync_from_template.outputs.report }} + assignees: oprypkhantc + reviewers: oprypkhantc + + # See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule + # GitHub automatically disables `schedule` workflows in public repositories + # after 60 days without commits, so this job is there to prevent it. + workflow-keepalive: + name: Workflow keepalive + runs-on: ubuntu-latest + if: github.event_name == 'schedule' + + permissions: + actions: write + + steps: + - uses: liskin/gh-workflow-keepalive@v1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f0dcfb7..e5c0845 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,66 +9,79 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.1, 8.2 ] + php: [8.2] steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - 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@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 - - - name: Execute phpunit - run: composer test -- --colors=always + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + 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@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 + + - name: Execute phpunit + run: composer test -- --colors=always php-cs-fixer: name: php-cs-fixer runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - extensions: dom, curl, libxml, mbstring, zip - tools: composer:v2 - coverage: none - - - 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 install --prefer-dist --no-progress - - - name: Execute php-cs-fixer - run: composer cs-fix -- --dry-run --diff --using-cache=no + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: dom, curl, libxml, mbstring, zip + tools: composer:v2 + coverage: none + + - 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 install --prefer-dist --no-progress + + - name: Execute php-cs-fixer + run: composer cs-fix -- --dry-run --diff --using-cache=no + + prettier: + name: Prettier + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run prettier + uses: actionsx/prettier@v2 + with: + args: --check . phpstan: name: PHPStan on PHP v${{ matrix.php }} @@ -76,32 +89,32 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.1, 8.2 ] + php: [8.2] steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - 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@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 - - - name: Execute phpstan - run: composer phpstan + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + 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@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 + + - name: Execute phpstan + run: composer phpstan diff --git a/.gitignore b/.gitignore index 099a63a..2a9ce1e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ !.idea/fileTemplates # Dependencies -/vendor/ +/vendor /composer.lock # Build/coverage @@ -16,7 +16,7 @@ **/.phpunit.result.cache # Temporary -tmp/ +/tmp # Misc .DS_Store diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..7f30dcc --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +CHANGELOG.md + +/.idea +/build +/coverage +/tmp +/vendor diff --git a/.prettierrc.yml b/.prettierrc.yml new file mode 100644 index 0000000..0176969 --- /dev/null +++ b/.prettierrc.yml @@ -0,0 +1 @@ +singleQuote: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69cf175..d19c55e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,9 @@ # 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` + +- 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` +- reformat the rest with prettier: `docker run -it --rm -v $PWD:/app -w /app tmknom/prettier --write .` +- analyse with phpstan: `docker run -it --rm -v $PWD:/app -w /app chialab/php-dev:8.2 composer phpstan` diff --git a/README.md b/README.md index e09dc84..43f6ce1 100644 --- a/README.md +++ b/README.md @@ -4,37 +4,40 @@ Laravel data transfer objects. ## Requirements -* PHP version >=7.4.1 -* Docker (optional) +- PHP version >=7.4.1 +- Docker (optional) ## Installation Require this package with composer. + ``` composer require tenantcloud/php-data-transfer-objects ``` ## Examples - // Create empty data object. - $data = ExampleDTO::create(); - - // Serialize for array or json - $data->toArray(); - $data->toJson(); - // Create from existing data - $data = ExampleDTO::from(['foo']); - - // Check is property filled - $data->hasFoo(); + // Create empty data object. + $data = ExampleDTO::create(); + + // Serialize for array or json + $data->toArray(); + $data->toJson(); + + // Create from existing data + $data = ExampleDTO::from(['foo']); - // Get foo property - $data->getFoo(); + // Check is property filled + $data->hasFoo(); - // Set property - $data->setFoo($foo); + // Get foo property + $data->getFoo(); + + // Set property + $data->setFoo($foo); ### Commands + Install dependencies: `docker run -it --rm -v $PWD:/app -w /app composer install` diff --git a/composer.json b/composer.json index 98ef76f..47db79d 100644 --- a/composer.json +++ b/composer.json @@ -1,45 +1,45 @@ { - "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", + "name": "tenantcloud/data-transfer-objects", + "description": "PHP data transfer objects", + "license": "MIT", + "require": { + "php": ">=8.2", + "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": "^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 - } - } + "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 + } + } }