Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce data transfer objects. #2306

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

nickygerritsen
Copy link
Member

This seems like a big PR (and it probably is), but basically what it does is it changes many (but not all, it's only a start) of our 'magic' arrays into objects, mostly using PHP 8's new constructor property promotion. This has some advantages:

  • Return types are typed, so your IDE, the PHP parser and PHPStan can (and will) complain if you do something strange.
  • For example for the submissions filter it actually tells you in the DTO object what you can filter on, without you needing to check some docblock, or even worse the filter code.
  • For API return types we can move a lot of the YAML configuration to actual PHP code, making it more typesafe again.

Most of these changes are for the API, but not all. The API part should be extensively tested by CI, and the few UI changes should be OK.

@vmcj and me were discussing that, if this gets approval soon ™️ , he might want to run it at SWERC to see if it works. It's easy to rollback IMHO and then we will find out soon enough if everything works. But I can also understand people might find this risky. But then, given the upcoming contest season for us, I'm not sure when to merge.

Note: I created separate commits so you can see what I did but in the end I will squash everything.

*/
protected function getAwardsData(Request $request, string $requestedType = null): ?array
protected function getContestAndScoreboard(Request $request): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check details but this change looks fishy to me...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git diff is horrible. I extracted a method since I changed the existing method that either returned one award or an array of awards in two methods

'filename' => $k,
'content' => base64_encode($inout[$k]),
];
$result[] = new JudgehostFile(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result[] = new JudgehostFile(
$result[] = new JudgehostFile(

'content' => base64_encode($file->getFileContent()),
'is_executable' => $file->isExecutable(),
];
$result[] = new JudgehostFile(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$result[] = new JudgehostFile(
$result[] = new JudgehostFile(

Copy link
Member

@vmcj vmcj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I find this an improvement. Do we have a codecov report somewhere how much of the diff is covered by tests?

@nickygerritsen
Copy link
Member Author

Overall I find this an improvement. Do we have a codecov report somewhere how much of the diff is covered by tests?

First of all, seems codecov.io doesn't handle PR's from forks currently since we moved it to Github, but I ran it locally. I can only tell something about the API easily. For unit tests, we don't test:

  • contests/<x>/state, but we test that during integration. Could still add it to a test.
  • contests/<x>/event-feed, but again tested during integration. Could still add it to a test, at least with stream=0.
  • contests/<x>/status, which we should maybe add.
  • contests/<x>/samples, which we should maybe add a test for.
  • Almost the whole JudgehostController, but we have integration tests for it.
  • contests/<x>/judgements/<x>, but the list we do. Maybe add a test for the singular as well?
  • POSTing to configure languages.
  • The getRuntimeAsScoreTiebreaker mode for the scoreboard recently added.
  • contests/<x>/submissions/<x>/files and contests/<x>/submissions/<x>/source-code'. We should probably add some tests.
  • Adding teams, groups and organizations.

For the purpose of this PR I think we test almost everything, but this list might be a good start to improve our API coverage.

@nickygerritsen nickygerritsen force-pushed the data-transfer-objects branch 2 times, most recently from a55f1bc to d162ae1 Compare February 9, 2024 10:11
@nickygerritsen nickygerritsen added this pull request to the merge queue Feb 9, 2024
Merged via the queue into DOMjudge:main with commit af00d7e Feb 9, 2024
21 checks passed
@nickygerritsen nickygerritsen deleted the data-transfer-objects branch February 9, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants