Skip to content

Release/v1.0.3 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions .github/lang/es-ES/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Biblioteca PHP para manejar excepciones.

## 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 @@ -61,39 +63,34 @@ git clone https://github.com/josantonius/php-exception-handler.git

### Clase ExceptionHandler

```php
use Josantonius\ExceptionHandler\ExceptionHandler;
```
`Josantonius\ExceptionHandler\ExceptionHandler`

Establece un manejador de excepciones:

```php
/**
* Sets a exception handler.
*
* @param callable $callback Función para manejo de excepciones.
* @param array $runBeforeCallback Métodos a llamar en la excepción antes del callback.
* @param array $runAfterCallback Métodos a llamar en la excepción después del callback.
* @param callable $callback Exception handler function.
* @param string[] $runBeforeCallback Method names to call in the exception before run callback.
* @param string[] $runAfterCallback Method names to call in the exception after run callback.
*
* @throws NotCallableException si la llamada de retorno no es de tipo callable.
* @throws WrongMethodNameException si el nombre del método no es string o está vacío.
* @throws NotCallableException if the callback is not callable.
* @throws WrongMethodNameException if the method names are not string or are empty.
*
* @see https://www.php.net/manual/en/functions.first_class_callable_syntax.php
*/
new ExceptionHandler(
callable $callback,
string[] $runBeforeCallback = [],
string[] $runAfterCallback = []
public function __construct(
private callable $callback,
private array $runBeforeCallback = [],
private array $runAfterCallback = []
);
```

## Excepciones utilizadas

```php
use Josantonius\ExceptionHandler\Exceptions\NotCallableException;
```

```php
use Josantonius\ExceptionHandler\Exceptions\WrongMethodNameException;
```

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

## [v1.0.3](https://github.com/josantonius/php-exception-handler/releases/tag/v1.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.

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

* Fixed error when validating method names. Now it will throw exception if it is an empty string.
Expand Down
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ PHP library for handling exceptions.
- [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 @@ -61,9 +63,7 @@ git clone https://github.com/josantonius/php-exception-handler.git

### ExceptionHandler Class

```php
use Josantonius\ExceptionHandler\ExceptionHandler;
```
`Josantonius\ExceptionHandler\ExceptionHandler`

Sets a exception handler:

Expand All @@ -72,28 +72,25 @@ Sets a exception handler:
* Sets a exception handler.
*
* @param callable $callback Exception handler function.
* @param array $runBeforeCallback Method names to call in the exception before run callback.
* @param array $runAfterCallback Method names to call in the exception after run callback.
* @param string[] $runBeforeCallback Method names to call in the exception before run callback.
* @param string[] $runAfterCallback Method names to call in the exception after run callback.
*
* @throws NotCallableException if the callback is not callable.
* @throws WrongMethodNameException if the method names are not string or are empty.
*
* @see https://www.php.net/manual/en/functions.first_class_callable_syntax.php
*/
new ExceptionHandler(
callable $callback,
string[] $runBeforeCallback = [],
string[] $runAfterCallback = []
public function __construct(
private callable $callback,
private array $runBeforeCallback = [],
private array $runAfterCallback = []
);
```

## Exceptions Used

```php
use Josantonius\ExceptionHandler\Exceptions\NotCallableException;
```

```php
use Josantonius\ExceptionHandler\Exceptions\WrongMethodNameException;
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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
2 changes: 1 addition & 1 deletion phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,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/ExceptionHandler.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-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* 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-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Josantonius\ExceptionHandler;

Expand Down
14 changes: 7 additions & 7 deletions src/Exceptions/NotCallableException.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/*
* This file is part of https://github.com/josantonius/php-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* 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-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Josantonius\ExceptionHandler\Exceptions;

Expand Down
14 changes: 7 additions & 7 deletions src/Exceptions/WrongMethodNameException.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/*
* This file is part of https://github.com/josantonius/php-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* 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-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Josantonius\ExceptionHandler\Exceptions;

Expand Down
34 changes: 18 additions & 16 deletions tests/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

/*
* This file is part of https://github.com/josantonius/php-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* 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-exception-handler repository.
*
* (c) Josantonius <hello@josantonius.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
*/

namespace Josantonius\ErrorHandler\Tests;

Expand All @@ -31,14 +33,14 @@ public function setUp(): void
$this->handler = new Handler();
}

public function testShouldFailIfCallableCallbackIsNotPassed(): void
public function test_should_fail_if_callable_callback_is_not_passed(): void
{
$this->expectException(NotCallableException::class);

new ExceptionHandler(callback: 'foo');
}

public function testShouldFailIfTheMethodNamesNotContainValidDataType(): void
public function test_should_fail_if_the_method_names_not_contain_valid_data_type(): void
{
$this->expectException(WrongMethodNameException::class);

Expand All @@ -48,15 +50,15 @@ public function testShouldFailIfTheMethodNamesNotContainValidDataType(): void
);
}

public function testShouldSetTheHandlerOnlyWithTheCallback(): void
public function test_should_set_the_handler_only_with_the_callback(): void
{
$this->assertInstanceOf(
ExceptionHandler::class,
new ExceptionHandler(callback: $this->handler->init(...))
);
}

public function testShouldSetTheHandlerOnlyWithCallsToRunBefore(): void
public function test_should_set_the_handler_only_with_calls_to_run_before(): void
{
$this->assertInstanceOf(
ExceptionHandler::class,
Expand All @@ -67,7 +69,7 @@ public function testShouldSetTheHandlerOnlyWithCallsToRunBefore(): void
);
}

public function testShouldSetTheHandlerOnlyWithCallsToAfter(): void
public function test_should_set_the_handler_only_with_calls_to_after(): void
{
$this->assertInstanceOf(
ExceptionHandler::class,
Expand All @@ -78,7 +80,7 @@ public function testShouldSetTheHandlerOnlyWithCallsToAfter(): void
);
}

public function testShouldCallTheCallbackWhenAnExceptionIsThrow(): void
public function test_should_call_the_callback_when_an_exception_is_throw(): void
{
$exceptionHandler = new ExceptionHandler(callback: $this->handler->init(...));

Expand All @@ -94,7 +96,7 @@ public function testShouldCallTheCallbackWhenAnExceptionIsThrow(): void
$this->assertEquals('init', History::get(0)->methodName);
}

public function testShouldCallTheCallbackBeforeRunMethodsWhenAnExceptionIsThrow(): void
public function test_should_call_the_callback_before_run_methods_when_exception_is_throw(): void
{
$exceptionHandler = new ExceptionHandler(
callback: $this->handler->init(...),
Expand All @@ -113,7 +115,7 @@ public function testShouldCallTheCallbackBeforeRunMethodsWhenAnExceptionIsThrow(
$this->assertEquals('context', History::get(0)->methodName);
}

public function testShouldCallTheCallbackAfterRunMethodsWhenAnExceptionIsThrow(): void
public function test_should_call_the_callback_after_run_methods_when_exception_is_throw(): void
{
$exceptionHandler = new ExceptionHandler(
callback: $this->handler->init(...),
Expand All @@ -134,7 +136,7 @@ public function testShouldCallTheCallbackAfterRunMethodsWhenAnExceptionIsThrow()
$this->assertEquals('render', History::get(2)->methodName);
}

public function testShouldCallTheCallbackAfterAndBeforeRunMethodsWhenAnExceptionIsThrow(): void
public function test_should_call_callback_and_all_methods_when_an_exception_is_throw(): void
{
$exceptionHandler = new ExceptionHandler(
callback: $this->handler->init(...),
Expand Down