Skip to content

Commit

Permalink
Merge pull request #5 from josantonius/release/v2.0.3
Browse files Browse the repository at this point in the history
Release/v2.0.3
  • Loading branch information
josantonius authored Sep 29, 2022
2 parents 9ac448c + 2c87365 commit 68d16fd
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 158 deletions.
50 changes: 25 additions & 25 deletions .github/lang/es-ES/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Biblioteca para manejo de hooks en PHP.

## Requisitos

Esta biblioteca es compatible con las versiones de PHP: 8.1.
- Sistema operativo: Linux | Windows.

- Versiones de PHP: 8.1 | 8.2.

## Instalación

Expand Down Expand Up @@ -62,44 +64,40 @@ git clone https://github.com/josantonius/php-hook.git

### Instancia Action

```php
use Josantonius\Hook\Action;
```
`Josantonius\Hook\Action`

Obtener el nivel de prioridad de la acción:

```php
$action->getPriority(): int
public function getPriority(): int;
```

Obtener el resultado de la llamada a la acción:

```php
$action->getResult(): mixed
public function getResult(): mixed;
```

Comprueba si la acción se realiza solo una vez:

```php
$action->isOnce(): bool
public function isOnce(): bool;
```

Comprueba si la acción ya se ha realizado:

```php
$action->wasDone(): bool
public function wasDone(): bool;
```

### Clase Hook

```php
use Josantonius\Hook\Hook;
```
`Josantonius\Hook\Hook`

Registrar nuevo gancho:

```php
$hook = new Hook(string $name);
public function __construct(private string $name);
```

Agregar acción en el gancho:
Expand All @@ -112,7 +110,7 @@ Agregar acción en el gancho:
*
* @return Action Acción agregada.
*/
$hook->addAction(callable $callback, int $priority = Priority::NORMAL): Action
public function addAction(callable $callback, int $priority = Priority::NORMAL): Action;
```

Agregar acción en el gancho una vez:
Expand All @@ -126,7 +124,7 @@ Agregar acción en el gancho una vez:
*
* @return Action Acción agregada.
*/
$hook->addActionOnce(callable $callback, int $priority = Priority::NORMAL): Action
public function addActionOnce(callable $callback, int $priority = Priority::NORMAL): Action;
```

Ejecutar las acciones agregadas al gancho:
Expand All @@ -138,7 +136,7 @@ Ejecutar las acciones agregadas al gancho:
*
* @return Action[] Acciones hechas.
*/
$hook->doActions(mixed ...$arguments): Action[]
public function doActions(mixed ...$arguments): array;
```

Comprueba si el gancho tiene acciones:
Expand All @@ -148,7 +146,7 @@ Comprueba si el gancho tiene acciones:
* Verdadero si el gancho tiene alguna acción incluso si la acción
* se ha hecho antes (acciones recurrentes creadas con addAction).
*/
$hook->hasActions(): bool
public function hasActions(): bool;
```

Comprueba si el gancho tiene acciones sin realizar:
Expand All @@ -157,7 +155,7 @@ Comprueba si el gancho tiene acciones sin realizar:
/**
* Verdadero si el gancho tiene alguna acción sin realizar.
*/
$hook->hasUndoneActions(): bool
public function hasUndoneActions(): bool;
```

Comprueba si las acciones se han realizado al menos una vez:
Expand All @@ -166,25 +164,27 @@ Comprueba si las acciones se han realizado al menos una vez:
/**
* Si doActions fue ejecutado al menos una vez.
*/
$hook->hasDoneActions(): bool
public function hasDoneActions(): bool;
```

Obtener el nombre del hook:

```php
$hook->getName(): string
public function getName(): string;
```

### Priority Class
### Clase Priority

`Josantonius\Hook\Priority`

Constantes disponibles:

```php
Priority::HIGHEST; // 50
Priority::HIGH; // 100
Priority::NORMAL; // 150
Priority::LOW; // 200
Priority::LOWEST; // 250
public const HIGHEST = 50;
public const HIGH = 100;
public const NORMAL = 150;
public const LOW = 200;
public const LOWEST = 250;
```

## Excepciones utilizadas
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ jobs:
name: 'PHPUnit (PHP ${{ matrix.php }} - ${{ matrix.system }})'
strategy:
matrix:
system: ['ubuntu-latest']
system: ['ubuntu-latest', 'windows-latest']
php:
- '8.1'
- '8.2'
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# CHANGELOG

## [v2.0.3](https://github.com/josantonius/php-hook/releases/tag/v2.0.3) (2022-09-29)

* The notation type in the test function names has been changed from camel to snake case for readability.

* Functions were added to document the methods and avoid confusion.

* Disabled the ´CamelCaseMethodName´ rule in ´phpmd.xml´ to avoid warnings about function names in tests.

* The alignment of the asterisks in the comments has been fixed.

* Tests for Windows have been added.

* Tests for PHP 8.2 have been added.

## [v2.0.2](https://github.com/josantonius/php-hook/releases/tag/v2.0.2) (2022-08-11)

