Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStorz committed Sep 26, 2023
1 parent 67eadb5 commit 42f6c00
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 33 deletions.
6 changes: 2 additions & 4 deletions src/Command/FetchCensusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public function __construct(
CensusAPIService $apiService,
CensusGroupRepository $censusGroupRepository,
GroupTypeRepository $groupTypeRepository
)
{
) {
$this->apiService = $apiService;
$this->censusGroupRepository = $censusGroupRepository;
$this->groupTypeRepository = $groupTypeRepository;
Expand Down Expand Up @@ -54,7 +53,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$rawCensusGroups = $rawCensusData->getContent()['census_evaluations']['groups'];
foreach ($rawCensusGroups as $rawCensusGroup) {
$exists = $this->censusGroupRepository->findOneBy(['group_id' => $rawCensusGroup['group_id'], 'year' => $year]);
if(is_null($exists)) {
if (is_null($exists)) {
$groupsToAggregate[] = $rawCensusGroup['group_id'];
$this->mapRawCensusGroupToCensusGroup($rawCensusGroup, $year);
}
Expand All @@ -63,7 +62,6 @@ public function execute(InputInterface $input, OutputInterface $output)
}
// Aggregate Groups
foreach (array_unique($groupsToAggregate) as $groupId) {

}
return Command::SUCCESS;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Controller/Api/Apps/CensusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ class CensusController extends AbstractController
private CensusDataProvider $censusDataProvider;
private CensusFilterDataProvider $censusFilterDataProvider;

public function __construct (
public function __construct(
CensusDataProvider $censusDataProvider,
CensusFilterDataProvider $censusFilterDataProvider
)
{
) {
$this->censusDataProvider = $censusDataProvider;
$this->censusFilterDataProvider = $censusFilterDataProvider;
}
Expand Down Expand Up @@ -103,5 +102,4 @@ public function postFilterData(Group $group, CensusRequestData $censusRequestDat
$this->denyAccessUnlessGranted(PermissionVoter::VIEWER, $group);
return $this->json($this->censusFilterDataProvider->setFilterData($group, $censusRequestData));
}

}
2 changes: 1 addition & 1 deletion src/Controller/Api/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function createInvite(
}

if ($inviteDTO->getPermissionType() === PermissionVoter::OWNER) {
throw new ApiException(Response::HTTP_FORBIDDEN,'You may not add group Owners.');
throw new ApiException(Response::HTTP_FORBIDDEN, 'You may not add group Owners.');
}

if ($this->inviteService->inviteExists($group, $inviteDTO->getEmail())) {
Expand Down
18 changes: 10 additions & 8 deletions src/DTO/Mapper/CensusMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class CensusMapper
* @param int[] $relevantYears
* @return TableDTO
*/
public static function MapToCensusTable(StatisticGroup $statisticGroup, array $censusGroups, array $relevantYears) {
public static function MapToCensusTable(StatisticGroup $statisticGroup, array $censusGroups, array $relevantYears)
{
$dto = new TableDTO();
$dto->setId($statisticGroup->getId());
$dto->setName($statisticGroup->getName());
Expand Down Expand Up @@ -52,16 +53,16 @@ public static function MapToCensusTable(StatisticGroup $statisticGroup, array $c
$improvementVsLastYear = null;
$improvementVs3YearsAgo = null;
$improvementVsAvg5Years = null;
if(!is_null($totalCounts[count($totalCounts)-1])) {
if (!is_null($totalCounts[count($totalCounts)-2])) {
$improvementVsLastYear = (100 / $totalCounts[count($totalCounts)-2]) * $totalCounts[count($totalCounts)-1] - 100;
if (!is_null($totalCounts[count($totalCounts) - 1])) {
if (!is_null($totalCounts[count($totalCounts) - 2])) {
$improvementVsLastYear = (100 / $totalCounts[count($totalCounts) - 2]) * $totalCounts[count($totalCounts) - 1] - 100;
}
if (!is_null($totalCounts[count($totalCounts)-4])) {
$improvementVs3YearsAgo = (100 / $totalCounts[count($totalCounts)-4]) * $totalCounts[count($totalCounts)-1] - 100;
if (!is_null($totalCounts[count($totalCounts) - 4])) {
$improvementVs3YearsAgo = (100 / $totalCounts[count($totalCounts) - 4]) * $totalCounts[count($totalCounts) - 1] - 100;
}
}
if (!$incomplete) {
$improvementVsAvg5Years = (100/ (($totalCounts[0] + $totalCounts[1] + $totalCounts[2] + $totalCounts[3] + $totalCounts[4]) / 5)) * $totalCounts[count($totalCounts)-1] - 100;
$improvementVsAvg5Years = (100 / (($totalCounts[0] + $totalCounts[1] + $totalCounts[2] + $totalCounts[3] + $totalCounts[4]) / 5)) * $totalCounts[count($totalCounts) - 1] - 100;
}
$dto->setRelativeMemberCounts([$improvementVsLastYear, $improvementVs3YearsAgo, $improvementVsAvg5Years]);
return $dto;
Expand All @@ -72,7 +73,8 @@ public static function MapToCensusTable(StatisticGroup $statisticGroup, array $c
* @param CensusGroup[] $censusGroups
* @param int[] $relevantYears
*/
public static function MapToLineChart(StatisticGroup $statisticGroup, array $censusGroups, array $relevantYears) {
public static function MapToLineChart(StatisticGroup $statisticGroup, array $censusGroups, array $relevantYears)
{
$groupData = new DevelopmentWidgetDTO();
$absolute = [];
$relative = [];
Expand Down
1 change: 0 additions & 1 deletion src/DTO/Model/Apps/Census/GroupCensusDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,4 @@ public function setPtaFCount(int $pta_f_count): void
{
$this->pta_f_count = $pta_f_count;
}

}
1 change: 0 additions & 1 deletion src/DTO/Model/Apps/Census/MembersWidgetDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ public function setData(array $data): void
{
$this->data = $data;
}

}
35 changes: 22 additions & 13 deletions src/Service/DataProvider/CensusDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

class CensusDataProvider extends WidgetDataProvider
{

private CensusGroupRepository $censusGroupRepository;
private StatisticGroupRepository $statisticGroupRepository;
public function __construct(
Expand All @@ -43,7 +42,8 @@ public function __construct(
);
}

public function getPreviewData(Group $group) {
public function getPreviewData(Group $group)
{
$groups = $this->groupRepository->findAllRelevantSubGroupsByParentGroupId($group->getId(), ['Group::Abteilung', 'Group::Kantonalverband', 'Group::Region']); // Replace with group endpoint
$return = [
'm' => [
Expand Down Expand Up @@ -102,7 +102,8 @@ public function getPreviewData(Group $group) {
* @param int[] $groups
* @return StatisticGroup[]
*/
public function flattenGroupTree(array $groupIds) {
public function flattenGroupTree(array $groupIds)
{
$groups = [];
foreach ($groupIds as $groupId) {
$groups[] = $this->statisticGroupRepository->findOneBy(['id' => $groupId]);
Expand All @@ -121,7 +122,8 @@ public function flattenGroupTree(array $groupIds) {
* @param StatisticGroup $baseGroup
* @return StatisticGroup|null
*/
public function getNewGroupWithRelevantParent(StatisticGroup $baseGroup) {
public function getNewGroupWithRelevantParent(StatisticGroup $baseGroup)
{
if ($baseGroup->getGroupType()->getGroupType() === GroupType::DEPARTMENT) {
$clonedGroup = clone $baseGroup;
$relevantParent = $this->findHighestRelevantRegion($clonedGroup);
Expand All @@ -141,7 +143,8 @@ public function getNewGroupWithRelevantParent(StatisticGroup $baseGroup) {
return $baseGroup;
}

public function findHighestRelevantRegion(StatisticGroup $group) {
public function findHighestRelevantRegion(StatisticGroup $group)
{
$parentGroup = $group->getParentGroup();
if (is_null($parentGroup)) {
return $group;
Expand All @@ -157,18 +160,19 @@ public function findHighestRelevantRegion(StatisticGroup $group) {
* @param TableDTO[] $dtos
* @return void
*/
public function sortDTOs(array $dtos) {
public function sortDTOs(array $dtos)
{
$regions = array_filter($dtos, function ($dto) {
return $dto->getType() === GroupType::REGION;
});
$departments = array_filter($dtos, function ($dto) {
return $dto->getType() === GroupType::DEPARTMENT;
});
usort($regions, function (TableDTO $a, TableDTO $b) {
return strcmp($a->getName(),$b->getName());
return strcmp($a->getName(), $b->getName());
});
usort($departments, function (TableDTO $a, TableDTO $b) {
return strcmp($a->getName(),$b->getName());
return strcmp($a->getName(), $b->getName());
});
$return = [];
foreach ($regions as $region) {
Expand All @@ -188,14 +192,17 @@ public function sortDTOs(array $dtos) {
return $return;
}

public function getRelevantGroups(Group $group) {
$groupIds = array_filter($this->statisticGroupRepository->findAllRelevantChildGroups($group->getId()), function ($id) use ($group) { // We need to filter because the function also returns the group itself
public function getRelevantGroups(Group $group)
{
$groupIds = array_filter($this->statisticGroupRepository->findAllRelevantChildGroups($group->getId()), function ($id) use ($group) {
// We need to filter because the function also returns the group itself
return !($id === $group->getId());
});
return $this->flattenGroupTree($groupIds);
}

public function getTableData(Group $group, CensusRequestData $censusRequestData) {
public function getTableData(Group $group, CensusRequestData $censusRequestData)
{
$flattenedGroups = $this->getRelevantGroups($group);

$dataTransferObjects = [];
Expand All @@ -209,7 +216,8 @@ public function getTableData(Group $group, CensusRequestData $censusRequestData)
];
}

public function getDevelopmentData(Group $group, CensusRequestData $censusRequestData) {
public function getDevelopmentData(Group $group, CensusRequestData $censusRequestData)
{
$relevantGroups = $this->getRelevantGroups($group);

$absolute = [];
Expand Down Expand Up @@ -264,7 +272,8 @@ public function getMembersData(Group $group, CensusRequestData $censusRequestDat
return $return;
}

public function getTreemapData(Group $group, CensusRequestData $censusRequestData) {
public function getTreemapData(Group $group, CensusRequestData $censusRequestData)
{
$relevantGroups = $this->getRelevantGroups($group);
$return = [];
$colors = ['#EEE09F', '#3BB5DC', '#9A7A54', '#1DA650', '#DD1F19', '#d9b826', '#929292'];
Expand Down
2 changes: 1 addition & 1 deletion src/Service/DataProvider/CensusFilterDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getFilterData(Group $group): CensusFilterDTO
return $this->mapGroupSettingsToCensusFilter($groupSettings);
}

private function mapGroupSettingsToCensusFilter(GroupSettings $groupSettings):CensusFilterDTO
private function mapGroupSettingsToCensusFilter(GroupSettings $groupSettings): CensusFilterDTO
{
$filterData = new CensusFilterDTO();
$filterData->setFilterFemales($groupSettings->getCensusFilterFemales() ?? false);
Expand Down

0 comments on commit 42f6c00

Please sign in to comment.