Skip to content

Commit

Permalink
style: fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joelbeckmann committed Jan 21, 2025
1 parent 48f562f commit 507e55e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Controller/CodebookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function datasetMatrixAction(Request $request, string $uuid): JsonRespons
private function codebookCollectionToJsonArray(?Collection $codebook): ?array
{
$jsonCodebook = null;
if ($codebook && is_iterable($codebook)) {
if ($codebook) {
$jsonCodebook = [];
foreach ($codebook as $var) {
$jsonCodebook['variables'][] = [
Expand Down
44 changes: 24 additions & 20 deletions src/Controller/FileManagementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,36 @@ public function submitSavAction(string $fileId): JsonResponse
$this->logger->debug("Enter FileManagementController::previewSavAction with [FileId: {$fileId}]");
$dataset = $this->em->find(Dataset::class, $fileId);
$data = null;

if ($dataset) {
$data = $this->savImportable->savToArray($dataset);
}
if (isset($dataset, $data) && !empty($data)) {
if (is_iterable($data) && key_exists('codebook', $data)) {
foreach ($data['codebook'] as $var) {
$this->em->persist(
DatasetVariables::createNew(
$dataset,
$var['id'],
$var['name'],
$var['label'],
$var['itemText'],
$var['values'],
$var['missings'],
)
);
}
$this->em->flush();
if (key_exists('records', $data)) {
$this->crud->saveDatasetMatrix($data['records'], $dataset->getId());
}

if (!isset($dataset) or empty($data)) {
return new JsonResponse([], Response::HTTP_UNPROCESSABLE_ENTITY);
}

if (key_exists('codebook', $data)) {
foreach ($data['codebook'] as $var) {
$this->em->persist(
DatasetVariables::createNew(
$dataset,
$var['id'],
$var['name'],
$var['label'],
$var['itemText'],
$var['values'],
$var['missings'],
)
);
}
$this->em->flush();
if (key_exists('records', $data)) {
$this->crud->saveDatasetMatrix($data['records'], $dataset->getId());
}
}

return new JsonResponse($data ?? [], $data != null ? Response::HTTP_OK : Response::HTTP_UNPROCESSABLE_ENTITY);
return new JsonResponse($data, Response::HTTP_OK);
}

#[Route(path: '/preview/csv/{fileId}', name: 'preview-csv', methods: ['POST'])]
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ public function documentationAction(string $uuid, Request $request): Response

$formData = $form->getData();
$currentCreators = $this->em->getRepository(CreatorMetaDataGroup::class)->findBy(['basicInformation' => $basicInformation]);
if (is_iterable($currentCreators)) {
foreach ($currentCreators as $currentCreator) {
$this->em->remove($currentCreator);
}

foreach ($currentCreators as $currentCreator) {
$this->em->remove($currentCreator);
}

$newCreators = $formData->getCreators();
if (!$form->getData()->getCreators() instanceof Collection) {
throw new \Error('Creators is not a collection');
Expand Down
34 changes: 16 additions & 18 deletions src/Security/Authentication/OauthAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,23 @@ public function authenticate(Request $request): SelfValidatingPassport
$user = $this->crud->readById(DataWizUser::class, $keycloakUser->getId());
$kcArray = $keycloakUser->toArray();

if (is_iterable($kcArray)) {
if ($user === null) {
$user = new DataWizUser();
$user->setId(new Uuid($keycloakUser->getId()));
$user->setRoles([UserRoles::USER]);
$user->setDateRegistered(new \DateTime());
}
if (key_exists('email', $kcArray)) {
$user->setEmail($kcArray['email']);
}
if (key_exists('given_name', $kcArray)) {
$user->setFirstname($kcArray['given_name']);
}
if (key_exists('family_name', $kcArray)) {
$user->setLastname($kcArray['family_name']);
}
$user->setLastLogin(new \DateTime());
$this->crud->update($user);
if ($user === null) {
$user = new DataWizUser();
$user->setId(new Uuid($keycloakUser->getId()));
$user->setRoles([UserRoles::USER]);
$user->setDateRegistered(new \DateTime());
}
if (key_exists('email', $kcArray)) {
$user->setEmail($kcArray['email']);
}
if (key_exists('given_name', $kcArray)) {
$user->setFirstname($kcArray['given_name']);
}
if (key_exists('family_name', $kcArray)) {
$user->setLastname($kcArray['family_name']);
}
$user->setLastLogin(new \DateTime());
$this->crud->update($user);

return $user;
})
Expand Down

0 comments on commit 507e55e

Please sign in to comment.