From 6561e8e08c54d08d8cf51f9176ec265aea19cc59 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sun, 24 Jul 2022 23:22:03 +0200 Subject: [PATCH 01/10] build: delete unused files --- .travis.yml | 49 ------- CONDUCT.md | 73 ----------- README-ES.md | 309 --------------------------------------------- tests/Example.php | 72 ----------- tests/HookTest.php | 218 -------------------------------- 5 files changed, 721 deletions(-) delete mode 100644 .travis.yml delete mode 100644 CONDUCT.md delete mode 100644 README-ES.md delete mode 100644 tests/Example.php delete mode 100644 tests/HookTest.php diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d733f2c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,49 +0,0 @@ -language: php - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -dist: trusty - -branches: - only: - - master - -git: - depth: 5 - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - hhvm - - nightly - -matrix: - fast_finish: true - include: - - php: 7.1 - env: PHPCS=PSR2 - - allow_failures: - - php: nightly - -before_script: - - export PATH="./vendor/bin:$PATH" - - travis_retry composer self-update - - travis_retry composer install --no-interaction --prefer-source --dev - -script: - - phpunit - - | - if [[ "$PHPCS" ]] ; then - phpcs --standard=phpcs.xml $(find . -name '*.php') - phpmd src,tests text ./phpmd.xml - fi - -after_success: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/CONDUCT.md b/CONDUCT.md deleted file mode 100644 index 30f74c5..0000000 --- a/CONDUCT.md +++ /dev/null @@ -1,73 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making 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 [INSERT EMAIL ADDRESS]. 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 https://www.contributor-covenant.org/version/1/4/code-of-conduct.html - -[homepage]: https://www.contributor-covenant.org diff --git a/README-ES.md b/README-ES.md deleted file mode 100644 index d3be715..0000000 --- a/README-ES.md +++ /dev/null @@ -1,309 +0,0 @@ -# PHP Hook library - -[![Latest Stable Version](https://poser.pugx.org/josantonius/Hook/v/stable)](https://packagist.org/packages/josantonius/Hook) [![Latest Unstable Version](https://poser.pugx.org/josantonius/Hook/v/unstable)](https://packagist.org/packages/josantonius/Hook) [![License](https://poser.pugx.org/josantonius/Hook/license)](LICENSE) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/22a7928128324c3e8a7ca9ea4aa2abcb)](https://www.codacy.com/app/Josantonius/PHP-Hook?utm_source=github.com&utm_medium=referral&utm_content=Josantonius/PHP-Hook&utm_campaign=Badge_Grade) [![Total Downloads](https://poser.pugx.org/josantonius/Hook/downloads)](https://packagist.org/packages/josantonius/Hook) [![Travis](https://travis-ci.org/Josantonius/PHP-Hook.svg)](https://travis-ci.org/Josantonius/PHP-Hook) [![PSR2](https://img.shields.io/badge/PSR-2-1abc9c.svg)](http://www.php-fig.org/psr/psr-2/) [![PSR4](https://img.shields.io/badge/PSR-4-9b59b6.svg)](http://www.php-fig.org/psr/psr-4/) [![CodeCov](https://codecov.io/gh/Josantonius/PHP-Hook/branch/master/graph/badge.svg)](https://codecov.io/gh/Josantonius/PHP-Hook) - -[English version](README.md) - -Biblioteca para manejo de hooks. - ---- - -- [Requisitos](#requisitos) -- [Instalación](#instalación) -- [Métodos disponibles](#métodos-disponibles) -- [Cómo empezar](#cómo-empezar) -- [Uso](#uso) -- [Tests](#tests) -- [Tareas pendientes](#-tareas-pendientes) -- [Contribuir](#contribuir) -- [Repositorio](#repositorio) -- [Licencia](#licencia) -- [Copyright](#copyright) - ---- - -## Requisitos - -Esta clase es soportada por versiones de **PHP 5.6** o superiores y es compatible con versiones de **HHVM 3.0** o superiores. - -## Instalación - -La mejor forma de instalar esta extensión es a través de [Composer](http://getcomposer.org/download/). - -Para instalar **PHP Hook library**, simplemente escribe: - - $ composer require Josantonius/Hook - -El comando anterior sólo instalará los archivos necesarios, si prefieres **descargar todo el código fuente** puedes utilizar: - - $ composer require Josantonius/Hook --prefer-source - -También puedes **clonar el repositorio** completo con Git: - - $ git clone https://github.com/Josantonius/PHP-Hook.git - -O **instalarlo manualmente**: - -[Descargar Hook.php](https://raw.githubusercontent.com/Josantonius/PHP-Hook/master/src/Hook.php): - - $ wget https://raw.githubusercontent.com/Josantonius/PHP-Hook/master/src/Hook.php - -## Métodos disponibles - -Métodos disponibles en esta biblioteca: - -### - Obtener instancia: - -```php -Hook::getInstance(); -``` - -| Atributo | Descripción | Tipo | Requerido | Predeterminado -| --- | --- | --- | --- | --- | -| $id | ID único para multiples instancias. | string | No | '0' | - -**# Return** (object) → instancia - -### - Definir el nombre del método para usar el patrón singleton: - -```php -Hook::setSingletonName($method); -``` - -| Atributo | Descripción | Tipo | Requerido | Predeterminado -| --- | --- | --- | --- | --- | -| $method | Definir el nombre del método para usar el patrón singleton. | callable | No | | - -**# Return** (void) - -### - Agregar función personalizado al gancho de acción: - -```php -Hook::addAction($tag, $function, $priority, $args); -``` - -| Atributo | Descripción | Tipo | Requerido | Predeterminado -| --- | --- | --- | --- | --- | -| $tag | Nombre del gancho de acción. | string | Sí | | -| $function | Función donde insertar el gancho de acción. | callable | Sí | | -| $priority | Orden en que se ejecuta la acción. | int | No | 8 | -| $args | Número de argumentos aceptados. | int | No | 0 | - -**# Return** (boolean) - -### - Agregar acciones desde array: - -```php -Hook::addActions($actions); -``` - -| Atributo | Descripción | Tipo | Requerido | Predeterminado -| --- | --- | --- | --- | --- | -| $actions | Acciones | array | Sí | | - -**# Return** (boolean) - -### - Ejecutar todos los ganchos de determinada acción: - -Por defecto, buscará el método `getInstance()` para usar el patrón singleton y crear una única instancia de la clase. Si no existe, creará un nuevo objeto. - -```php -Hook::doAction($tag, $args, $remove); -``` - -| Atributo | Descripción | Tipo | Requerido | Predeterminado -| --- | --- | --- | --- | --- | -| $tag | Nombre del gancho de acción. | string | Sí | | -| $args | Argumentos opcionales. | mixed | No | array() | -| $remove | Eliminar gancho después de ejecutar acciones | boolean | No | true | - -**# Return** (mixed|false) → salida de la última acción o falso - -### - Obtener el gancho de acción actual: - -```php -Hook::current(); -``` - -**# Return** (string|false) → gancho de acción actual - -### - Comprobar si existe determinado gancho de acción: - -```php -Hook::isAction($tag); -``` - -| Atributo | Descripción | Tipo | Requerido | Predeterminado -| --- | --- | --- | --- | --- | -| $tag | Nombre del gancho de acción | string | Sí | | - -**# Return** (boolean) - -## Cómo empezar - -Para utilizar esta biblioteca, simplemente: - -Para utilizar esta biblioteca con **Composer**: - -```php -require __DIR__ . '/vendor/autoload.php'; - -use Josantonius\Hook\Hook; -``` - -Si la instalaste **manualmente**, utiliza: - -```php -require_once __DIR__ . '/Hook.php'; - -use Josantonius\Hook\Hook; -``` - -## Uso - -### - Agregar gancho de acción: - -```php -Hook::addAction('css', ['Josantonius\Hook\Test\Example', 'css']); -``` - -### - Agregar gancho de acción con prioridad: - -```php -Hook::addAction('js', ['Josantonius\Hook\Test\Example', 'js'], 1); -``` - -### - Agregar gancho de acción con prioridad y número de argumentos: - -```php -$instance = new Example; - -Hook::addAction('meta', [$instance, 'meta'], 2, 1); -``` - -### - Agregar gancho de acción y definir patrón singleton: - -```php -Hook::setSingletonName('singletonMethod'); - -$instance = call_user_func( - 'Josantonius\Hook\Test\Example::singletonMethod' -); - -Hook::addAction('article', [$instance, 'article'], 3, 0); -``` - -### - Agregar múltiples ganchos de acción: - -```php -$instance = new Example; - -Hook::addActions([ - ['after-body', [$instance, 'afterBody'], 4, 0], - ['footer', [$instance, 'footer'], 5, 0], -]); -``` - -### - Agregar múltiples ganchos de acción y definir patrón singleton: - -```php -Hook::setSingletonName('singletonMethod'); - -$instance = call_user_func( - 'Josantonius\Hook\Test\Example::singletonMethod' -); - -Hook::addActions([ - ['slide', [$instance, 'slide'], 6, 0], - ['form', [$instance, 'form'], 7, 2], -]); -``` - -### - Comprobar si una acción ha sido definida: - -```php -Hook::setSingletonName('singletonMethod'); - -Hook::isAction('meta'); -``` - -### - Ejecutar ganchos de acción: - -```php -Hook::doAction('css'); -Hook::doAction('js'); -Hook::doAction('after-body'); -Hook::doAction('article'); -Hook::doAction('footer'); -``` - -### - Ejecutar ganchos de acción con argumentos: - -```php -Hook::doAction('meta', 'The title'); -Hook::doAction('form', ['input', 'select']); -``` - -## Tests - -Para ejecutar las [pruebas](tests) necesitarás [Composer](http://getcomposer.org/download/) y seguir los siguientes pasos: - - $ git clone https://github.com/Josantonius/PHP-Hook.git - - $ cd PHP-Hook - - $ composer install - -Ejecutar pruebas unitarias con [PHPUnit](https://phpunit.de/): - - $ composer phpunit - -Ejecutar pruebas de estándares de código [PSR2](http://www.php-fig.org/psr/psr-2/) con [PHPCS](https://github.com/squizlabs/PHP_CodeSniffer): - - $ composer phpcs - -Ejecutar pruebas con [PHP Mess Detector](https://phpmd.org/) para detectar inconsistencias en el estilo de codificación: - - $ composer phpmd - -Ejecutar todas las pruebas anteriores: - - $ composer tests - -## ☑ Tareas pendientes - -- [ ] Añadir nueva funcionalidad. -- [ ] Mejorar pruebas. -- [ ] Mejorar documentación. -- [ ] Refactorizar código para las reglas de estilo de código deshabilitadas. Ver [phpmd.xml](phpmd.xml) y [.php_cs.dist](.php_cs.dist). - -## Contribuir - -Si deseas colaborar, puedes echar un vistazo a la lista de -[issues](https://github.com/Josantonius/PHP-Hook/issues) o [tareas pendientes](#-tareas-pendientes). - -**Pull requests** - -* [Fork and clone](https://help.github.com/articles/fork-a-repo). -* Ejecuta el comando `composer install` para instalar dependencias. - Esto también instalará las [dependencias de desarrollo](https://getcomposer.org/doc/03-cli.md#install). -* Ejecuta el comando `composer fix` para estandarizar el código. -* Ejecuta las [pruebas](#tests). -* Crea una nueva rama (**branch**), **commit**, **push** y envíame un - [pull request](https://help.github.com/articles/using-pull-requests). - -## Repositorio - -La estructura de archivos de este repositorio se creó con [PHP-Skeleton](https://github.com/Josantonius/PHP-Skeleton). - -## Licencia - -Este proyecto está licenciado bajo **licencia MIT**. Consulta el archivo [LICENSE](LICENSE) para más información. - -## Copyright - -2017 - 2018 Josantonius, [josantonius.com](https://josantonius.com/) - -Si te ha resultado útil, házmelo saber :wink: - -Puedes contactarme en [Twitter](https://twitter.com/Josantonius) o a través de mi [correo electrónico](mailto:hello@josantonius.com). \ No newline at end of file diff --git a/tests/Example.php b/tests/Example.php deleted file mode 100644 index 987102f..0000000 --- a/tests/Example.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @copyright 2017 - 2018 (c) Josantonius - PHP-Hook - * @license https://opensource.org/licenses/MIT - The MIT License (MIT) - * @link https://github.com/Josantonius/PHP-Hook - * @since 1.0.8 - */ -namespace Josantonius\Hook; - -/** - * Example class. - */ -class Example -{ - /** - * Class instance. - */ - private static $singleton; - - public static function getInstance() - { - return self::$singleton = new self; - } - - public static function singletonMethod() - { - return self::getInstance(); - } - - public function meta($title) - { - return 'meta-hook'; - } - - public function css() - { - return 'css-hook'; - } - - public function js() - { - return 'js-hook'; - } - - public function afterBody() - { - return 'after-hook'; - } - - public function slide() - { - return Hook::current(); - } - - public function form($input, $select) - { - return 'form-hook'; - } - - public function article() - { - return 'article-hook'; - } - - public function footer() - { - return 'footer-hook'; - } -} diff --git a/tests/HookTest.php b/tests/HookTest.php deleted file mode 100644 index a95793d..0000000 --- a/tests/HookTest.php +++ /dev/null @@ -1,218 +0,0 @@ - - * @copyright 2017 - 2018 (c) Josantonius - PHP-Hook - * @license https://opensource.org/licenses/MIT - The MIT License (MIT) - * @link https://github.com/Josantonius/PHP-Hook - * @since 1.0.6 - */ -namespace Josantonius\Hook; - -use PHPUnit\Framework\TestCase; - -/** - * Tests class for Hook library. - */ -final class HookTest extends TestCase -{ - /** - * Hook instance. - * - * @since 1.0.9 - * - * @var object - */ - protected $Hook; - - /** - * Set up. - * - * @since 1.0.9 - */ - public function setUp() - { - parent::setUp(); - - $this->Hook = new Hook; - } - - /** - * Check if it is an instance of Hook. - * - * @since 1.0.9 - */ - public function testIsInstanceOfHook() - { - $this->assertInstanceOf('Josantonius\Hook\Hook', $this->Hook); - } - - /** - * Add action hook. - */ - public function testAddAction() - { - $hook = $this->Hook; - - $this->assertTrue( - $hook::addAction('css', ['Josantonius\Hook\Example', 'css']) - ); - } - - /** - * Add action hook with priority. - */ - public function testAddActionWithPriority() - { - $hook = $this->Hook; - - $this->assertTrue( - $hook::addAction('js', ['Josantonius\Hook\Example', 'js'], 1) - ); - } - - /** - * Add action hook with priority and arguments number. - */ - public function testAddActionWithPriorityAndArguments() - { - $hook = $this->Hook; - - $instance = new Example; - - $this->assertTrue( - $hook::addAction('meta', [$instance, 'meta'], 2, 1) - ); - } - - /** - * Add action hook and set singleton method. - */ - public function testAddActionWithCustomSingletonMethod() - { - $hook = $this->Hook; - - $hook::setSingletonName('singletonMethod'); - - $instance = call_user_func( - 'Josantonius\Hook\Example::singletonMethod' - ); - - $this->assertTrue( - $hook::addAction('article', [$instance, 'article'], 3, 0) - ); - } - - /** - * Add multiple action hooks. - */ - public function testAddMultipleActions() - { - $hook = $this->Hook; - - $instance = new Example; - - $this->assertTrue( - $hook::addActions([ - ['after-body', [$instance, 'afterBody'], 4, 0], - ['footer', [$instance, 'footer'], 5, 0], - ]) - ); - } - - /** - * Add multiple action hooks and set singleton method. - */ - public function testAddMultipleActionsWithCustomSingletonMethod() - { - $hook = $this->Hook; - - $hook::setSingletonName('singletonMethod'); - - $instance = call_user_func( - 'Josantonius\Hook\Example::singletonMethod' - ); - - $this->assertTrue( - $hook::addActions([ - ['slide', [$instance, 'slide'], 6, 0], - ['form', [$instance, 'form'], 7, 2], - ]) - ); - } - - /** - * Check if is action. - * - * @since 1.0.7 - */ - public function testIsAction() - { - $hook = $this->Hook; - - $this->assertTrue( - $hook::isAction('meta') - ); - - $this->assertTrue( - $hook::isAction('form') - ); - } - - /** - * Check if isn`t action. - * - * @since 1.0.7 - */ - public function testIsNotAction() - { - $hook = $this->Hook; - - $this->assertFalse( - $hook::isAction('unknown') - ); - } - - /** - * Execute action hooks. - */ - public function testDoActions() - { - $hook = $this->Hook; - - $this->assertContains('css-hook', $hook::doAction('css')); - $this->assertContains('js-hook', $hook::doAction('js')); - $this->assertContains('after-hook', $hook::doAction('after-body')); - $this->assertContains('article-hook', $hook::doAction('article')); - $this->assertContains('footer-hook', $hook::doAction('footer')); - } - - /** - * Execute action hooks and get current hook. - */ - public function testDoActionAndGetCurrentHook() - { - $hook = $this->Hook; - - $this->assertContains('slide', $hook::doAction('slide')); - } - - /** - * Execute action hook with arguments. - */ - public function testDoActionsWithArguments() - { - $hook = $this->Hook; - - $this->assertContains( - 'meta-hook', - $hook::doAction('meta', 'The title') - ); - - $this->assertContains( - 'form-hook', - $hook::doAction('form', ['input', 'select']) - ); - } -} From 8535e085f965f8a31f4d5a8e474a510a003e0d39 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Fri, 29 Jul 2022 23:53:50 +0200 Subject: [PATCH 02/10] build: add scripts and normalize Added scripts, normalized the archive, upgrade to php 8.1, and removed unused packages. Closes #3 --- composer.json | 57 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) mode change 100644 => 100755 composer.json diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 35e61fa..9c27923 --- a/composer.json +++ b/composer.json @@ -1,41 +1,36 @@ { - "name": "josantonius/hook", - "type": "library", + "name": "josantonius/hook", "description": "Library for handling hooks.", + "license": "MIT", + "type": "library", "keywords": [ - "Hook", - "Actions", - "Action Hooks", - "HHVM", - "PHP" + "hook", + "actions", + "action-hooks", + "php" ], - "license": "MIT", "authors": [ { - "name": "Josantonius", - "email": "hello@josantonius.com", - "homepage": "https://josantonius.com", - "role": "Developer" + "name": "Josantonius", + "email": "hello@josantonius.dev", + "homepage": "https://josantonius.dev", + "role": "Developer" } ], "support": { "issues": "https://github.com/josantonius/php-hook/issues", - "forum": "http://stackoverflow.com/tags/josantonius/php-hook", - "source": "https://github.com/josantonius/php-hook" - }, - "config": { - "preferred-install": "dist" + "source": "https://github.com/josantonius/php-hook", + "discussions": "https://github.com/josantonius/php-hook/discussions" }, - "minimum-stability": "stable", "require": { - "php": "^5.6 || ^7.0" + "php": "^8.0" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0", - "squizlabs/php_codesniffer": "^3.0", - "friendsofphp/php-cs-fixer": "^2.3 || ^2.8", - "phpmd/phpmd": "^2.6" + "phpmd/phpmd": "^2.6", + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.7" }, + "minimum-stability": "stable", "autoload": { "psr-4": { "Josantonius\\Hook\\": "src/" @@ -43,22 +38,26 @@ }, "autoload-dev": { "psr-4": { - "Josantonius\\Hook\\": "tests/" + "Josantonius\\Hook\\Tests\\": "tests/" } }, + "config": { + "preferred-install": "dist" + }, "extra": { "branch-alias": { "dev-master": "1.0-dev" } }, "scripts": { - "phpunit": "vendor/bin/phpunit --colors=always;", - "phpcs": "vendor/bin/phpcs --standard=phpcs.xml $(find . -name '*.php');", - "phpmd": "vendor/bin/phpmd src,tests text ./phpmd.xml", + "coverage": "vendor/bin/phpunit --coverage-clover=coverage.xml", "fix": [ - "vendor/bin/php-cs-fixer fix -v", "vendor/bin/phpcbf src tests" ], + "htmlCoverage": "vendor/bin/phpunit --coverage-html coverage", + "phpcs": "vendor/bin/phpcs --standard=phpcs.xml $(find . -name '*.php');", + "phpmd": "vendor/bin/phpmd src,tests text ./phpmd.xml", + "phpunit": "vendor/bin/phpunit --colors=always;", "tests": [ "clear", "@phpmd", @@ -66,4 +65,4 @@ "@phpunit" ] } -} +} \ No newline at end of file From d1ad0c313bb532559c10ada6318905bc870db3a7 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sat, 30 Jul 2022 02:19:13 +0200 Subject: [PATCH 03/10] build: update changes in .git* files Update latest changes in .gitattributes and .gitignore files. Closes #3 --- .gitattributes | 8 ++------ .gitignore | 14 +++++++------- 2 files changed, 9 insertions(+), 13 deletions(-) mode change 100644 => 100755 .gitattributes mode change 100644 => 100755 .gitignore diff --git a/.gitattributes b/.gitattributes old mode 100644 new mode 100755 index 58ff123..2713ee2 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,9 @@ +/.github export-ignore /tests export-ignore CHANGELOG.md export-ignore -README.md export-ignore -README-ES.md export-ignore phpcs.xml export-ignore phpunit.xml export-ignore phpmd.xml export-ignore -.travis.yml export-ignore -.editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.php_cs.dist export-ignore -CONDUCT.md export-ignore \ No newline at end of file +.php-cs-fixer.dist.php export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index b5216cd..f6e198e --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,12 @@ -.git*/ vendor/ -docs/*.pyc -docs/_build -build/artifacts/ +coverage/ +.vscode/ composer.phar composer.lock composer-test.lock phpcbf-fixed.diff -.idea -.DS_STORE -.php_cs.cache \ No newline at end of file +.php_cs.cache +php-hook.code-workspace +.repository.md +.phpunit.result.cache +coverage.xml \ No newline at end of file From 4c155d8e11abd40ae95fd8637aec76052e6e0165 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sat, 30 Jul 2022 02:20:51 +0200 Subject: [PATCH 04/10] build: delete unused files Closes #3 --- .editorconfig | 12 ----- .php_cs.dist | 120 -------------------------------------------------- 2 files changed, 132 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .php_cs.dist diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index d672f69..0000000 --- a/.editorconfig +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 6735b7d..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,120 +0,0 @@ -setRiskyAllowed(true) - ->setRules(array( - '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false], - 'blank_line_after_opening_tag' => true, - 'blank_line_after_namespace' => false, - 'blank_line_before_return' => true, - 'cast_spaces' => true, -// 'class_keyword_remove' => true, - 'combine_consecutive_unsets' => true, - 'concat_space' => ['spacing' => 'one'], - 'declare_equal_normalize' => true, - 'declare_strict_types' => false, - 'dir_constant' => true, - 'ereg_to_preg' => true, - 'function_typehint_space' => true, -// 'general_phpdoc_annotation_remove' => ['author', 'category', 'package', 'copyright', 'version'], - 'hash_to_slash_comment' => true, - 'heredoc_to_nowdoc' => true, - 'include' => true, - 'indentation_type' => true, -// 'is_null' => ['use_yoda_style' => false], - 'linebreak_after_opening_tag' => true, - 'lowercase_cast' => true, -// 'mb_str_functions' => true, - 'method_separation' => true, - 'modernize_types_casting' => true, - 'native_function_casing' => true, -// 'native_function_invocation' => true, - 'new_with_braces' => false, // - 'no_alias_functions' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'useTrait'], - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => ['use' => 'echo'], - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_multiline_whitespace_before_semicolons' => true, - 'no_php4_constructor' => true, - 'no_short_bool_cast' => true, - 'no_short_echo_tag' => false, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => true, - 'no_unreachable_default_argument_value' => true, - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'not_operator_with_space' => false, - 'not_operator_with_successor_space' => true, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_construct' => true, - 'php_unit_dedicate_assert' => true, - 'php_unit_fqcn_annotation' => true, - 'php_unit_strict' => true, -// 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_align' => true, - 'phpdoc_annotation_without_dot' => true, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'], - 'phpdoc_no_empty_return' => true, - 'phpdoc_no_package' => true, -// 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_order' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => false, - 'phpdoc_single_line_var_spacing' => true, -// 'phpdoc_summary' => true, - 'phpdoc_to_comment' => true, - 'phpdoc_trim' => true, - 'phpdoc_types' => true, - 'phpdoc_var_without_name' => true, - 'pow_to_exponentiation' => true, -// 'pre_increment' => true, - 'protected_to_private' => true, - 'psr0' => true, - 'psr4' => true, - 'random_api_migration' => true, - 'return_type_declaration' => ['space_before' => 'one'], - 'self_accessor' => true, - 'short_scalar_cast' => true, -// 'silenced_deprecation_error' => true, -// 'simplified_null_return' => true, - 'single_blank_line_before_namespace' => false, - 'single_quote' => true, - 'space_after_semicolon' => true, - 'standardize_not_equals' => true, -// 'strict_comparison' => true, - 'ternary_operator_spaces' => true, - 'strict_param' => true, - 'ternary_to_null_coalescing' => false, -// 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true - )) - ->setFinder( - PhpCsFixer\Finder::create() - ->in(__DIR__) - )->setLineEnding("\n"); From d4f325f61aef220e161cd190d94bb3c55db920af Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sat, 30 Jul 2022 02:22:04 +0200 Subject: [PATCH 05/10] build: change rules Rules were modified. Closes #3 --- phpcs.xml | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++--- phpmd.xml | 104 +++++++++++++++++----------- 2 files changed, 255 insertions(+), 51 deletions(-) mode change 100644 => 100755 phpcs.xml mode change 100644 => 100755 phpmd.xml diff --git a/phpcs.xml b/phpcs.xml old mode 100644 new mode 100755 index 32363c5..97e64cc --- a/phpcs.xml +++ b/phpcs.xml @@ -1,17 +1,199 @@ - + + + Coding standard. + - - PHP Coding Standards + - - - - - - node_modules + - vendor + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + + + error + Method name "%s" must not be prefixed with an underscore to indicate visibility + + + + + + + + + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + node_modules + vendor \ No newline at end of file diff --git a/phpmd.xml b/phpmd.xml old mode 100644 new mode 100755 index 005d852..b4fc6a8 --- a/phpmd.xml +++ b/phpmd.xml @@ -1,45 +1,67 @@ - - - - - - - - - - - - - - - - - + + + Coding standard. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From a74939065b806f2b4ef3752b64fa7db65eff17d7 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sat, 30 Jul 2022 02:23:16 +0200 Subject: [PATCH 06/10] build: update for version 9 Closes #3 --- phpunit.xml | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) mode change 100644 => 100755 phpunit.xml diff --git a/phpunit.xml b/phpunit.xml old mode 100644 new mode 100755 index 8a27461..94d16dd --- a/phpunit.xml +++ b/phpunit.xml @@ -1,26 +1,23 @@ - - - - - - tests - - - - - - src - - - + + + + src + + + + + tests + + From 4171f5f789469076bdd5f0401e0e5bca0c0df9e2 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sat, 30 Jul 2022 02:24:06 +0200 Subject: [PATCH 07/10] ci: replace travis with github actions Replace Travis with GitHub Actions for continuous integration. Closes #3 --- .github/workflows/ci.yml | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100755 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100755 index 0000000..e235a71 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,92 @@ +name: CI + +on: + push: + branches: [ "main", "develop" ] + pull_request: + branches: [ "main", "develop" ] + +permissions: + contents: read + +jobs: + + code-style: + runs-on: 'ubuntu-latest' + name: 'Coding style' + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '8.1' + coverage: 'none' + tools: 'composer:v2, composer-normalize' + + - name: 'Install dependencies' + run: | + composer install --no-interaction --no-progress --ansi + + - name: 'Check PHP code' + run: | + composer phpcs + composer phpmd + + - name: 'Check composer.json' + run: 'composer-normalize --diff --dry-run --no-update-lock' + if: 'always()' + + phpunit: + runs-on: ${{ matrix.system }} + name: 'PHPUnit (PHP ${{ matrix.php }} - ${{ matrix.system }})' + strategy: + matrix: + system: ['ubuntu-latest'] + php: + - '8.1' + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php }}' + coverage: 'none' + tools: 'composer:v2' + + - name: 'Install dependencies' + run: | + composer install --no-interaction --no-progress --ansi + + - name: 'Run unit tests' + run: | + composer phpunit + + code-coverage: + runs-on: 'ubuntu-latest' + name: 'Code Coverage' + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '8.1' + tools: 'composer:v2' + + - name: 'Install dependencies' + run: | + composer install --no-interaction --no-progress --ansi + + - name: 'Run code coverage' + run: | + composer coverage + + - name: Send code coverage report to Codecov.io + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From be22bcb922e1e4a56eb43ebaab44e8bbce181dc5 Mon Sep 17 00:00:00 2001 From: Josantonius Date: Sat, 30 Jul 2022 02:24:44 +0200 Subject: [PATCH 08/10] docs: improve documentation Add and modify new document files. Closes #3 --- .github/CODE_OF_CONDUCT.md | 131 ++++++++ .github/CONTRIBUTING.md | 314 ++++++++++++++++++ .github/FUNDING.yml | 2 + .github/lang/es-ES/CODE_OF_CONDUCT.md | 139 ++++++++ .github/lang/es-ES/CONTRIBUTING.md | 319 ++++++++++++++++++ .github/lang/es-ES/LICENSE | 23 ++ .github/lang/es-ES/README.md | 447 ++++++++++++++++++++++++++ LICENSE | 2 +- README.md | 428 +++++++++++++++--------- 9 files changed, 1658 insertions(+), 147 deletions(-) create mode 100755 .github/CODE_OF_CONDUCT.md create mode 100755 .github/CONTRIBUTING.md create mode 100755 .github/FUNDING.yml create mode 100755 .github/lang/es-ES/CODE_OF_CONDUCT.md create mode 100755 .github/lang/es-ES/CONTRIBUTING.md create mode 100755 .github/lang/es-ES/LICENSE create mode 100755 .github/lang/es-ES/README.md mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100755 index 0000000..5d1569c --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,131 @@ +# Contributor Covenant Code of Conduct + +- [Our Pledge](#our-pledge) +- [Our Standards](#our-standards) +- [Enforcement Responsibilities](#enforcement-responsibilities) +- [Scope](#scope) +- [Enforcement](#enforcement) +- [Enforcement Guidelines](#enforcement-guidelines) + - [1. Correction](#1-correction) + - [2. Warning](#2-warning) + - [3. Temporary Ban](#3-temporary-ban) + - [4. Permanent Ban](#4-permanent-ban) +- [Attribution](#attribution) + +--- + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +- Demonstrating empathy and kindness toward other people. +- Being respectful of differing opinions, viewpoints, and experiences. +- Giving and gracefully accepting constructive feedback. +- Accepting responsibility and apologizing to those affected by our mistakes. +- Focusing on what is best for the overall community. + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery. +- Sexual attention or advances of any kind. +- Trolling, insulting or derogatory comments. +- Personal or political attacks. +- Public or private harassment. +- Publishing others' private information without their explicit permission. +- Any conduct considered inappropriate in a professional environment. + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders 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, and will communicate reasons for +moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail +address, posting via an official social media account, or acting as an +appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[hello@josantonius.dev](mailto:hello@josantonius.dev). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the +[Contributor Covenant](https://www.contributor-covenant.org/), +version 2.1, available at +. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100755 index 0000000..2f9e354 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,314 @@ +# Contributing + +We would love for you to contribute to this project and help make it even better! +As a contributor, here are the guidelines we would like you to follow: + +--- + +- [Code of Conduct](#code-of-conduct) +- [Got a Question, Problem or Idea?](#got-a-question-problem-or-idea) +- [Add or Improve a Feature?](#add-or-improve-a-feature) +- [Found a Bug?](#found-a-bug) +- [Submitting an Issue](#submitting-an-issue) +- [Submitting a Pull Request](#submitting-a-pull-request) + - [After Your Pull Request is Merged](#after-your-pull-request-is-merged) +- [Coding Rules](#coding-rules) +- [Commit Message Conventions](#commit-message-conventions) + - [Commit Message Header](#commit-message-header) + - [Type](#type) + - [Scope](#scope) + - [Summary](#summary) + - [Commit Message Body](#commit-message-body) + - [Commit Message Footer](#commit-message-footer) + +--- + +## Code of Conduct + +Help us keep this project open and inclusive. +Please read and follow our [Code of Conduct](CODE_OF_CONDUCT.md). + +## Got a Question, Problem or Idea? + +Start a [new discussion](https://github.com/josantonius/php-hook/discussions/new) and select the +appropriate category for it: + +- `General`: Anything that is relevant to the project. +- `Ideas`: Ideas to change/improve the project or propose new features. +- `Polls`: Polls with multi options for the community to vote for and discuss. +- `Q&A`: Questions for the community to answer, in a question/answer format. +- `Show and tell`: Creations, experiments, or tests relevant to the project. + +## Add or Improve a Feature? + +- For a **Major Feature**, +first [open a new discussion](https://github.com/josantonius/php-hook/discussions/new) in the +`Ideas` category and outline your proposal so that it can be discussed. This will also allow us to +better coordinate our efforts, prevent duplication of work, and help you to craft the change so that +it is successfully accepted into the project. + +- **Small Features** can be crafted and directly +[submitted as a Pull Request](#submitting-a-pull-request). + +## Found a Bug? + +If you find a bug in the source code, you can help us by +[submitting an issue](#submitting-an-issue) to our +[repository](https://github.com/josantonius/php-hook). Even better, you can +[submit a Pull Request](#submitting-a-pull-request) with a fix. + +## Submitting an Issue + +Issues are very valuable for any project. + +Great bug reports tend to have: + +- A quick summary and/or background. +- Steps to reproduce. +- Be specific. +- Give sample code if you can. +- What you expected would happen. +- What actually happens. +- Notes; why you think this might be happening, tests that didn't work... + +You can file new issues by filling out our +[new issue form](https://github.com/josantonius/php-hook/issues/new). + +## Submitting a Pull Request + +Pull requests are a great way to put your ideas into this project or simply fix something. + +Before you submit your Pull Request (PR) consider the following guidelines: + +1. Search [GitHub](https://github.com/josantonius/php-hook/pulls) for an open or closed PR that +relates to your submission. You don't want to duplicate effort. + +1. [Fork](https://github.com/josantonius/php-hook/fork) the repository to your own GitHub account. + +1. Clone the repository to your machine. + +1. Go to the cloned repository. + + ```shell + cd php-hook + ``` + +1. Create a branch from the `main branch` with a succinct but descriptive name. + + ```shell + git checkout -b descriptive-name main + ``` + +1. Make your changes in the new git branch, including appropriate test cases. + +1. Follow our [Coding Rules](#coding-rules). + +1. Run the full repository test suite. + + ```shell + composer tests + ``` + +1. Commit your changes using a descriptive commit message that follows our + [commit message conventions](#commit-message-conventions). + + ```shell + git commit -a + ``` + + **The optional commit `-a` command line option will automatically "add" and "rm" edited files.** + +1. Push your branch to GitHub: + + ```shell + git push origin descriptive-name + ``` + +1. In GitHub, send a [pull request](https://github.com/josantonius/php-hook/compare/main..) +to `php-hook:main`. + +- If we suggest changes then: + - Make the required updates. + - Re-run the test suites to ensure tests are still passing. + - Rebase your branch and force push to your GitHub repository (this will update your Pull Request): + + ```shell + git rebase main -i + git push -f + ``` + +That's it! Thank you for your contribution! + +### After Your Pull Request is Merged + +After your pull request is merged, you can safely delete your branch and pull the changes from the +`main` (upstream) repository: + +- Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows: + + ```shell + git push origin --delete descriptive-name + ``` + +- Check out the `main` branch: + + ```shell + git checkout main -f + ``` + +- Delete the local branch: + + ```shell + git branch -D descriptive-name + ``` + +- Update your ´main´ branch with the latest upstream version: + + ```shell + git pull --ff upstream main + ``` + +## Coding Rules + +To ensure consistency throughout the source code, keep these rules in mind as you are working: + +- All features or bug fixes **must be tested** by one or more specs (unit-tests). + + You can use the following command to check the tests: + + ```shell + composer phpunit + ``` + +- All new feature **must be documented** in the `README.md` file. + +- We use `PHP CodeSniffer` and `PHP Mess Detector` to define our code standards. + + You can use the following commands to check the status of your code: + + ```shell + composer phpcs + ``` + + ```shell + composer phpmd + ``` + + You can use the following command to automatically format errors found with `PHP CodeSniffer`: + + ```shell + composer fix + ``` + +## Commit Message Conventions + +We have very precise rules over how our Git commit messages must be formatted. +This format leads to **easier to read commit history**. + +Each commit message consists of a **header**, a **body**, and a **footer**. + +```none +
+ + + +