Initial commit

This commit is contained in:
Andrea Marco Sartori 2022-09-16 07:17:51 +10:00
commit e7ffe59871
20 changed files with 731 additions and 0 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

17
.gitattributes vendored Normal file
View File

@ -0,0 +1,17 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# Ignore all test and documentation with "export-ignore".
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/.travis.yml export-ignore
/PULL_REQUEST_TEMPLATE.md export-ignore
/ISSUE_TEMPLATE.md export-ignore
/phpcs.xml.dist export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/docs export-ignore
/.github export-ignore

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: cerbero90

87
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,87 @@
name: build
on:
push:
pull_request:
jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php: [8.0, 8.1]
laravel: [8.*, 9.*]
dependency-version: [prefer-stable]
os: [ubuntu-latest]
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: none
- name: Install dependencies
run: |
composer require "illuminate/contracts=${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest --verbose
coverage:
runs-on: ubuntu-latest
name: Coverage
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: dom, curl, libxml, mbstring, zip
tools: composer:v2
coverage: xdebug
- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest --coverage-text --coverage-clover=coverage.clover
- name: Upload coverage
run: |
vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
style:
runs-on: ubuntu-latest
name: Coding style
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: phpcs
coverage: none
- name: Execute check
run: phpcs --standard=psr12 src/

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
build
composer.lock
vendor
phpcs.xml
phpunit.xml
.phpunit.result.cache

30
.scrutinizer.yml Normal file
View File

