Returning the path to PHP pages for a layout and a view, if they exist
Yes, there is a way:


Identify all parts that differ in the two functions.
Write a new function that takes each of these differences as a parameter.
From the existing functions, call the new function, passing the appropriate values as parameters.
Compare the resulting code with the original code to see whether the refactoring was worth it.


Hint:


   In this case, the differing parts are configKey, fileName, suffix and errorMessage.