Skip to content

pre-release/v1.0.3 #1

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 4 commits into from
Aug 27, 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
25 changes: 10 additions & 15 deletions .github/lang/es-ES/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,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
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PHP library for handling exceptions.
- [TODO](#todo)
- [Changelog](#changelog)
- [Contribution](#contribution)
- [Sponsor](#Sponsor)
- [Sponsor](#sponsor)
- [License](#license)

---
Expand Down Expand Up @@ -61,9 +61,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 +70,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 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