Skip to content

Conversation

@JanTvrdik
Copy link

Summary

  • Use a finally block in removeTemporaryFiles() to ensure $this->temporaryFiles is always cleared after removal
  • Prevents attempting to delete the same files multiple times when the method is called from both the shutdown function and destructor
  • Added test assertions to verify the array is cleared after calling removeTemporaryFiles()

Test plan

  • Existing tests pass
  • Added assertions to verify temporaryFiles array is emptied after removal

Use a finally block in removeTemporaryFiles() to ensure the
temporaryFiles array is always cleared after removal, even if
an exception occurs. This prevents attempting to delete the
same files multiple times when the method is called from both
the shutdown function and destructor.
Copilot AI review requested due to automatic review settings January 27, 2026 12:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the robustness of temporary file cleanup by using a finally block to ensure the temporaryFiles array is always cleared, even if an exception occurs during file deletion. This prevents potential issues where the same files could be attempted to be deleted multiple times when removeTemporaryFiles() is called from both the shutdown function and destructor.

Changes:

  • Wrapped the file deletion loop in a try-finally block to guarantee array cleanup
  • Added test assertions to verify the temporaryFiles array is emptied after calling removeTemporaryFiles()

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Knp/Snappy/AbstractGenerator.php Added try-finally block in removeTemporaryFiles() to ensure temporaryFiles array is always cleared
tests/Knp/Snappy/AbstractGeneratorTest.php Added assertions to verify array is cleared after removal in both cleanup test methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

$remove = new ReflectionMethod($generator, 'removeTemporaryFiles');
$remove->invoke($generator);

$this->assertCount(0, $files->getValue($generator));
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

Consider adding a test case that verifies the temporaryFiles array is cleared even when unlink throws an exception. This would fully validate the purpose of the finally block introduced in this PR. The test could mock unlink to throw an exception and then verify that temporaryFiles is still emptied despite the exception.

Copilot uses AI. Check for mistakes.
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.

2 participants