Skip to content

Commit

Permalink
phpstan level 8
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst committed Nov 22, 2024
1 parent 9f26b9c commit e072fe2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
8 changes: 6 additions & 2 deletions Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function create(Request $request): Response

if ($form->isSubmitted() && $form->isValid()) {
try {
$this->manageService->create($sharedProject, $form->get('password')->getData());
/** @var string $password */
$password = $form->get('password')->getData();
$this->manageService->create($sharedProject, $password);
$this->flashSuccess('action.update.success');

return $this->redirectToRoute('manage_shared_project_timesheets');
Expand Down Expand Up @@ -127,7 +129,9 @@ public function update(SharedProjectTimesheet $sharedProject, string $shareKey,

if ($form->isSubmitted() && $form->isValid()) {
try {
$this->manageService->update($sharedProject, $form->get('password')->getData());
/** @var string $password */
$password = $form->get('password')->getData();
$this->manageService->update($sharedProject, $password);
$this->flashSuccess('action.update.success');

return $this->redirectToRoute('manage_shared_project_timesheets');
Expand Down
8 changes: 6 additions & 2 deletions Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public function indexAction(#[MapEntity(mapping: ['shareKey' => 'shareKey'])] Sh
return $this->renderCustomerView($sharedPortal, $request);
}

return $this->renderProjectView($sharedPortal, $sharedPortal->getProject(), $request);
if ($sharedPortal->getProject() !== null) {
return $this->renderProjectView($sharedPortal, $sharedPortal->getProject(), $request);
}

throw $this->createNotFoundException('Invalid shared portal: neither customer nor project is set');
}

#[Route(path: '/auth/shared-project-timesheets/customer/{customer}/{shareKey}/project/{project}', methods: ['GET', 'POST'])]
Expand Down Expand Up @@ -161,7 +165,7 @@ private function renderProjectView(SharedProjectTimesheet $sharedProject, Projec
? $this->viewService->getMonthlyStats($sharedProject, $year, $month, $project) : null;

// we cannot call $this->getDateTimeFactory() as it throws a AccessDeniedException for anonymous users
$timezone = $project->getCustomer()->getTimezone() ?? date_default_timezone_get();
$timezone = $project->getCustomer()?->getTimezone() ?? date_default_timezone_get();
$date = new \DateTimeImmutable('now', new \DateTimeZone($timezone));

$stats = $this->projectStatisticService->getBudgetStatisticModel($project, $date);
Expand Down
8 changes: 8 additions & 0 deletions Model/TimeRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public static function fromTimesheet(Timesheet $timesheet, string $mergeMode = R
throw new \InvalidArgumentException("Invalid merge mode given: $mergeMode");
}

if ($timesheet->getBegin() === null) {
throw new \InvalidArgumentException('Timesheet without begin date is not supported');
}

if ($timesheet->getUser() === null) {
throw new \InvalidArgumentException('Timesheet without user is not supported');
}

$record = new TimeRecord($timesheet->getBegin(), $timesheet->getUser(), $mergeMode);
$record->addTimesheet($timesheet);

Expand Down
4 changes: 4 additions & 0 deletions Repository/SharedProjectTimesheetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public function getProjects(SharedProjectTimesheet $sharedProject): array
return [$sharedProject->getProject()];
}

if ($sharedProject->getCustomer() === null) {
throw new \InvalidArgumentException('Unsupported, needs a customer');
}

/** @var ProjectRepository $projectRepository */
$projectRepository = $this->_em->getRepository(Project::class); // @phpstan-ignore varTag.type

Expand Down
2 changes: 1 addition & 1 deletion Service/ManageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function create(SharedProjectTimesheet $sharedPortal, ?string $password =
if ($sharedPortal->getShareKey() === null) {
$i = 0;
do {
$newKey = substr(preg_replace('/[^A-Za-z0-9]+/', '', $this->getUuidV4()), 0, 20);
$newKey = substr(preg_replace('/[^A-Za-z0-9]+/', '', $this->getUuidV4()), 0, 20); // @phpstan-ignore argument.type
$existingEntry = $this->repository->findByShareKey($newKey);

// make sure we exit in case we cannot generate a new key
Expand Down
6 changes: 6 additions & 0 deletions Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ public function getTimeRecords(SharedProjectTimesheet $sharedProject, int $year,
$timeRecords = [];
$mergeMode = $sharedProject->getRecordMergeMode();
foreach ($timesheets as $timesheet) {
if ($timesheet->getBegin() === null || $timesheet->getUser() === null) {
continue;
}
$dateKey = $timesheet->getBegin()->format('Y-m-d');
if (!\array_key_exists($dateKey, $timeRecords)) {
$timeRecords[$dateKey] = [];
}

$userKey = preg_replace('/[^a-z0-9]/', '', strtolower($timesheet->getUser()->getDisplayName()));
if ($userKey === null) {
continue;
}
if ($mergeMode !== RecordMergeMode::MODE_NONE) {
// Assume that records from one user will be merged into one
if (!\array_key_exists($userKey, $timeRecords[$dateKey])) {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ includes:
- %rootDir%/../phpstan/conf/bleedingEdge.neon

parameters:
level: 7
level: 8
excludePaths:
- vendor/(?)
- tests/(?)
Expand Down

0 comments on commit e072fe2

Please sign in to comment.