dproofreaders icon indicating copy to clipboard operation
dproofreaders copied to clipboard

Resolve duplicate function names

Open cpeel opened this issue 1 year ago • 0 comments

.php pages often define their own functions that are used only within the page. Functions are all defined in the same public namespace in PHP and defining a second function name is an error. But because .php pages are not included in other pages this is not actually a problem.

phpstan, however, doesn't know this and has gotten confused by it. As we add more type definitions to the codebase we're likely to run into this more. We can fix this by either:

  1. making function names unique across the codebase
  2. using PHP namespaces so they won't collide
  3. moving functions into classes -- where appropriate

Here are the list of the current duplicate function names grouped into common problem-children.

Site Admin

These files were likely copied from one another -- or a common ancestor.

tools/site_admin/copy_pages.php:function display_form(
tools/site_admin/delete_pages.php:function display_form
tools/site_admin/project_jump.php:function display_form

tools/site_admin/copy_pages.php:function do_stuff(
tools/site_admin/delete_pages.php:function do_stuff(
tools/site_admin/project_jump.php:function do_stuff(

tools/site_admin/copy_pages.php:function error_and_die(
tools/site_admin/project_jump.php:function error_and_die(
tools/site_admin/manage_site_word_lists.php:function _handle_action(
tools/site_admin/show_common_words_from_project_word_lists.php:function _handle_action(

Quizzes

quiz/generic/wizard/output.php:function enl(
quiz/generic/wizard/output_quiz.php:function enl(

quiz/generic/wizard/quiz_pages.php:function evalstart()
quiz/generic/wizard/messages.php:function evalstart()

quiz/generic/wizard/quiz_pages.php:function filltext(
quiz/generic/wizard/messages.php:function filltext(

quiz/generic/wizard/output.php:function make_output()
quiz/generic/wizard/output_quiz.php:function make_output()

quiz/generic/wizard/output.php:function sdbsn($x)
quiz/generic/wizard/output_quiz.php:function sdbsn($x)

quiz/generic/wizard/output.php:function ssqs($x)
quiz/generic/wizard/output_quiz.php:function ssqs($x)

My Projects / My Suggestions

my_suggestions.php was copied from my_projects.php

tools/proofers/my_suggestions.php:function get_table_column_specs()
tools/proofers/my_projects.php:function get_table_column_specs()

tools/proofers/my_suggestions.php:function get_view_options($username)
tools/proofers/my_projects.php:function get_view_options($username)

tools/proofers/my_suggestions.php:function output_link_box($username, $verbose)
tools/proofers/my_projects.php:function output_link_box($username)

tools/proofers/my_suggestions.php:function show_page_menu(
tools/proofers/my_projects.php:function show_page_menu(

tools/proofers/my_suggestions.php:function show_headings($colspecs, $username, $anchor)
tools/proofers/my_projects.php:function show_headings($colspecs, $sorting, $username, $sort_name, $anchor)

Exception handlers

We define two exception handlers, one for test and one for prod, that are different for API vs web and bootstrap.inc is common code that sets them up.

api/index.php:function production_exception_handler($exception)
pinc/base.inc:function production_exception_handler($exception)

api/index.php:function test_exception_handler($exception)
pinc/base.inc:function test_exception_handler($exception)

Forum test abstraction

forum_interface.inc conditionally includes one of forum_interface_phpbb3.inc or forum_interface_json.inc -- the latter is only used during testing. By definition the latter two files define the exact same set of functions. We could punt this by telling phpstan to ignore forum_interface_json.inc.

Misc

tools/project_manager/remote_file_manager.php:function fatal_error($message)
tools/changestate.php:function fatal_error($msg)
stats/includes/common.inc:function get_username_for_uid($u_id)
tasks.php:function get_username_for_uid($u_id)
tools/project_manager/generate_post_files.php:function output_page_header($project)
tools/changestate.php:function output_page_header()

cpeel avatar Aug 18 '24 04:08 cpeel