* Improved documentation.
Expand Down
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ Library for handling hooks in PHP.
- [TODO](#todo)
- [Changelog](#changelog)
- [Contribution](#contribution)
- [Sponsor](#Sponsor)
- [Sponsor](#sponsor)
- [License](#license)

---

## Requirements

This library is compatible with the PHP versions: 8.1.
- Operating System: Linux | Windows.

- PHP versions: 8.1 | 8.2.

## Installation

Expand Down Expand Up @@ -63,44 +65,40 @@ git clone https://github.com/josantonius/php-hook.git

### Action Instance

```php
use Josantonius\Hook\Action;
```
`Josantonius\Hook\Action`

Gets action priority:

```php
$action->getPriority(): int
public function getPriority(): int;
```

Gets action callback result:

```php
$action->getResult(): mixed
public function getResult(): mixed;
```

Checks if the action is done once:

```php
$action->isOnce(): bool
public function isOnce(): bool;
```

Checks if the action has already been done:

```php
$action->wasDone(): bool
public function wasDone(): bool;
```

### Hook Class

```php
use Josantonius\Hook\Hook;
```
`Josantonius\Hook\Hook`

Register new hook:

```php
$hook = new Hook(string $name);
public function __construct(private string $name);
```

Adds action on the hook:
Expand All @@ -113,7 +111,7 @@ Adds action on the hook:
*
* @return Action Added action.
*/
$hook->addAction(callable $callback, int $priority = Priority::NORMAL): Action
public function addAction(callable $callback, int $priority = Priority::NORMAL): Action;
```

Adds action once on the hook:
Expand All @@ -127,7 +125,7 @@ Adds action once on the hook:
*
* @return Action Added action.
*/
$hook->addActionOnce(callable $callback, int $priority = Priority::NORMAL): Action
public function addActionOnce(callable $callback, int $priority = Priority::NORMAL): Action;
```

Runs the added actions for the hook:
Expand All @@ -139,7 +137,7 @@ Runs the added actions for the hook:
*
* @return Action[] Done actions.
*/
$hook->doActions(mixed ...$arguments): Action[]
public function doActions(mixed ...$arguments): array;
```

Checks if the hook has actions:
Expand All @@ -149,7 +147,7 @@ Checks if the hook has actions:
* True if the hook has any action even if the action has been
* done before (recurring actions created with addAction).
*/
$hook->hasActions(): bool
public function hasActions(): bool;
```

Checks if the hook has undone actions:
Expand All @@ -158,7 +156,7 @@ Checks if the hook has undone actions:
/**
* True if the hook has some action left undone.
*/
$hook->hasUndoneActions(): bool
public function hasUndoneActions(): bool;
```

Checks if the actions were done at least once:
Expand All @@ -167,29 +165,27 @@ Checks if the actions were done at least once:
/**
* If doActions was executed at least once.
*/
$hook->hasDoneActions(): bool
public function hasDoneActions(): bool;
```

Gets hook name:

```php
$hook->getName(): string
public function getName(): string;
```

### Priority Class

```php
use Josantonius\Hook\Priority;
```
`Josantonius\Hook\Priority`

Available constants:

```php
Priority::HIGHEST; // 50
Priority::HIGH; // 100
Priority::NORMAL; // 150
Priority::LOW; // 200
Priority::LOWEST; // 250
public const HIGHEST = 50;
public const HIGH = 100;
public const NORMAL = 150;
public const LOW = 200;
public const LOWEST = 250;
```

## Exceptions Used
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"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;",
"phpunit": "vendor/bin/phpunit",
"tests": [
"clear",
"@phpmd",
Expand Down
6 changes: 4 additions & 2 deletions phpmd.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
<ruleset name="PHPMD rule set" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
<ruleset name="PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>Coding standard.</description>
Expand Down Expand Up @@ -30,7 +32,7 @@
<rule ref="rulesets/controversial.xml/Superglobals" />
<rule ref="rulesets/controversial.xml/CamelCaseClassName" />
<rule ref="rulesets/controversial.xml/CamelCasePropertyName" />
<rule ref="rulesets/controversial.xml/CamelCaseMethodName" />
<!--<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>-->
<rule ref="rulesets/controversial.xml/CamelCaseParameterName" />
<rule ref="rulesets/controversial.xml/CamelCaseVariableName" />

Expand Down
14 changes: 7 additions & 7 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
declare(strict_types=1);

/*
* This file is part of https://github.com/josantonius/php-hook repository.
*
* (c) Josantonius <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* This file is part of https://github.com/josantonius/php-hook repository.
*
* (c) Josantonius <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Josantonius\Hook;

Expand Down
14 changes: 7 additions & 7 deletions src/Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
declare(strict_types=1);

/*
* This file is part of https://github.com/josantonius/php-hook repository.
*
* (c) Josantonius <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
* This file is part of https://github.com/josantonius/php-hook repository.
*
* (c) Josantonius <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Josantonius\Hook;

Expand Down
Loading

0 comments on commit 68d16fd

Please sign in to comment.