Skip to content

pre-release/v2.0.4 #3

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
28 changes: 15 additions & 13 deletions .github/lang/es-ES/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Biblioteca de PHP para obtener mensajes y definiciones de códigos de estado HTT

- [Requisitos](#requisitos)
- [Instalación](#instalación)
- [Available Classes](#available-classes)
- [Clases disponibles](#clases-disponibles)
- [Clase HttpStatusCode](#clase-httpstatuscode)
- [Excepciones utilizadas](#excepciones-utilizadas)
- [Uso](#uso)
- [Listado en formato JSON](#listado-en-formato-json)
- [Tests](#tests)
- [Tareas pendientes](#-tareas-pendientes)
- [Tareas pendientes](#tareas-pendientes)
- [Registro de Cambios](#registro-de-cambios)
- [Contribuir](#contribuir)
- [Patrocinar](#patrocinar)
Expand Down Expand Up @@ -62,9 +62,7 @@ git clone https://github.com/josantonius/http-status-code.git

### Clase HttpStatusCode

```php
use Josantonius\HttpStatusCode\HttpStatusCode;
```
`Josantonius\HttpStatusCode\HttpStatusCode`

Crear una nueva instancia que defina el idioma:

Expand All @@ -77,37 +75,37 @@ Crear una nueva instancia que defina el idioma:
*
* @throws UnsupportedLanguageException if language is not supported.
*/
$httpStatusCode = new HttpStatusCode(string $language = 'en');
public function __construct(string $language = 'en');
```

Obtiene el mensaje de un código de estado HTTP:

```php
$httpStatusCode->getMessage(int $code): string|null
public function getMessage(int $code): string|null;
```

Obtiene los mensajes de todos los códigos de estado HTTP:

```php
$httpStatusCode->getMessages(): array
public function getMessages(): array;
```

Obtiene la definición de un código de estado HTTP:

```php
$httpStatusCode->getDefinition(int $code): string|null
public function getDefinition(int $code): string|null;
```

Obtiene las definiciones de todos los códigos de estado HTTP:

```php
$httpStatusCode->getDefinitions(): array
public function getDefinitions(): array;
```

Obtiene mensajes y definiciones de todos los códigos de estado HTTP:

```php
$httpStatusCode->getAll(): array
public function getAll(): array;
```

## Excepciones utilizadas
Expand All @@ -123,10 +121,14 @@ Ejemplo de uso para esta biblioteca:
### Crear una nueva instancia que defina el idioma

```php
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode(); // Obtiene los mensajes en inglés.
```

```php
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode('es'); // Obtiene los mensajes en español.
```

Expand Down Expand Up @@ -235,9 +237,9 @@ $httpStatusCode->getAll();
]
```

## List in Json format
## Listado en formato JSON

[Go to the resource](https://gist.github.com/Josantonius/b455e315bc7f790d14b136d61d9ae469).
[Ir al recurso](https://gist.github.com/Josantonius/b455e315bc7f790d14b136d61d9ae469).

## Tests

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PHP library to get HTTP status code messages and definitions.
- [TODO](#todo)
- [Changelog](#changelog)
- [Contribution](#contribution)
- [Sponsor](#Sponsor)
- [Sponsor](#sponsor)
- [License](#license)

---
Expand Down Expand Up @@ -62,9 +62,7 @@ git clone https://github.com/josantonius/http-status-code.git

### HttpStatusCode Class

```php
use Josantonius\HttpStatusCode\HttpStatusCode;
```
`Josantonius\HttpStatusCode\HttpStatusCode`

Create a new instance defining the language:

Expand All @@ -77,37 +75,37 @@ Create a new instance defining the language:
*
* @throws UnsupportedLanguageException if language is not supported.
*/
$httpStatusCode = new HttpStatusCode(string $language = 'en');
public function __construct(string $language = 'en');
```

Gets message of an HTTP status code:

```php
$httpStatusCode->getMessage(int $code): string|null
public function getMessage(int $code): string|null;
```

Gets the messages of all HTTP status codes:

```php
$httpStatusCode->getMessages(): array
public function getMessages(): array;
```

Gets definition of an HTTP status code:

```php
$httpStatusCode->getDefinition(int $code): string|null
public function getDefinition(int $code): string|null;
```

Gets the definitions of all HTTP status codes:

```php
$httpStatusCode->getDefinitions(): array
public function getDefinitions(): array;
```

Gets messages and definitions of all HTTP status codes:

```php
$httpStatusCode->getAll(): array
public function getAll(): array;
```

## Exceptions Used
Expand All @@ -129,6 +127,8 @@ $httpStatusCode = new HttpStatusCode(); // Gets the messages in English.
```

```php
use Josantonius\HttpStatusCode\HttpStatusCode;

$httpStatusCode = new HttpStatusCode('es'); // Gets the messages in Spanish.
```

Expand Down
2 changes: 1 addition & 1 deletion phpmd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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/Exceptions/UnsupportedLanguageException.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-http-status-code 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-http-status-code 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\HttpStatusCode\Exceptions;

Expand Down
14 changes: 7 additions & 7 deletions src/HttpStatusCode.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-http-status-code 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-http-status-code 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\HttpStatusCode;

Expand Down
28 changes: 15 additions & 13 deletions tests/HttpStatusCodeTest.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-http-status-code 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-http-status-code 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\HttpStatusCode\Tests;

Expand All @@ -29,14 +31,14 @@ public function setUp(): void
$this->httpStatusCodeEs = new HttpStatusCode('es');
}

public function testShouldFailIfUnsupportedLanguageIsUsed()
public function test_should_fail_if_unsupported_language_is_used()
{
$this->expectException(UnsupportedLanguageException::class);

new HttpStatusCode('fr');
}

public function testShouldGetMessage()
public function test_should_get_message()
{
$this->assertEquals(
'Request Time-out',
Expand All @@ -49,15 +51,15 @@ public function testShouldGetMessage()
);
}

public function testShouldGetMessages()
public function test_should_get_messages()
{
$messages = $this->httpStatusCodeEn->getMessages();

$this->assertIsArray($messages);
$this->assertArrayHasKey(408, $messages);
}

public function testShouldGetDefinition()
public function test_should_get_definition()
{
$this->assertStringContainsString(
'The server timed out waiting for the request.',
Expand All @@ -70,15 +72,15 @@ public function testShouldGetDefinition()
);
}

public function testShouldGetDefinitions()
public function test_should_get_definitions()
{
$definitions = $this->httpStatusCodeEn->getDefinitions();

$this->assertIsArray($definitions);
$this->assertArrayHasKey(408, $definitions);
}

public function testShouldGetAll()
public function test_should_get_all()
{
$all = $this->httpStatusCodeEn->getAll();

Expand Down