Skip to content

Commit

Permalink
Merge pull request #112 from maurobonfietti/1.21.0
Browse files Browse the repository at this point in the history
Version 1.21.0
  • Loading branch information
maurobonfietti authored Sep 4, 2020
2 parents 29a8cae + 6d84509 commit 1f06a07
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/App/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require __DIR__ . '/../../vendor/autoload.php';
$baseDir = __DIR__ . '/../../';
$dotenv = Dotenv\Dotenv::createUnsafeImmutable($baseDir);
$dotenv = Dotenv\Dotenv::createImmutable($baseDir);
$envFile = $baseDir . '.env';
if (file_exists($envFile)) {
$dotenv->load();
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function __construct(Container $container)
$this->container = $container;
}

/**
* @param array|null|object $message
*/
protected function jsonResponse(
Response $response,
string $status,
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class DefaultController extends BaseController
{
public const API_VERSION = '1.20.0';
public const API_VERSION = '1.21.0';

public function getHelp(Request $request, Response $response): Response
{
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/ApiError.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __invoke(
'code' => $statusCode,
];
$body = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
$response->getBody()->write($body);
$response->getBody()->write((string) $body);

return $response
->withStatus($statusCode)
Expand Down
6 changes: 3 additions & 3 deletions src/Repository/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getAllTasks(): array
$statement = $this->getDb()->prepare($query);
$statement->execute();

return $statement->fetchAll();
return (array) $statement->fetchAll();
}

public function getAll(int $userId): array
Expand All @@ -41,7 +41,7 @@ public function getAll(int $userId): array
$statement->bindParam('userId', $userId);
$statement->execute();

return $statement->fetchAll();
return (array) $statement->fetchAll();
}

public function search(string $tasksName, int $userId, ?int $status): array
Expand All @@ -56,7 +56,7 @@ public function search(string $tasksName, int $userId, ?int $status): array
}
$statement->execute();

return $statement->fetchAll();
return (array) $statement->fetchAll();
}

public function create(object $task): object
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Note/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class Create extends Base
{
public function create(array $input): object
{
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);
if (! isset($data->name)) {
throw new Note('Invalid data: name is required.', 400);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Note/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class Update extends Base
public function update(array $input, int $noteId): object
{
$note = $this->getOneFromDb($noteId);
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);
if (isset($data->name)) {
$note->name = self::validateNoteName($data->name);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Service/Task/TaskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public function getOne(int $taskId, int $userId): object
return $task;
}

public function search(string $tasksName, int $userId, $status): array
{
public function search(
string $tasksName,
int $userId,
?string $status
): array {
if ($status !== null) {
$status = (int) $status;
}
Expand All @@ -40,7 +43,7 @@ public function search(string $tasksName, int $userId, $status): array

public function create(array $input): object
{
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);
if (! isset($data->name)) {
throw new Task('The field "name" is required.', 400);
}
Expand Down Expand Up @@ -83,7 +86,7 @@ public function delete(int $taskId, int $userId): void
private function validateTask(array $input, int $taskId): object
{
$task = $this->getTaskFromDb($taskId, (int) $input['decoded']->sub);
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);
if (! isset($data->name) && ! isset($data->status)) {
throw new Task('Enter the data to update the task.', 400);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/User/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected static function validateEmail(string $emailValue): string
throw new User('Invalid email', 400);
}

return $email;
return (string) $email;
}

protected function getUserFromCache(int $userId): object
Expand All @@ -51,7 +51,7 @@ protected function getUserFromCache(int $userId): object
$key = $this->redisService->generateKey($redisKey);
if ($this->redisService->exists($key)) {
$data = $this->redisService->get($key);
$user = json_decode(json_encode($data), false);
$user = json_decode((string) json_encode($data), false);
} else {
$user = $this->getUserFromDb($userId);
$this->redisService->setex($key, $user);
Expand Down
6 changes: 3 additions & 3 deletions src/Service/User/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function create(array $input): object
public function update(array $input, int $userId): object
{
$user = $this->getUserFromDb($userId);
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);
if (! isset($data->name) && ! isset($data->email)) {
throw new User('Enter the data to update the user.', 400);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ public function delete(int $userId): void

public function login(array $input): string
{
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);
if (! isset($data->email)) {
throw new User('The field "email" is required.', 400);
}
Expand All @@ -117,7 +117,7 @@ public function login(array $input): string

private function validateUserData(array $input): object
{
$user = json_decode(json_encode($input), false);
$user = json_decode((string) json_encode($input), false);
if (! isset($user->name)) {
throw new User('The field "name" is required.', 400);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/NoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function testGetNotes(): void
$this->assertStringContainsString('id', $result);
$this->assertStringContainsString('name', $result);
$this->assertStringContainsString('description', $result);
$this->assertMatchesRegularExpression('{"code":200,"status":"success"}', $value);
$this->assertMatchesRegularExpression('{"name":"[A-Za-z0-9_. ]+","description":"[A-Za-z0-9_. ]+"}', $value);
$this->assertMatchesRegularExpression('{"code":200,"status":"success"}', (string) $value);
$this->assertMatchesRegularExpression('{"name":"[A-Za-z0-9_. ]+","description":"[A-Za-z0-9_. ]+"}', (string) $value);
$this->assertStringNotContainsString('error', $result);
}

Expand All @@ -40,7 +40,7 @@ public function testGetNotesByPage(): void
$response = $this->runApp('GET', '/api/v1/notes?page=1&perPage=3');

$result = (string) $response->getBody();
$value = json_encode(json_decode($result));
$value = (string) json_encode(json_decode($result));

$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('application/json', $response->getHeaderLine('Content-Type'));
Expand Down

0 comments on commit 1f06a07

Please sign in to comment.