Returning the path to PHP pages for a layout and a view, if they exist I have these two functions.

function layout($layout) {
    $layout = Config::get('path/layouts') . '/' . $layout . '.layout.php';
    if (!file_exists($layout)) {
        throw new CoreException($layout . ' layout is not found');
    }
    return $layout;
}

function page($page) {
    $page = Config::get('path/pages') . '/' . $page. '.view.php';
    if (!file_exists($page)) {
        throw new CoreException($page . ' page is not found');
    }
    return $page;
}


Is there a way to avoid repeated parts?
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.