From 81025b25c41f50f3730d11d7fb10ae32a4c1061b Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 29 Oct 2024 17:19:39 +0100 Subject: [PATCH] Initial commit --- .editorconfig | 16 ++ .gitattributes | 21 ++ .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/01-bug-report.yml | 62 ++++++ .github/ISSUE_TEMPLATE/02-feature-request.yml | 53 +++++ .github/ISSUE_TEMPLATE/config.yml | 5 + .github/PULL_REQUEST_TEMPLATE.md | 33 +++ .github/workflows/ci.yml | 108 ++++++++++ .gitignore | 21 ++ .idea/inspectionProfiles/Project_Default.xml | 8 + LICENSE | 21 ++ README.md | 46 +++++ composer.json | 64 ++++++ examples/example.php | 16 ++ phpcs.xml.dist | 191 ++++++++++++++++++ phpmd.xml.dist | 45 +++++ phpstan-baseline.neon | 2 + phpstan.dist.neon | 17 ++ phpunit.xml.dist | 24 +++ src/Example.php | 23 +++ tests/ExampleTest.php | 29 +++ 21 files changed, 806 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/01-bug-report.yml create mode 100644 .github/ISSUE_TEMPLATE/02-feature-request.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 examples/example.php create mode 100644 phpcs.xml.dist create mode 100644 phpmd.xml.dist create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.dist.neon create mode 100644 phpunit.xml.dist create mode 100644 src/Example.php create mode 100644 tests/ExampleTest.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f1c2db0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +indent_style = tab +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.py] +indent_style = space +indent_size = 4 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b9e932a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,21 @@ +/.build export-ignore +/.github export-ignore +/.idea export-ignore +/.phan export-ignore +/.phpdoc export-ignore +/docs export-ignore +/examples export-ignore +/tests export-ignore +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.readthedocs.yml export-ignore +/composer.lock export-ignore +/phpcs.xml.dist export-ignore +/phpdoc.xml.dist export-ignore +/phpmd.xml.dist export-ignore +/phpunit.xml.dist export-ignore +/phpstan.dist.neon export-ignore +/phpstan-baseline.neon export-ignore + +*.php diff=php diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..fc89a67 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +ko_fi: codemasher diff --git a/.github/ISSUE_TEMPLATE/01-bug-report.yml b/.github/ISSUE_TEMPLATE/01-bug-report.yml new file mode 100644 index 0000000..411ad55 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/01-bug-report.yml @@ -0,0 +1,62 @@ +# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms +# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema + +name: "Bug report" +description: "You've found a bug? Does the library not behave as expected?" +title: "[BUG] " +labels: ["bug"] + +body: + + - type: markdown + attributes: + value: "You've found a bug? Does the library not behave as expected?\nPlease help us to improve this project and fill out the following form.\nIf you are unsure whether it is a bug, or you have a question or an issue that is not a bug, please go to [the discussions section](../discussions) instead. Thanks!" + + - type: textarea + validations: + required: true + attributes: + label: "Issue description" + description: "Please describe the bug or unexpected behaviour, add screenshots to help explain the problem if applicable." + placeholder: "A clear and concise description of the issue" + + - type: textarea + validations: + required: true + attributes: + label: "Expected behavior" + description: "Please describe what you expected to happen or how the library should behave in this case." + placeholder: "A clear and concise description of what you expected to happen" + + - type: textarea + validations: + required: false + attributes: + label: "Code sample" + description: "If applicable, please add a code sample that reproduces the issue.\nNote: the content of this textarea will be rendered as PHP code!" + placeholder: "PHP code" + render: php + + - type: dropdown + id: version + validations: + required: true + attributes: + label: "Library version" + description: "What version of the library are you running?" + options: + - "latest" + - "dev-main" + - "1.x" + default: 0 + + - type: textarea + validations: + required: false + attributes: + label: "Additional context" + description: "Add any other context that might be of use here, e.g. exact library version, PHP Version, operating system, other code snippets..." + + - type: markdown + attributes: + value: "Thanks for taking the time to fill out this issue report!" diff --git a/.github/ISSUE_TEMPLATE/02-feature-request.yml b/.github/ISSUE_TEMPLATE/02-feature-request.yml new file mode 100644 index 0000000..f18d1ec --- /dev/null +++ b/.github/ISSUE_TEMPLATE/02-feature-request.yml @@ -0,0 +1,53 @@ +# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms +# https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema + +name: "Feature request" +description: "You have an idea for a new feature?" +title: "[ENHANCEMENT] " +labels: ["enhancement"] + +body: + + - type: markdown + attributes: + value: "You have an idea for a new feature (or improve an existing one)? Great!\nPlease help us to improve this project and fill out the following form.\nIf you have a question or an issue that is not a feature request, please go to [the discussions section](../discussions) instead. Thanks!" + + - type: textarea + validations: + required: true + attributes: + label: "Feature description" + description: "Please describe the requested feature." + placeholder: "A clear and concise description of the requested feature" + + - type: textarea + validations: + required: false + attributes: + label: "Code sample" + description: "If applicable, please add a code sample to illustrate the feature.\nNote: the content of this textarea will be rendered as PHP code!" + placeholder: "PHP code" + render: php + + - type: textarea + validations: + required: false + attributes: + label: "Additional context" + description: "Add any other context that might be of use here, e.g. other code snippets..." + + - type: dropdown + validations: + required: true + id: pr + attributes: + label: "Pull Request" + description: "**Are you (the requester) willing to submit a pull request for that feature?**\nA yes will greatly increase the chance that the feature will be added." + options: + - "" + - "No - I can't/won't submit a PR" + - "Yes - I will submit a PR" + + - type: markdown + attributes: + value: "Thanks for taking the time to fill out this feature request!" diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..1953e4a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: "You have a question or an issue that is not a bug?" + about: "Please use the Q&A section under discussions. Thanks!" + url: https://github.com/chillerlan/php-library-template/discussions diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..5b45485 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,33 @@ +## Proposed changes + + + + + + +## Types of changes + + + +What types of changes does your code introduce? + +- [ ] Bugfix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Documentation fix or enhancement (no code was touched) +- [ ] Other (CI, dependencies, etc., please describe) + + +## Checklist: + +- [ ] I have checked to ensure there aren't other open [Issues](../../../issues) or [Pull Requests](../../../pulls) for the same update/change +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added necessary documentation (if appropriate) +- [ ] Any dependent changes have been merged and published in downstream modules +- [ ] Static analysis and unit tests pass locally with my changes + + +## Further comments + +If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d5f7917 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,108 @@ +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions +# https://github.com/sebastianbergmann/phpunit/blob/main/.github/workflows/ci.yaml + +# https://github.com/actions/checkout +# https://github.com/actions/upload-artifact +# https://github.com/shivammathur/setup-php +# https://github.com/ramsey/composer-install +# https://github.com/codecov/codecov-action +# https://github.com/codacy/codacy-coverage-reporter-action +# https://github.com/JamesIves/github-pages-deploy-action +# https://github.com/stefanzweifel/git-auto-commit-action + +on: + push: + branches: + - main + pull_request: + branches: + - main + +name: "Continuous Integration" + +env: + PHP_EXTENSIONS: "" # caution: setting 'none' resets/disables shared extensions + PHP_INI_VALUES: memory_limit=-1, error_reporting=-1, display_errors=On + +jobs: + + static-code-analysis: + name: "Static Code Analysis" + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php-version: + - "8.1" + - "8.2" + - "8.3" + + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + - name: "Install PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: ${{ env.PHP_EXTENSIONS }} + ini-values: ${{ env.PHP_INI_VALUES }} + coverage: none + + - name: "Validate composer.json" + run: composer validate --ansi --strict + + - name: "Install dependencies with composer" + uses: ramsey/composer-install@v3 + + - name: "Run PHPStan" + run: php vendor/bin/phpstan + + + tests: + name: "Unit Tests" + needs: static-code-analysis + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + php-version: + - "8.1" + - "8.2" + - "8.3" + + steps: + - name: "Checkout" + uses: actions/checkout@v4 + + - name: "Install PHP with extensions" + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: ${{ env.PHP_EXTENSIONS }} + ini-values: ${{ env.PHP_INI_VALUES }} + coverage: pcov + + - name: "Install dependencies with composer" + uses: ramsey/composer-install@v3 + + - name: "Run tests with phpunit" + run: php vendor/bin/phpunit --colors=always --configuration=phpunit.xml.dist + +# - name: "Send code coverage report to Codecov.io" +# uses: codecov/codecov-action@v4 +# with: +# token: ${{ secrets.CODECOV_TOKEN }} +# files: .build/coverage/clover.xml + +# - name: "Send code coverage report to Codacy" +# uses: codacy/codacy-coverage-reporter-action@v1 +# with: +# project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} +# coverage-reports: .build/coverage/clover.xml + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7420578 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# IDE - IntelliJ +.idea/* +# Keep the code styles. +!.idea/codeStyles +.idea/codeStyles/* +!.idea/codeStyles/Project.xml +!.idea/codeStyles/codeStyleConfig.xml +# Keep the inspection levels +!.idea/inspectionProfiles +.idea/inspectionProfiles/* +!.idea/inspectionProfiles/Project_Default.xml + +# project stuff +.build/* +vendor/* +composer.lock +phpcs.xml +phpdoc.xml +phpmd.xml +phpunit.xml +phpstan.neon diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..62cae6e --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..28dfe7a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 smiley + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..63e18da --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# chillerlan/php-library-template-nodocs + +A template/boilerplate for PHP libraries (similar to [chillerlan/php-library-template](https://github.com/chillerlan/php-library-template) but without phpdocs and readthedocs deployment). + +[![PHP Version Support][php-badge]][php] +[![Packagist version][packagist-badge]][packagist] +[![License][license-badge]][license] +[![Continuous Integration][gh-action-badge]][gh-action] +[![CodeCov][coverage-badge]][coverage] +[![Packagist downloads][downloads-badge]][downloads] + +[php-badge]: https://img.shields.io/packagist/php-v/chillerlan/php-library-template-nodocs?logo=php&color=8892BF&logoColor=fff +[php]: https://www.php.net/supported-versions.php +[packagist-badge]: https://img.shields.io/packagist/v/chillerlan/php-library-template-nodocs.svg?logo=packagist&logoColor=fff +[packagist]: https://packagist.org/packages/chillerlan/php-library-template-nodocs +[license-badge]: https://img.shields.io/github/license/chillerlan/php-library-template-nodocs +[license]: https://github.com/chillerlan/php-library-template-nodocs/blob/main/LICENSE +[gh-action-badge]: https://img.shields.io/github/actions/workflow/status/chillerlan/php-library-template-nodocs/ci.yml?branch=main&logo=github&logoColor=fff +[gh-action]: https://github.com/chillerlan/php-library-template-nodocs/actions/workflows/ci.yml?query=branch%3Amain +[coverage-badge]: https://img.shields.io/codecov/c/github/chillerlan/php-library-template-nodocs.svg?logo=codecov&logoColor=fff +[coverage]: https://codecov.io/github/chillerlan/php-library-template-nodocs +[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-library-template-nodocs.svg?logo=packagist&logoColor=fff +[downloads]: https://packagist.org/packages/chillerlan/php-library-template-nodocs/stats + +## Overview + +### Features + +- [GitHub Actions](https://github.com/chillerlan/php-library-template-nodocs/actions) runner +- [Composer](https://getcomposer.org) dependency management +- [PHPUnit](https://phpunit.de) unit tests +- [PHPStan](https://github.com/phpstan/phpstan) static analysis +- [PHPCS](https://github.com/PHPCSStandards/PHP_CodeSniffer) coding standard analyzer +- [PHPMD](https://phpmd.org) mess detector +- [Codecov](https://codecov.io) code coverage analysis +- [phpDocumentor](https://www.phpdoc.org) auto generated API docs + + +### Requirements + +- PHP 8.1+ + + +## Disclaimer + +Use at your own risk! diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1b9ae73 --- /dev/null +++ b/composer.json @@ -0,0 +1,64 @@ +{ + "$schema": "https://getcomposer.org/schema.json", + "name": "chillerlan/php-library-template-nodocs", + "description": "A PHP Library template/boilerplate.", + "license": "MIT", + "type": "library", + "keywords": ["boilerplate", "library-template"], + "authors": [ + { + "name": "smiley", + "email": "smiley@chillerlan.net", + "homepage": "https://github.com/codemasher" + }, + { + "name": "Contributors", + "homepage":"https://github.com/chillerlan/php-library-template-nodocs/graphs/contributors" + } + ], + "funding": [ + { + "type": "Ko-Fi", + "url": "https://ko-fi.com/codemasher" + } + ], + "homepage": "https://github.com/chillerlan/php-library-template-nodocs", + "support": { + "issues": "https://github.com/chillerlan/php-library-template-nodocs/issues", + "source": "https://github.com/chillerlan/php-library-template-nodocs" + }, + "minimum-stability": "stable", + "prefer-stable": true, + "require": { + "php": "^8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.5", + "phpmd/phpmd": "^2.15", + "phpstan/phpstan": "^1.11", + "phpstan/phpstan-deprecation-rules": "^1.2", + "squizlabs/php_codesniffer": "^3.10" + }, + "suggest": { + }, + "autoload": { + "psr-4": { + "chillerlan\\LibraryTemplate\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "chillerlan\\LibraryTemplateTest\\": "tests" + } + }, + "scripts": { + "phpcs": "@php vendor/bin/phpcs", + "phpunit": "@php vendor/bin/phpunit", + "phpstan": "@php vendor/bin/phpstan" + }, + "config": { + "lock": false, + "sort-packages": true, + "platform-check": true + } +} diff --git a/examples/example.php b/examples/example.php new file mode 100644 index 0000000..38e2b1d --- /dev/null +++ b/examples/example.php @@ -0,0 +1,16 @@ + + * @copyright 2024 smiley + * @license MIT + */ +declare(strict_types=1); + +require_once __DIR__.'/../vendor/autoload.php'; + +$example = new \chillerlan\LibraryTemplate\Example; + +echo $example->hello(); diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..75125bf --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,191 @@ + + + chillerlan rules for phpcs + + examples + src + tests + + + + + + error + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + error + + + + error + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + examples + + + + examples + + + + examples + + + + examples + + + + examples + + + diff --git a/phpmd.xml.dist b/phpmd.xml.dist new file mode 100644 index 0000000..a447d07 --- /dev/null +++ b/phpmd.xml.dist @@ -0,0 +1,45 @@ + + + + codemasher/chillerlan PMD ruleset + */examples/* + */vendor/* + */tests/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..aab4991 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: [] diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..a545e56 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,17 @@ +# https://phpstan.org/config-reference + +parameters: + level: 9 + tmpDir: .build/phpstan-cache + paths: + - examples + - src + - tests + + treatPhpDocTypesAsCertain: false + +includes: + - phpstan-baseline.neon + - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-deprecation-rules/rules.neon +# - vendor/chillerlan/php-settings-container/rules-magic-access.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..aaf4f64 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,24 @@ + + + + + tests + + + + + src + + + + + + + + + diff --git a/src/Example.php b/src/Example.php new file mode 100644 index 0000000..a7fdf20 --- /dev/null +++ b/src/Example.php @@ -0,0 +1,23 @@ + + * @copyright 2024 smiley + * @license MIT + */ +declare(strict_types=1); + +namespace chillerlan\LibraryTemplate; + +/** + * + */ +class Example{ + + public function hello():string{ + return 'hi'; + } + +} diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php new file mode 100644 index 0000000..900fae9 --- /dev/null +++ b/tests/ExampleTest.php @@ -0,0 +1,29 @@ + + * @copyright 2024 smiley + * @license MIT + */ +declare(strict_types=1); + +namespace chillerlan\LibraryTemplateTest; + +use chillerlan\LibraryTemplate\Example; +use PHPUnit\Framework\TestCase; + +/** + * + */ +class ExampleTest extends TestCase{ + + public function testInstance():void{ + $obj = new Example; + + $this::assertInstanceOf(Example::class, $obj); + $this::assertSame('hi', $obj->hello()); + } + +}