Skip to content

Commit 8572303

Browse files
authored
Merge pull request #2 from josantonius/release/v1.0.3
Release/v1.0.3
2 parents b7eb3ac + 461bcb6 commit 8572303

10 files changed

+81
-70
lines changed

.github/lang/es-ES/README.md

+13-16
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ Biblioteca PHP para manejar excepciones.
3232

3333
## Requisitos
3434

35-
Esta biblioteca es compatible con las versiones de PHP: 8.1.
35+
- Sistema operativo: Linux | Windows.
36+
37+
- Versiones de PHP: 8.1 | 8.2.
3638

3739
## Instalación
3840

@@ -61,39 +63,34 @@ git clone https://github.com/josantonius/php-exception-handler.git
6163

6264
### Clase ExceptionHandler
6365

64-
```php
65-
use Josantonius\ExceptionHandler\ExceptionHandler;
66-
```
66+
`Josantonius\ExceptionHandler\ExceptionHandler`
6767

6868
Establece un manejador de excepciones:
6969

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

9090
## Excepciones utilizadas
9191

9292
```php
9393
use Josantonius\ExceptionHandler\Exceptions\NotCallableException;
94-
```
95-
96-
```php
9794
use Josantonius\ExceptionHandler\Exceptions\WrongMethodNameException;
9895
```
9996

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ jobs:
4343
name: 'PHPUnit (PHP ${{ matrix.php }} - ${{ matrix.system }})'
4444
strategy:
4545
matrix:
46-
system: ['ubuntu-latest']
46+
system: ['ubuntu-latest', 'windows-latest']
4747
php:
4848
- '8.1'
49+
- '8.2'
4950
steps:
5051
- name: Checkout Code
5152
uses: actions/checkout@v3

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# CHANGELOG
22

3+
## [v1.0.3](https://github.com/josantonius/php-exception-handler/releases/tag/v1.0.3) (2022-09-29)
4+
5+
* The notation type in the test function names has been changed from camel to snake case for readability.
6+
7+
* Functions were added to document the methods and avoid confusion.
8+
9+
* Disabled the ´CamelCaseMethodName´ rule in ´phpmd.xml´ to avoid warnings about function names in tests.
10+
11+
* The alignment of the asterisks in the comments has been fixed.
12+
13+
* Tests for Windows have been added.
14+
15+
* Tests for PHP 8.2 have been added.
16+
317
## [v1.0.2](https://github.com/josantonius/php-exception-handler/releases/tag/v1.0.2) (2022-08-11)
418

519
* Fixed error when validating method names. Now it will throw exception if it is an empty string.

README.md

