Extract Method Pattern - Reduce complexity violations (C901, PLR0912, PLR0915) in complex functions by breaking them into smaller, focused helper functions while maintaining exact functionality.
- Original Stats: 56 statements, C901/PLR0915 violations
- Final Stats: ~15 statements (orchestration only)
- Helper Functions: 6 extracted functions
_validate_devcontainer_path()- Input validation_check_devcontainer_exists()- File existence check_create_devcontainer_directories()- Directory creation_write_devcontainer_content()- Content writing_compute_content_diff()- Diff computation_check_content_unchanged()- Change detection
- Original Stats: 61 statements, C901/PLR0915 violations
- Final Stats: ~10 statements (orchestration only)
- Helper Functions: 4 extracted functions
_extract_pr_title_from_content()- Title extraction_build_pr_header_section()- Header construction_build_pr_content_section()- Content formatting_build_pr_footer_section()- Footer generation
- Original Stats: 63 statements, C901/PLR0915 violations
- Final Stats: ~15 statements (orchestration only)
- Helper Functions: 6 extracted functions
_read_plan_input_content()- Input content reading_process_plan_keywords_and_languages()- Keyword/language processing_generate_plan_command_suggestions()- Command generation_build_plan_assumptions()- Assumptions creation_build_plan_environment_needs()- Environment needs_build_plan_title()- Title generation
- Single Responsibility Principle: Each helper function has one clear purpose
- Data Flow: Main functions orchestrate, helpers process specific aspects
- Error Handling: Preserved all original error handling and edge cases
- Return Values: Maintained exact return value structures
- Private helper functions prefixed with
_ - Descriptive names indicating specific functionality
- Consistent parameter naming across related functions
- Reduced Cyclomatic Complexity: From C901 violations to simple orchestration
- Reduced Statement Count: From PLR0915 violations to manageable sizes
- Improved Readability: Clear separation of concerns
- Enhanced Maintainability: Easier to test and modify individual aspects
ruff check --select=C901,PLR0912,PLR0915 autorepro/env.py autorepro/pr.py autorepro/utils/plan_processing.py
All checks passed!- Phase 2 Tests: 123/123 ✅ (100% pass rate)
- Full Test Suite: 540/540 ✅ (100% pass rate)
- No Regressions: All functionality preserved
- Config Shadowing Issue: Fixed NameError in
cmd_execandcmd_prwhereconfigparameter was shadowing global config import - Import Dependencies: Added
datetimeimport topr.pyfor timestamp functionality
| File | Function | Original Lines | Final Lines | Helper Functions | Complexity Reduction |
|---|---|---|---|---|---|
env.py |
write_devcontainer() |
56 | ~15 | 6 | C901, PLR0915 → ✅ |
pr.py |
build_pr_body() |
61 | ~10 | 4 | C901, PLR0915 → ✅ |
plan_processing.py |
process_plan_input() |
63 | ~15 | 6 | C901, PLR0915 → ✅ |
Total: 16 helper functions extracted, 3 violations eliminated
- ✅ Extract Method Pattern Applied: All 3 complex functions refactored
- ✅ Complexity Violations Eliminated: C901, PLR0915 violations resolved
- ✅ Functionality Preserved: 100% test pass rate maintained
- ✅ Code Quality Improved: Better separation of concerns and readability
- ✅ No Regressions: All existing functionality works exactly as before
Ready to proceed to Phase 3: Simple Argument Fixes - targeting remaining PLR0913 violations (too many arguments) in report.py and process.py functions.
Phase 2 completed successfully on $(date). All complex function refactoring objectives achieved.