@ -0,0 +1,30 @@
build:
nodes:
analysis:
project_setup:
override: true
tests:
override: [php-scrutinizer-run]
filter:
excluded_paths: [tests/*]
checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
tools:
external_code_coverage:
timeout: 600

1
.styleci.yml Normal file
View File

@ -0,0 +1 @@
preset: psr12

22
CHANGELOG.md Normal file
View File

@ -0,0 +1,22 @@
# Changelog
All notable changes to `:package_name` will be documented in this file.
Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## NEXT - YYYY-MM-DD
### Added
- Nothing
### Deprecated
- Nothing
### Fixed
- Nothing
### Removed
- Nothing
### Security
- Nothing

74
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,74 @@
# Contributor Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at `andrea.marco.sartori@gmail.com`. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

32
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,32 @@
# Contributing
Contributions are **welcome** and will be fully **credited**.
We accept contributions via Pull Requests on [Github](https://github.com/cerbero90/:package_name).
## Pull Requests
- **[PSR-12 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-12-extended-coding-style-guide.md)** - Check the code style with ``$ composer check-style`` and fix it with ``$ composer fix-style``.
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
- **Create feature branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
## Running Tests
``` bash
$ composer test
```
**Happy coding**!

27
ISSUE_TEMPLATE.md Normal file
View File

@ -0,0 +1,27 @@
<!-- Provide a general summary of the issue in the Title above -->
## Detailed description
Provide a detailed description of the change or addition you are proposing.
Make it clear if the issue is a bug, an enhancement or just a question.
## Context
Why is this change important to you? How would you use it?
How can it benefit other users?
## Possible implementation
Not obligatory, but suggest an idea for implementing addition or change.
## Your environment
Include as many relevant details about the environment you experienced the bug in and how to reproduce it.
* Version used (e.g. PHP 5.6, HHVM 3):
* Operating system and version (e.g. Ubuntu 16.04, Windows 7):
* Link to your project:
* ...
* ...

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
# The MIT License (MIT)
Copyright (c) 2020 Andrea Marco Sartori <andrea.marco.sartori@gmail.com>
> 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.

43
PULL_REQUEST_TEMPLATE.md Normal file
View File

@ -0,0 +1,43 @@
<!--- Provide a general summary of your changes in the Title above -->
## Description
Describe your changes in detail.
## Motivation and context
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here (if you write `fixes #num`
or `closes #num`, the issue will be automatically closed when the pull is accepted.)
## How has this been tested?
Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc.
## Screenshots (if appropriate)
## Types of changes
What types of changes does your code introduce? Put an `x` in all the boxes that apply:
- [ ] Bug fix (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 change)
## Checklist:
Go over all the following points, and put an `x` in all the boxes that apply.
Please, please, please, don't send your pull request until all of the boxes are ticked. Once your pull request is created, it will trigger a build on our [continuous integration](http://www.phptherightway.com/#continuous-integration) server to make sure your [tests and code style pass](https://help.github.com/articles/about-required-status-checks/).
- [ ] I have read the **[CONTRIBUTING](CONTRIBUTING.md)** document.
- [ ] My pull request addresses exactly one patch/feature.
- [ ] I have created a branch for this patch/feature.
- [ ] Each individual commit in the pull request is meaningful.
- [ ] I have added tests to cover my changes.
- [ ] If my change requires a change to the documentation, I have updated it accordingly.
If you're unsure about any of these, don't hesitate to ask. We're here to help!

88
README.md Normal file
View File

@ -0,0 +1,88 @@
# :package_title
[![Author][ico-author]][link-author]
[![PHP Version][ico-php]][link-php]
[![Laravel Version][ico-laravel]][link-laravel]
[![Octane Compatibility][ico-octane]][link-octane]
[![Build Status][ico-actions]][link-actions]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Latest Version][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![PSR-12][ico-psr12]][link-psr12]
[![Total Downloads][ico-downloads]][link-downloads]
:package_description
## 📦 Install
Via Composer:
``` bash
composer require cerbero/:package_name
```
## 🔮 Usage
1. Create a new package by [using this template](https://github.com/cerbero90/skeleton/generate)
1. Clone the newly created repository
1. Run `php prefill.php`
1. Delete `prefill.php`
1. Review versions of PHP and Laravel to support in [composer.json](composer.json), [build.yml](.github/workflows/build.yml) and [README badges](README.md)
1. Push changes to master
1. Submit package to [Packagist](https://packagist.org/packages/submit)
1. Add repository to [Scrutinizer](https://scrutinizer-ci.com/g/new)
1. Initialize GitFlow
1. Happy coding!
## 📆 Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## 🧪 Testing
``` bash
composer test
```
## 💞 Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
## 🧯 Security
If you discover any security related issues, please email andrea.marco.sartori@gmail.com instead of using the issue tracker.
## 🏅 Credits
- [Andrea Marco Sartori][link-author]
- [All Contributors][link-contributors]
## ⚖️ License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-author]: https://img.shields.io/static/v1?label=author&message=cerbero90&color=50ABF1&logo=twitter&style=flat-square
[ico-php]: https://img.shields.io/packagist/php-v/cerbero/:package_name?color=%234F5B93&logo=php&style=flat-square
[ico-laravel]: https://img.shields.io/static/v1?label=laravel&message=%E2%89%A55.5&color=ff2d20&logo=laravel&style=flat-square
[ico-octane]: https://img.shields.io/static/v1?label=octane&message=compatible&color=ff2d20&logo=laravel&style=flat-square
[ico-version]: https://img.shields.io/packagist/v/cerbero/:package_name.svg?label=version&style=flat-square
[ico-actions]: https://img.shields.io/github/workflow/status/cerbero90/:package_name/build?style=flat-square&logo=github
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-psr12]: https://img.shields.io/static/v1?label=compliance&message=PSR-12&color=blue&style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/cerbero90/:package_name.svg?style=flat-square&logo=scrutinizer
[ico-code-quality]: https://img.shields.io/scrutinizer/g/cerbero90/:package_name.svg?style=flat-square&logo=scrutinizer
[ico-downloads]: https://img.shields.io/packagist/dt/cerbero/:package_name.svg?style=flat-square
[link-author]: https://twitter.com/cerbero90
[link-php]: https://www.php.net
[link-laravel]: https://laravel.com
[link-octane]: https://github.com/laravel/octane
[link-packagist]: https://packagist.org/packages/cerbero/:package_name
[link-actions]: https://github.com/cerbero90/:package_name/actions?query=workflow%3Abuild
[link-psr12]: https://www.php-fig.org/psr/psr-12/
[link-scrutinizer]: https://scrutinizer-ci.com/g/cerbero90/:package_name/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/cerbero90/:package_name
[link-downloads]: https://packagist.org/packages/cerbero/:package_name
[link-contributors]: ../../contributors

57
composer.json Normal file
View File

@ -0,0 +1,57 @@
{
"name": "cerbero/:package_name",
"type": "library",
"description": ":package_description",
"keywords": [
"laravel"
],
"homepage": "https://github.com/cerbero90/:package_name",
"license": "MIT",
"authors": [{
"name": "Andrea Marco Sartori",
"email": "andrea.marco.sartori@gmail.com",
"homepage": "https://github.com/cerbero90",
"role": "Developer"
}],
"require": {
"php": "^8.0",
"illuminate/support": ">=8.0"
},
"require-dev": {
"orchestra/testbench": ">=6.0",
"pestphp/pest": "^1.21",
"scrutinizer/ocular": "^1.8",
"squizlabs/php_codesniffer": "^3.0"
},
"autoload": {
"psr-4": {
"Cerbero\\:package_ns\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Cerbero\\:package_ns\\": "tests"
}
},
"scripts": {
"test": "pest",
"check-style": "phpcs --standard=PSR12 src",
"fix-style": "phpcbf --standard=PSR12 src"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"providers": [
"Cerbero\\:package_ns\\Providers\\:package_nsServiceProvider"
]
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}

14
phpcs.xml.dist Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset name=":package_name">
<description>The coding standard of :package_name package</description>
<arg value="p" />
<config name="ignore_warnings_on_exit" value="1" />
<config name="ignore_errors_on_exit" value="1" />
<arg name="colors" />
<arg value="s" />
<!-- Use the PSR12 Standard-->
<rule ref="PSR12" />
</ruleset>

28
phpunit.xml.dist Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="cerbero90 Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>

110
prefill.php Normal file
View File

@ -0,0 +1,110 @@
<?php
define('COL_DESCRIPTION', 0);
define('COL_HELP', 1);
define('COL_DEFAULT', 2);
$fields = [
'package_name' => ['Package name', '<package> in https://github.com/vendor/package', basename(__DIR__)],
'package_description' => ['Package very short description', '', ''],
];
$values = [];
$replacements = [
':package_name' => function () use (&$values) {
return $values['package_name'];
},
':package_ns' => function () use (&$values) {
$value = ucwords(str_replace(['-', '_'], ' ', $values['package_name']));
return str_replace(' ', '', $value);
},
':package_title' => function () use (&$values) {
return ucwords(str_replace(['-', '_'], ' ', $values['package_name']));
},
':package_description' => function () use (&$values) {
return $values['package_description'];
},
];
function read_from_console($prompt)
{
if (function_exists('readline')) {
$line = trim(readline($prompt));
if (!empty($line)) {
readline_add_history($line);
}
} else {
echo $prompt;
$line = trim(fgets(STDIN));
}
return $line;
}
function interpolate($text, $values)
{
if (!preg_match_all('/\{(\w+)\}/', $text, $m)) {
return $text;
}
foreach ($m[0] as $k => $str) {
$f = $m[1][$k];
$text = str_replace($str, $values[$f], $text);
}
return $text;
}
$modify = 'n';
do {
if ($modify == 'q') {
exit;
}
$values = [];
echo "----------------------------------------------------------------------\n";
echo "Please, provide the following information:\n";
echo "----------------------------------------------------------------------\n";
foreach ($fields as $f => $field) {
$default = isset($field[COL_DEFAULT]) ? interpolate($field[COL_DEFAULT], $values) : '';
$prompt = sprintf(
'%s%s%s: ',
$field[COL_DESCRIPTION],
$field[COL_HELP] ? ' (' . $field[COL_HELP] . ')' : '',
$field[COL_DEFAULT] !== '' ? ' [' . $default . ']' : ''
);
$values[$f] = read_from_console($prompt);
if (empty($values[$f])) {
$values[$f] = $default;
}
}
echo "\n";
echo "----------------------------------------------------------------------\n";
echo "Please, check that everything is correct:\n";
echo "----------------------------------------------------------------------\n";
foreach ($fields as $f => $field) {
echo $field[COL_DESCRIPTION] . ": $values[$f]\n";
}
echo "\n";
} while (($modify = strtolower(read_from_console('Modify files with these values? [y/N/q] '))) != 'y');
echo "\n";
$files = array_merge(
glob(__DIR__ . '/*.md'),
glob(__DIR__ . '/*.xml.dist'),
glob(__DIR__ . '/composer.json'),
glob(__DIR__ . '/src/Providers/*.php'),
glob(__DIR__ . '/tests/*.php')
);
foreach ($files as $f) {
$contents = file_get_contents($f);
foreach ($replacements as $str => $func) {
$contents = str_replace($str, $func(), $contents);
}
file_put_contents($f, $contents);
}
rename('./src/Providers/RenameMeServiceProvider.php', './src/Providers/' . $replacements[':package_ns']() . 'ServiceProvider.php');
rename('./tests/RenameMeTest.php', './tests/' . $replacements[':package_ns']() . 'Test.php');
echo "Done.\n";
echo "Now you should remove the file '" . basename(__FILE__) . "'.\n";

View File

@ -0,0 +1,32 @@
<?php
namespace Cerbero\:package_ns\Providers;
use Illuminate\Support\ServiceProvider;
/**
* The service provider.
*
*/
class :package_nsServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Execute logic after the service provider is booted.
*
* @return void
*/
public function boot()
{
//
}
}

26
tests/RenameMeTest.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace Cerbero\:package_ns;
use Cerbero\:package_ns\Providers\:package_nsServiceProvider;
use Orchestra\Testbench\TestCase;
/**
* The package test suite.
*
*/
class :package_nsTest extends TestCase
{
/**
* Retrieve the package providers.
*
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
{
return [
:package_nsServiceProvider::class,
];
}
}