+11-14
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ PHP library for handling exceptions.
2525
- [TODO](#todo)
2626
- [Changelog](#changelog)
2727
- [Contribution](#contribution)
28-
- [Sponsor](#Sponsor)
28+
- [Sponsor](#sponsor)
2929
- [License](#license)
3030

3131
---
3232

3333
## Requirements
3434

35-
This library is compatible with the PHP versions: 8.1.
35+
- Operating System: Linux | Windows.
36+
37+
- PHP versions: 8.1 | 8.2.
3638

3739
## Installation
3840

@@ -61,9 +63,7 @@ git clone https://github.com/josantonius/php-exception-handler.git
6163

6264
### ExceptionHandler Class
6365

64-
```php
65-
use Josantonius\ExceptionHandler\ExceptionHandler;
66-
```
66+
`Josantonius\ExceptionHandler\ExceptionHandler`
6767

6868
Sets a exception handler:
6969

@@ -72,28 +72,25 @@ Sets a exception handler:
7272
* Sets a exception handler.
7373
*
7474
* @param callable $callback Exception handler function.
75-
* @param array $runBeforeCallback Method names to call in the exception before run callback.
76-
* @param array $runAfterCallback Method names to call in the exception after run callback.
75+
* @param string[] $runBeforeCallback Method names to call in the exception before run callback.
76+
* @param string[] $runAfterCallback Method names to call in the exception after run callback.
7777
*
7878
* @throws NotCallableException if the callback is not callable.
7979
* @throws WrongMethodNameException if the method names are not string or are empty.
8080
*
8181
* @see https://www.php.net/manual/en/functions.first_class_callable_syntax.php
8282
*/
83-
new ExceptionHandler(
84-
callable $callback,
85-
string[] $runBeforeCallback = [],
86-
string[] $runAfterCallback = []
83+
public function __construct(
84+
private callable $callback,
85+
private array $runBeforeCallback = [],
86+
private array $runAfterCallback = []
8787
);
8888
```
8989

9090
## Exceptions Used
9191

9292
```php
9393
use Josantonius\ExceptionHandler\Exceptions\NotCallableException;
94-
```
95-
96-
```php
9794
use Josantonius\ExceptionHandler\Exceptions\WrongMethodNameException;
9895
```
9996

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"htmlCoverage": "vendor/bin/phpunit --coverage-html coverage",
5959
"phpcs": "vendor/bin/phpcs --standard=phpcs.xml $(find . -name '*.php');",
6060
"phpmd": "vendor/bin/phpmd src,tests text ./phpmd.xml",
61-
"phpunit": "vendor/bin/phpunit --colors=always;",
61+
"phpunit": "vendor/bin/phpunit",
6262
"tests": [
6363
"clear",
6464
"@phpmd",

phpmd.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<rule ref="rulesets/controversial.xml/Superglobals" />
3333
<rule ref="rulesets/controversial.xml/CamelCaseClassName" />
3434
<rule ref="rulesets/controversial.xml/CamelCasePropertyName" />
35-
<rule ref="rulesets/controversial.xml/CamelCaseMethodName" />
35+
<!--<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>-->
3636
<rule ref="rulesets/controversial.xml/CamelCaseParameterName" />
3737
<rule ref="rulesets/controversial.xml/CamelCaseVariableName" />
3838

src/ExceptionHandler.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
declare(strict_types=1);
44

55
/*
6-
* This file is part of https://github.com/josantonius/php-exception-handler repository.
7-
*
8-
* (c) Josantonius <[email protected]>
9-
*
10-
* For the full copyright and license information, please view the LICENSE
11-
* file that was distributed with this source code.
12-
*/
6+
* This file is part of https://github.com/josantonius/php-exception-handler repository.
7+
*
8+
* (c) Josantonius <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
1313

1414
namespace Josantonius\ExceptionHandler;
1515

src/Exceptions/NotCallableException.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
/*
4-
* This file is part of https://github.com/josantonius/php-exception-handler repository.
5-
*
6-
* (c) Josantonius <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
4+
* This file is part of https://github.com/josantonius/php-exception-handler repository.
5+
*
6+
* (c) Josantonius <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
1111

1212
namespace Josantonius\ExceptionHandler\Exceptions;
1313

src/Exceptions/WrongMethodNameException.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
/*
4-
* This file is part of https://github.com/josantonius/php-exception-handler repository.
5-
*
6-
* (c) Josantonius <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
4+
* This file is part of https://github.com/josantonius/php-exception-handler repository.
5+
*
6+
* (c) Josantonius <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
1111

1212
namespace Josantonius\ExceptionHandler\Exceptions;
1313

tests/ExceptionHandlerTest.php

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

33
/*
4-
* This file is part of https://github.com/josantonius/php-exception-handler repository.
5-
*
6-
* (c) Josantonius <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
4+
* This file is part of https://github.com/josantonius/php-exception-handler repository.
5+
*
6+
* (c) Josantonius <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
12+
*/
1113

1214
namespace Josantonius\ErrorHandler\Tests;
1315

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

34-
public function testShouldFailIfCallableCallbackIsNotPassed(): void
36+
public function test_should_fail_if_callable_callback_is_not_passed(): void
3537
{
3638
$this->expectException(NotCallableException::class);
3739

3840
new ExceptionHandler(callback: 'foo');
3941
}
4042

41-
public function testShouldFailIfTheMethodNamesNotContainValidDataType(): void
43+
public function test_should_fail_if_the_method_names_not_contain_valid_data_type(): void
4244
{
4345
$this->expectException(WrongMethodNameException::class);
4446

@@ -48,15 +50,15 @@ public function testShouldFailIfTheMethodNamesNotContainValidDataType(): void
4850
);
4951
}
5052

51-
public function testShouldSetTheHandlerOnlyWithTheCallback(): void
53+
public function test_should_set_the_handler_only_with_the_callback(): void
5254
{
5355
$this->assertInstanceOf(
5456
ExceptionHandler::class,
5557
new ExceptionHandler(callback: $this->handler->init(...))
5658
);
5759
}
5860

59-
public function testShouldSetTheHandlerOnlyWithCallsToRunBefore(): void
61+
public function test_should_set_the_handler_only_with_calls_to_run_before(): void
6062
{
6163
$this->assertInstanceOf(
6264
ExceptionHandler::class,
@@ -67,7 +69,7 @@ public function testShouldSetTheHandlerOnlyWithCallsToRunBefore(): void
6769
);
6870
}
6971

70-
public function testShouldSetTheHandlerOnlyWithCallsToAfter(): void
72+
public function test_should_set_the_handler_only_with_calls_to_after(): void
7173
{
7274
$this->assertInstanceOf(
7375
ExceptionHandler::class,
@@ -78,7 +80,7 @@ public function testShouldSetTheHandlerOnlyWithCallsToAfter(): void
7880
);
7981
}
8082

81-
public function testShouldCallTheCallbackWhenAnExceptionIsThrow(): void
83+
public function test_should_call_the_callback_when_an_exception_is_throw(): void
8284
{
8385
$exceptionHandler = new ExceptionHandler(callback: $this->handler->init(...));
8486

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

97-
public function testShouldCallTheCallbackBeforeRunMethodsWhenAnExceptionIsThrow(): void
99+
public function test_should_call_the_callback_before_run_methods_when_exception_is_throw(): void
98100
{
99101
$exceptionHandler = new ExceptionHandler(
100102
callback: $this->handler->init(...),
@@ -113,7 +115,7 @@ public function testShouldCallTheCallbackBeforeRunMethodsWhenAnExceptionIsThrow(
113115
$this->assertEquals('context', History::get(0)->methodName);
114116
}
115117

116-
public function testShouldCallTheCallbackAfterRunMethodsWhenAnExceptionIsThrow(): void
118+
public function test_should_call_the_callback_after_run_methods_when_exception_is_throw(): void
117119
{
118120
$exceptionHandler = new ExceptionHandler(
119121
callback: $this->handler->init(...),
@@ -134,7 +136,7 @@ public function testShouldCallTheCallbackAfterRunMethodsWhenAnExceptionIsThrow()
134136
$this->assertEquals('render', History::get(2)->methodName);
135137
}
136138

137-
public function testShouldCallTheCallbackAfterAndBeforeRunMethodsWhenAnExceptionIsThrow(): void
139+
public function test_should_call_callback_and_all_methods_when_an_exception_is_throw(): void
138140
{
139141
$exceptionHandler = new ExceptionHandler(
140142
callback: $this->handler->init(...),

0 commit comments

Comments
 (0)