Skip to content

Commit

Permalink
Merge pull request #18 from maurobonfietti/0.17.0
Browse files Browse the repository at this point in the history
Version 0.17.0
  • Loading branch information
maurobonfietti committed Mar 16, 2021
2 parents 9fcdb95 + 2f9b362 commit 9f2d96b
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Command/CrudGeneratorCommand.php
Expand Up @@ -11,7 +11,7 @@

class CrudGeneratorCommand extends Command
{
const COMMAND_VERSION = '0.16.0';
const COMMAND_VERSION = '0.17.0';

public function __construct($app)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CrudGeneratorService.php
Expand Up @@ -131,7 +131,7 @@ private function updateRoutes()
private function updateRepository()
{
$repository = '
$container[\''.$this->entity.'_repository\'] = static function ($container): App\Repository\\'.$this->entityUpper.'Repository {
$container[\''.$this->entity.'_repository\'] = static function (Pimple\Container $container): App\Repository\\'.$this->entityUpper.'Repository {
return new App\Repository\\'.$this->entityUpper.'Repository($container[\'db\']);
};
';
Expand All @@ -144,7 +144,7 @@ private function updateRepository()
private function updateServices()
{
$service = '
$container[\''.$this->entity.'_service\'] = static function ($container): App\Service\\'.$this->entityUpper.'Service {
$container[\''.$this->entity.'_service\'] = static function (Pimple\Container $container): App\Service\\'.$this->entityUpper.'Service {
return new App\Service\\'.$this->entityUpper.'Service($container[\''.$this->entity.'_repository\']);
};
';
Expand Down
2 changes: 0 additions & 2 deletions src/Command/TemplateBase/Objectbase/Base.php
Expand Up @@ -11,8 +11,6 @@ abstract class Base
{
protected Container $container;

protected ObjectbaseService $objectbaseService;

public function __construct(Container $container)
{
$this->container = $container;
Expand Down
4 changes: 2 additions & 2 deletions src/Command/TemplateBase/Objectbase/Create.php
Expand Up @@ -12,9 +12,9 @@ final class Create extends Base
{
public function __invoke(Request $request, Response $response): Response
{
$input = $request->getParsedBody();
$input = (array) $request->getParsedBody();
$objectbase = $this->getObjectbaseService()->create($input);

return JsonResponse::withJson($response, json_encode($objectbase), 201);
return JsonResponse::withJson($response, (string) json_encode($objectbase), 201);
}
}
3 changes: 3 additions & 0 deletions src/Command/TemplateBase/Objectbase/Delete.php
Expand Up @@ -10,6 +10,9 @@

final class Delete extends Base
{
/**
* @param array<string> $args
*/
public function __invoke(
Request $request,
Response $response,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/Objectbase/GetAll.php
Expand Up @@ -14,6 +14,6 @@ public function __invoke(Request $request, Response $response): Response
{
$objectbases = $this->getObjectbaseService()->getAll();

return JsonResponse::withJson($response, json_encode($objectbases));
return JsonResponse::withJson($response, (string) json_encode($objectbases));
}
}
5 changes: 4 additions & 1 deletion src/Command/TemplateBase/Objectbase/GetOne.php
Expand Up @@ -10,13 +10,16 @@

final class GetOne extends Base
{
/**
* @param array<string> $args
*/
public function __invoke(
Request $request,
Response $response,
array $args
): Response {
$objectbase = $this->getObjectbaseService()->getOne((int) $args['id']);

return JsonResponse::withJson($response, json_encode($objectbase));
return JsonResponse::withJson($response, (string) json_encode($objectbase));
}
}
7 changes: 5 additions & 2 deletions src/Command/TemplateBase/Objectbase/Update.php
Expand Up @@ -10,14 +10,17 @@

final class Update extends Base
{
/**
* @param array<string> $args
*/
public function __invoke(
Request $request,
Response $response,
array $args
): Response {
$input = $request->getParsedBody();
$input = (array) $request->getParsedBody();
$objectbase = $this->getObjectbaseService()->update($input, (int) $args['id']);

return JsonResponse::withJson($response, json_encode($objectbase));
return JsonResponse::withJson($response, (string) json_encode($objectbase));
}
}
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/ObjectbaseRepository.php
Expand Up @@ -40,7 +40,7 @@ public function getAll(): array
$statement = $this->getDb()->prepare($query);
$statement->execute();

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

public function create(object $objectbase): object
Expand Down
4 changes: 2 additions & 2 deletions src/Command/TemplateBase/ObjectbaseService.php
Expand Up @@ -33,15 +33,15 @@ public function getOne(int $objectbaseId): object

public function create(array $input): object
{
$objectbase = json_decode(json_encode($input), false);
$objectbase = json_decode((string) json_encode($input), false);

return $this->objectbaseRepository->create($objectbase);
}

public function update(array $input, int $objectbaseId): object
{
$objectbase = $this->checkAndGet($objectbaseId);
$data = json_decode(json_encode($input), false);
$data = json_decode((string) json_encode($input), false);

return $this->objectbaseRepository->update($objectbase, $data);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Command/TemplateBase/ObjectbaseTest.php
Expand Up @@ -8,7 +8,7 @@ class ObjectbaseTest extends TestCase
{
private static $id;

public function testCreate()
public function testCreate(): void
{
$params = [
'' => '',
Expand All @@ -27,7 +27,7 @@ public function testCreate()
$this->assertStringNotContainsString('error', $result);
}

public function testGetAll()
public function testGetAll(): void
{
$request = $this->createRequest('GET', '/objectbase');
$response = $this->getAppInstance()->handle($request);
Expand All @@ -39,7 +39,7 @@ public function testGetAll()
$this->assertStringNotContainsString('error', $result);
}

public function testGetOne()
public function testGetOne(): void
{
$request = $this->createRequest('GET', '/objectbase/' . self::$id);
$response = $this->getAppInstance()->handle($request);
Expand All @@ -51,7 +51,7 @@ public function testGetOne()
$this->assertStringNotContainsString('error', $result);
}

public function testGetOneNotFound()
public function testGetOneNotFound(): void
{
$request = $this->createRequest('GET', '/objectbase/123456789');
$response = $this->getAppInstance()->handle($request);
Expand All @@ -62,7 +62,7 @@ public function testGetOneNotFound()
$this->assertStringContainsString('error', $result);
}

public function testUpdate()
public function testUpdate(): void
{
$req = $this->createRequest('PUT', '/objectbase/' . self::$id);
$request = $req->withParsedBody(['' => '']);
Expand All @@ -75,7 +75,7 @@ public function testUpdate()
$this->assertStringNotContainsString('error', $result);
}

public function testDelete()
public function testDelete(): void
{
$request = $this->createRequest('DELETE', '/objectbase/' . self::$id);
$response = $this->getAppInstance()->handle($request);
Expand Down

0 comments on commit 9f2d96b

Please sign in to comment.