This PR addresses the issue of duplicated code in the ParserTest.php file. The testParseWithEmptyNamesArray and testParseWithNonEmptyNamesArray methods contained similar blocks of code. To improve modularity and adhere to our coding standards, this code has been refactored into a separate, reusable function.
The common code between these two methods involved iterating over individuals parsed from a GEDCOM file, checking if they have names, and then formatting these names into a specific string format. This operation has been extracted into a new private method named generateOutputFromParsedGedcom.
Summary of Changes
Added a new private method generateOutputFromParsedGedcom in ParserTest.php that encapsulates the common logic for parsing a GEDCOM file, iterating over individuals, checking for non-empty names, and formatting these names into a string.
Refactored testParseWithEmptyNamesArray and testParseWithNonEmptyNamesArray methods to use the new generateOutputFromParsedGedcom method, reducing code duplication.
Ran the existing test suite to ensure all tests, including the refactored ones, still pass.
This refactoring makes the ParserTest.php file cleaner and more maintainable, and ensures our codebase adheres to good coding standards.
PR Feedback (click)
I created this PR to address this rule:
"Refactor large functions to be more modular."
Description
This PR addresses the issue of duplicated code in the
ParserTest.php
file. ThetestParseWithEmptyNamesArray
andtestParseWithNonEmptyNamesArray
methods contained similar blocks of code. To improve modularity and adhere to our coding standards, this code has been refactored into a separate, reusable function.The common code between these two methods involved iterating over individuals parsed from a GEDCOM file, checking if they have names, and then formatting these names into a specific string format. This operation has been extracted into a new private method named
generateOutputFromParsedGedcom
.Summary of Changes
generateOutputFromParsedGedcom
inParserTest.php
that encapsulates the common logic for parsing a GEDCOM file, iterating over individuals, checking for non-empty names, and formatting these names into a string.testParseWithEmptyNamesArray
andtestParseWithNonEmptyNamesArray
methods to use the newgenerateOutputFromParsedGedcom
method, reducing code duplication.This refactoring makes the
ParserTest.php
file cleaner and more maintainable, and ensures our codebase adheres to good coding standards.