Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
III-3128 Spring cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert Ramakers committed Nov 21, 2019
1 parent 49ee597 commit 84cacdc
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 134 deletions.
3 changes: 0 additions & 3 deletions app/Controller/EventControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class EventControllerProvider implements ControllerProviderInterface
const EVENT_DETAIL = 'event.detail';
const EVENT_CARD_SYSTEMS = 'event.card_systems';

/**
* @inheritdoc
*/
public function connect(Application $app)
{
$app['uitpas.event_detail_controller'] = $app->share(
Expand Down
4 changes: 0 additions & 4 deletions app/Controller/OrganizerControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

class OrganizerControllerProvider implements ControllerProviderInterface
{

/**
* @inheritdoc
*/
public function connect(Application $app)
{
$app['uitpas.organizer_card_systems_controller'] = $app->share(
Expand Down
17 changes: 4 additions & 13 deletions app/ErrorHandlerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,29 @@

use Crell\ApiProblem\ApiProblem;
use CultuurNet\UDB3\HttpFoundation\Response\ApiProblemJsonResponse;
use Exception;
use Silex\Application;
use Silex\ServiceProviderInterface;

class ErrorHandlerProvider implements ServiceProviderInterface
{
/**
* @inheritdoc
*/
public function register(Application $app)
{
$app->error(
function (\Exception $e) {
function (Exception $e) {
$problem = $this->createNewApiProblem($e);
return new ApiProblemJsonResponse($problem);
}
);
}

/**
* @param \Exception $e
* @return ApiProblem
*/
protected function createNewApiProblem(\Exception $e)
protected function createNewApiProblem(Exception $e): ApiProblem
{
$problem = new ApiProblem($e->getMessage());
$problem->setStatus($e->getCode() ? $e->getCode() : ApiProblemJsonResponse::HTTP_BAD_REQUEST);
$problem->setStatus($e->getCode() ?: ApiProblemJsonResponse::HTTP_BAD_REQUEST);
return $problem;
}

/**
* @inheritdoc
*/
public function boot(Application $app)
{
}
Expand Down
27 changes: 9 additions & 18 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
$app->register(new YamlConfigServiceProvider($appConfigLocation . '/config.yml'));

$app->register(new CorsServiceProvider(), array(
"cors.allowOrigin" => implode(" ", $app['config']['cors']['origins']),
"cors.allowCredentials" => true
'cors.allowOrigin' => implode(' ', $app['config']['cors']['origins']),
'cors.allowCredentials' => true
));

$app->register(new UrlGeneratorServiceProvider());
Expand All @@ -27,16 +27,7 @@
*/
$app['debug'] = $app['config']['debug'] === true;

/**
* Load additional bootstrap files.
*/
foreach ($app['config']['bootstrap'] as $identifier => $enabled) {
if (true === $enabled) {
require __DIR__ . "/bootstrap/{$identifier}.php";
}
}

$app['jwt'] = $app->share(
$app['jwt'] = $app::share(
function(Application $app) {
try {
/* @var TokenStorageInterface $tokenStorage */
Expand All @@ -56,26 +47,26 @@ function(Application $app) {
}
);

$app['current_user'] = $app->share(
$app['current_user'] = $app::share(
function (Application $app) {
/* @var Jwt|null $jwt */
$jwt = $app['jwt'];

if (!is_null($jwt)) {
$cfUser = new \CultureFeed_User();
if ($jwt instanceof Jwt) {
$cfUser = new CultureFeed_User();

$cfUser->id = $jwt->getClaim('uid');
$cfUser->nick = $jwt->getClaim('nick');
$cfUser->mbox = $jwt->getClaim('email');

return $cfUser;
} else {
return null;
}

return null;
}
);

$app['culturefeed_uitpas_client'] = $app->share(
$app['culturefeed_uitpas_client'] = $app::share(
function (Application $app) {
$oauthClient = new CultureFeed_DefaultOAuthClient(
$app['config']['uitid']['consumer']['key'],
Expand Down
Empty file removed bootstrap/.empty
Empty file.
1 change: 0 additions & 1 deletion config.dist.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
debug: false
bootstrap: []
consumerExecutionDelay: 0
url: http://udb-uitpas.dev
labels:
Expand Down
29 changes: 6 additions & 23 deletions src/Controller/EventCardSystemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,35 @@

namespace CultuurNet\UDB3\UiTPASService\Controller;

use CultureFeed_Uitpas;
use CultuurNet\UDB3\UiTPASService\Controller\Response\CardSystemsJsonResponse;
use Symfony\Component\HttpFoundation\Response;

class EventCardSystemsController
{
/**
* @var \CultureFeed_Uitpas
* @var CultureFeed_Uitpas
*/
private $uitpas;

/**
* @param \CultureFeed_Uitpas $uitpas
*/
public function __construct(\CultureFeed_Uitpas $uitpas)
public function __construct(CultureFeed_Uitpas $uitpas)
{
$this->uitpas = $uitpas;
}

/**
* @param string $eventId
* @return CardSystemsJsonResponse
*/
public function get($eventId)
public function get(string $eventId): CardSystemsJsonResponse
{
$cardSystems = $this->uitpas->getCardSystemsForEvent($eventId);
return new CardSystemsJsonResponse($cardSystems->objects);
}

/**
* @param string $eventId
* @param string $cardSystemId
* @param string|null $distributionKeyId
* @return Response
*/
public function add($eventId, $cardSystemId, $distributionKeyId = null)
public function add(string $eventId, string $cardSystemId, string $distributionKeyId = null): Response
{
$this->uitpas->addCardSystemToEvent($eventId, $cardSystemId, $distributionKeyId);
return new Response('OK', 200);
}

/**
* @param string $eventId
* @param string $cardSystemId
* @return Response
*/
public function delete($eventId, $cardSystemId)
public function delete(string $eventId, string $cardSystemId): Response
{
$this->uitpas->deleteCardSystemFromEvent($eventId, $cardSystemId);
return new Response('OK', 200);
Expand Down
17 changes: 7 additions & 10 deletions src/Controller/EventDetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace CultuurNet\UDB3\UiTPASService\Controller;

use CultureFeed_Uitpas;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class EventDetailController
{
/**
* @var \CultureFeed_Uitpas
* @var CultureFeed_Uitpas
*/
private $uitpas;

Expand All @@ -28,28 +29,24 @@ class EventDetailController
private $eventCardSystemsRouteName;

/**
* @param \CultureFeed_Uitpas $uitpas
* @param CultureFeed_Uitpas $uitpas
* @param UrlGeneratorInterface $urlGenerator
* @param string $eventDetailRouteName
* @param string $eventCardSystemsRouteName
*/
public function __construct(
\CultureFeed_Uitpas $uitpas,
CultureFeed_Uitpas $uitpas,
UrlGeneratorInterface $urlGenerator,
$eventDetailRouteName,
$eventCardSystemsRouteName
string $eventDetailRouteName,
string $eventCardSystemsRouteName
) {
$this->uitpas = $uitpas;
$this->urlGenerator = $urlGenerator;
$this->eventDetailRouteName = $eventDetailRouteName;
$this->eventCardSystemsRouteName = $eventCardSystemsRouteName;
}

/**
* @param string $eventId
* @return JsonResponse
*/
public function get($eventId)
public function get(string $eventId): JsonResponse
{
$data = [
'@id' => $this->urlGenerator->generate(
Expand Down
14 changes: 4 additions & 10 deletions src/Controller/OrganizerCardSystemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@

namespace CultuurNet\UDB3\UiTPASService\Controller;

use CultureFeed_Uitpas;
use CultuurNet\UDB3\UiTPASService\Controller\Response\CardSystemsJsonResponse;

class OrganizerCardSystemsController
{
/**
* @var \CultureFeed_Uitpas
* @var CultureFeed_Uitpas
*/
private $uitpas;

/**
* @param \CultureFeed_Uitpas $uitpas
*/
public function __construct(\CultureFeed_Uitpas $uitpas)
public function __construct(CultureFeed_Uitpas $uitpas)
{
$this->uitpas = $uitpas;
}

/**
* @param string $organizerId
* @return CardSystemsJsonResponse
*/
public function get($organizerId)
public function get(string $organizerId): CardSystemsJsonResponse
{
$cardSystems = $this->uitpas->getCardSystemsForOrganizer($organizerId);
return new CardSystemsJsonResponse($cardSystems->objects);
Expand Down
18 changes: 6 additions & 12 deletions src/Controller/Response/CardSystemsJsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace CultuurNet\UDB3\UiTPASService\Controller\Response;

use CultureFeed_Uitpas_CardSystem;
use CultureFeed_Uitpas_DistributionKey;
use Symfony\Component\HttpFoundation\Response;

class CardSystemsJsonResponse extends Response
{
/**
* @param \CultureFeed_Uitpas_CardSystem[] $cardSystems
* @param CultureFeed_Uitpas_CardSystem[] $cardSystems
* @param int $status
* @param array $headers
*/
public function __construct(array $cardSystems, $status = 200, array $headers = array())
public function __construct(array $cardSystems, int $status = 200, array $headers = array())
{
$data = [];
foreach ($cardSystems as $cardSystem) {
Expand All @@ -23,11 +25,7 @@ public function __construct(array $cardSystems, $status = 200, array $headers =
parent::__construct($content, $status, $headers);
}

/**
* @param \CultureFeed_Uitpas_CardSystem $cardSystem
* @return array
*/
private function convertCardSystemToArray(\CultureFeed_Uitpas_CardSystem $cardSystem)
private function convertCardSystemToArray(CultureFeed_Uitpas_CardSystem $cardSystem): array
{
$distributionKeys = [];
foreach ($cardSystem->distributionKeys as $distributionKey) {
Expand All @@ -41,11 +39,7 @@ private function convertCardSystemToArray(\CultureFeed_Uitpas_CardSystem $cardSy
];
}

/**
* @param \CultureFeed_Uitpas_DistributionKey $distributionKey
* @return array
*/
private function convertDistributionKeyToArray(\CultureFeed_Uitpas_DistributionKey $distributionKey)
private function convertDistributionKeyToArray(CultureFeed_Uitpas_DistributionKey $distributionKey): array
{
return [
'id' => $distributionKey->id,
Expand Down
24 changes: 15 additions & 9 deletions tests/Controller/EventCardSystemsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace CultuurNet\UDB3\UiTPASService\Controller;

class EventCardSystemsControllerTest extends \PHPUnit_Framework_TestCase
use CultureFeed_Uitpas;
use CultureFeed_Uitpas_CardSystem;
use CultureFeed_Uitpas_DistributionKey;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_TestCase;

class EventCardSystemsControllerTest extends PHPUnit_Framework_TestCase
{
/**
* @var \CultureFeed_Uitpas|\PHPUnit_Framework_MockObject_MockObject
* @var CultureFeed_Uitpas|PHPUnit_Framework_MockObject_MockObject
*/
private $uitpas;

Expand All @@ -16,7 +22,7 @@ class EventCardSystemsControllerTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->uitpas = $this->createMock(\CultureFeed_Uitpas::class);
$this->uitpas = $this->createMock(CultureFeed_Uitpas::class);
$this->controller = new EventCardSystemsController($this->uitpas);
}

Expand All @@ -27,15 +33,15 @@ public function it_can_get_card_systems_of_an_event()
{
$eventId = 'db93a8d0-331a-4575-a23d-2c78d4ceb925';

$cardSystem1 = new \CultureFeed_Uitpas_CardSystem();
$cardSystem1 = new CultureFeed_Uitpas_CardSystem();
$cardSystem1->id = 'card-system-1';
$cardSystem1->name = 'Card system 1';

$distributionKey1 = new \CultureFeed_Uitpas_DistributionKey();
$distributionKey1 = new CultureFeed_Uitpas_DistributionKey();
$distributionKey1->id = 'distribution-key-1';
$distributionKey1->name = 'Distribution key 1';

$distributionKey2 = new \CultureFeed_Uitpas_DistributionKey();
$distributionKey2 = new CultureFeed_Uitpas_DistributionKey();
$distributionKey2->id = 'distribution-key-2';
$distributionKey2->name = 'Distribution key 2';

Expand All @@ -44,15 +50,15 @@ public function it_can_get_card_systems_of_an_event()
$distributionKey2,
];

$cardSystem2 = new \CultureFeed_Uitpas_CardSystem();
$cardSystem2 = new CultureFeed_Uitpas_CardSystem();
$cardSystem2->id = 'card-system-2';
$cardSystem2->name = 'Card system 2';

$distributionKey3 = new \CultureFeed_Uitpas_DistributionKey();
$distributionKey3 = new CultureFeed_Uitpas_DistributionKey();
$distributionKey3->id = 'distribution-key-3';
$distributionKey3->name = 'Distribution key 3';

$distributionKey4 = new \CultureFeed_Uitpas_DistributionKey();
$distributionKey4 = new CultureFeed_Uitpas_DistributionKey();
$distributionKey4->id = 'distribution-key-4';
$distributionKey4->name = 'Distribution key 4';

Expand Down
Loading

0 comments on commit 84cacdc

Please sign in to comment.