Child pages
  • Incorrect type comments [5.2.2-B1]
Skip to end of metadata
Go to start of metadata

Each variable in code has associated type, that can be automatically determined by static code analysis (e.g. IDEs) tools by inspecting from where variable came from. In some cases however, e.g. when class factories are used, type can't be determined and type comment looking like this needs to be added:

/** @var ClassName $variable */
$variable = get_object_from_somewhere();

Adding type comment is not a problem, but how it's added is. In-Portal was initially developed using Zend Studio 5 (IDE) and in there type comments looked like this:

$variable = get_object_from_somewhere();
/* @var $variable ClassName */

This is a problem today, because such comments are recognized only by supper intelligent IDEs (e.g. PhpStorm) and are totally useless for most other static code analysis tools.

Luckily recently I've developed "CodingStandard.Commenting.TypeComment" sniff (see https://github.com/aik099/CodingStandard/issues/85 and https://github.com/aik099/CodingStandard/issues/77), that will automatically find and transform type comments into correct format. Here is report from running that sniff alone one the In-Portal code plus all modules:

PHP CODE SNIFFER REPORT SUMMARY
----------------------------------------------------------------------
FILE                                                  ERRORS  WARNINGS
----------------------------------------------------------------------
...in-bulletin/units/topics/topics_event_handler.php  13      0
...in-bulletin/units/topics/topics_tag_processor.php  3       0
...-bulletin/units/poll_comments/poll_comment_eh.php  6       0
...modules/in-bulletin/units/helpers/post_helper.php  2       0
......../modules/in-bulletin/units/polls/poll_eh.php  5       0
......../modules/in-bulletin/units/polls/poll_tp.php  3       0
...tin/units/private_messages/private_message_tp.php  5       0
...tin/units/private_messages/private_message_eh.php  11      0
.../private_message_body/private_message_body_eh.php  3       0
......../modules/in-bulletin/units/posts/post_tp.php  11      0
......../modules/in-bulletin/units/posts/post_eh.php  18      0
..................../modules/in-bulletin/install.php  1       0
........./modules/custom/units/widgets/widget_tp.php  2       0
........./modules/custom/units/widgets/widget_eh.php  5       0
...s/custom/units/sections/products/e_product_eh.php  1       0
...s/custom/units/sections/articles/e_article_eh.php  1       0
...modules/custom/units/sections/links/e_link_eh.php  1       0
...modules/custom/units/sections/users/e_user_eh.php  1       0
...modules/custom/units/sections/users/e_user_tp.php  1       0
...ustom/units/sections/categories/e_category_eh.php  1       0
........................./modules/custom/install.php  1       0
...ommerce/units/products/products_event_handler.php  21      0
...ommerce/units/products/products_tag_processor.php  8       0
...rencies/payment_type_currencies_event_handler.php  1       0
...s/in-commerce/units/downloads/download_helper.php  1       0
...affiliate_plans/affiliate_plans_event_handler.php  2       0
...s/discount_items/discount_items_tag_processor.php  1       0
...rce/units/currencies/currencies_tag_processor.php  1       0
...rce/units/currencies/currencies_event_handler.php  5       0
...merce/units/addresses/addresses_event_handler.php  13      0
...merce/units/addresses/addresses_tag_processor.php  2       0
...rce/units/shipping_quote_engines/intershipper.php  2       0
...e_engines/shipping_quote_engine_event_handler.php  4       0
...ng_quote_engines/custom_shipping_quote_engine.php  1       0
...ipping_quote_engines/shipping_quote_collector.php  4       0
...in-commerce/units/shipping_quote_engines/usps.php  6       0
...commerce/units/helpers/bank_lv_currency_rates.php  1       0
...in-commerce/units/helpers/frny_currency_rates.php  1       0
...ules/in-commerce/units/helpers/currency_rates.php  2       0
.../in-commerce/units/helpers/ecb_currency_rates.php  1       0
...odules/in-commerce/units/helpers/order_helper.php  4       0
...s/in-commerce/units/zones/zones_tag_processor.php  5       0
...s/in-commerce/units/zones/zones_event_handler.php  5       0
...ommerce/units/brackets/brackets_tag_processor.php  3       0
...ommerce/units/brackets/brackets_event_handler.php  10      0
...ons/product_option_combinations_event_handler.php  13      0
...ommerce/units/shipping/shipping_tag_processor.php  6       0
...ommerce/units/shipping/shipping_event_handler.php  7       0
...commerce/units/destinations/dst_event_handler.php  5       0
...its/manufacturers/manufacturers_event_handler.php  4       0
...its/taxesdestinations/taxes_dst_event_handler.php  8       0
...-commerce/units/reports/reports_event_handler.php  2       0
...-commerce/units/reports/reports_tag_processor.php  1       0
...rce/units/gateways/gw_classes/google_checkout.php  22      0
...n-commerce/units/gateways/gw_classes/ideal_nl.php  6       0
...mmerce/units/gateways/gw_classes/authorizenet.php  3       0
...mmerce/units/gateways/gw_classes/rightconnect.php  1       0
...merce/units/gateways/gw_classes/paypal_direct.php  2       0
...n-commerce/units/gateways/gw_classes/worldpay.php  2       0
...commerce/units/gateways/gw_classes/paymentech.php  2       0
...in-commerce/units/gateways/gw_classes/gw_base.php  2       0
...sses/notify_scripts/google_checkout_shippings.php  2       0
...classes/notify_scripts/google_checkout_notify.php  1       0
...erce/units/gateways/gw_classes/sella_guestpay.php  2       0
.../in-commerce/units/gateways/gw_classes/paypal.php  4       0
...s/in-commerce/units/gateways/gw_tag_processor.php  2       0
...s/in-commerce/units/gateways/gw_event_handler.php  1       0
...-commerce/units/pricing/pricing_event_handler.php  5       0
...-commerce/units/pricing/pricing_tag_processor.php  2       0
...s/shipping_costs/shipping_costs_event_handler.php  11      0
...ans_items/affiliate_plans_items_tag_processor.php  1       0
...les/in-commerce/units/orders/order_calculator.php  2       0
.../modules/in-commerce/units/orders/orders_item.php  3       0
...in-commerce/units/orders/orders_event_handler.php  90      0
...odules/in-commerce/units/orders/order_manager.php  2       0
...in-commerce/units/orders/orders_tag_processor.php  22      0
...ate_payments/affiliate_payments_event_handler.php  6       0
...merce/units/discounts/discounts_event_handler.php  1       0
.../units/gift_certificates/gift_certificates_eh.php  6       0
.../units/gift_certificates/gift_certificates_tp.php  1       0
...product_options/product_options_event_handler.php  1       0
...product_options/product_options_tag_processor.php  6       0
...units/payment_type/payment_type_event_handler.php  6       0
...-commerce/units/coupons/coupons_event_handler.php  6       0
...ackets/affiliate_plans_brackets_event_handler.php  3       0
...ackets/affiliate_plans_brackets_tag_processor.php  1       0
...units/coupon_items/coupon_items_tag_processor.php  1       0
...s/in-commerce/units/taxes/taxes_tag_processor.php  5       0
...s/in-commerce/units/taxes/taxes_event_handler.php  3       0
...s/in-commerce/units/files/files_event_handler.php  5       0
...rce/units/affiliates/affiliates_event_handler.php  17      0
...rce/units/affiliates/affiliates_tag_processor.php  4       0
...e/units/order_items/order_items_tag_processor.php  14      0
...e/units/order_items/order_items_event_handler.php  10      0
...iate_payment_types/affiliate_payment_types_tp.php  2       0
...t_types/affiliate_payment_types_event_handler.php  3       0
..................../modules/in-commerce/install.php  1       0
.........../modules/in-commerce/install/upgrades.php  1       0
...in-link/units/listings/listings_event_handler.php  11      0
...in-link/units/listings/listings_tag_processor.php  5       0
...link/units/link_validation/link_validation_eh.php  8       0
...odules/in-link/units/links/link_tag_processor.php  15      0
...dules/in-link/units/links/links_event_handler.php  14      0
...its/listing_types/listing_types_tag_processor.php  2       0
...its/listing_types/listing_types_event_handler.php  1       0
......................../modules/in-link/install.php  1       0
...in-news/units/articles/articles_event_handler.php  13      0
......................../modules/in-news/install.php  1       0
...lated_searches/related_searches_event_handler.php  1       0
................../core/units/content/content_eh.php  9       0
................../core/units/content/content_tp.php  1       0
........./core/units/groups/groups_event_handler.php  1       0
............../core/units/filters/item_filter_tp.php  2       0
............../core/units/filters/item_filter_eh.php  4       0
............../core/units/favorites/favorites_eh.php  4       0
........./core/units/visits/visits_event_handler.php  2       0
........./core/units/visits/visits_tag_processor.php  2       0
...e/units/permissions/permissions_tag_processor.php  7       0
...e/units/permissions/permissions_event_handler.php  6       0
...units/promo_block_groups/promo_block_group_tp.php  2       0
...units/promo_block_groups/promo_block_group_eh.php  2       0
......./core/units/modules/modules_event_handler.php  4       0
......./core/units/modules/modules_tag_processor.php  6       0
...ore/units/statistics/statistics_event_handler.php  1       0
...ore/units/statistics/statistics_tag_processor.php  4       0
..................../core/units/themes/themes_eh.php  3       0
........./core/units/themes/themes_tag_processor.php  1       0
......./core/units/reviews/reviews_event_handler.php  18      0
......./core/units/reviews/reviews_tag_processor.php  11      0
........./core/units/spam_reports/spam_report_tp.php  3       0
........./core/units/spam_reports/spam_report_eh.php  5       0
...its/config_search/config_search_event_handler.php  3       0
....................../core/units/pdf/pdf_helper.php  1       0
...ore/units/helpers/controls/edit_picker_helper.php  5       0
....../core/units/helpers/controls/minput_helper.php  5       0
.............../core/units/helpers/themes_helper.php  5       0
................./core/units/helpers/menu_helper.php  2       0
............../core/units/helpers/modules_helper.php  2       0
................./core/units/helpers/user_helper.php  7       0
................./core/units/helpers/cron_helper.php  3       0
............/core/units/helpers/recursive_helper.php  3       0
................./core/units/helpers/page_helper.php  5       0
............../core/units/helpers/captcha_helper.php  1       0
............../core/units/helpers/navigation_bar.php  2       0
............../core/units/helpers/geocode_helper.php  1       0
............./core/units/helpers/priority_helper.php  2       0
............./core/units/helpers/sections_helper.php  3       0
............../core/units/helpers/mailbox_helper.php  4       0
....../core/units/helpers/form_submission_helper.php  2       0
................./core/units/helpers/file_helper.php  2       0
............/core/units/helpers/filenames_helper.php  1       0
.............../core/units/helpers/rating_helper.php  1       0
.............../core/units/helpers/search_helper.php  9       0
........../core/units/helpers/mime_decode_helper.php  1       0
........./core/units/helpers/mailing_list_helper.php  3       0
................../core/units/helpers/xml_helper.php  5       0
..../core/units/helpers/cat_dbitem_export_helper.php  14      0
........../core/units/helpers/mod_rewrite_helper.php  7       0
................./core/units/helpers/skin_helper.php  3       0
................../core/units/helpers/fck_helper.php  2       0
........../core/units/helpers/permissions_helper.php  2       0
...../core/units/helpers/minifiers/minify_helper.php  2       0
.........../core/units/helpers/deployment_helper.php  2       0
............./core/units/helpers/template_helper.php  1       0
............/core/units/helpers/ajax_form_helper.php  3       0
................../core/units/helpers/csv_helper.php  4       0
......./core/units/helpers/country_states_helper.php  2       0
................./core/units/helpers/list_helper.php  1       0
....../core/units/helpers/language_import_helper.php  8       0
............./core/units/helpers/category_helper.php  2       0
.............../core/units/helpers/backup_helper.php  2       0
............./core/units/helpers/brackets_helper.php  4       0
........................../core/units/fck/fck_eh.php  4       0
........................../core/units/fck/fck_tp.php  1       0
...../core/units/page_revisions/page_revision_eh.php  16      0
...../core/units/page_revisions/page_revision_tp.php  2       0
........./core/units/site_domains/site_domain_eh.php  7       0
...../core/units/country_states/country_state_eh.php  6       0
........../core/units/user_groups/user_groups_eh.php  1       0
.........../core/units/admin/admin_tag_processor.php  15      0
........../core/units/admin/admin_events_handler.php  19      0
................../core/units/captcha/captcha_eh.php  2       0
...its/custom_fields/custom_fields_event_handler.php  13      0
...its/custom_fields/custom_fields_tag_processor.php  2       0
...its/configuration/configuration_event_handler.php  15      0
...its/configuration/configuration_tag_processor.php  4       0
........./core/units/promo_blocks/promo_block_tp.php  3       0
........./core/units/promo_blocks/promo_block_eh.php  11      0
......../core/units/user_profile/user_profile_eh.php  1       0
......../core/units/user_profile/user_profile_tp.php  2       0
.............../core/units/priorites/priority_eh.php  7       0
.............../core/units/forms/drafts/draft_eh.php  2       0
.../units/forms/submission_log/submission_log_eh.php  26      0
.../units/forms/submission_log/submission_log_tp.php  6       0
...ts/forms/form_submissions/form_submissions_eh.php  14      0
...its/forms/form_submissions/form_submission_tp.php  2       0
................/core/units/forms/forms/forms_tp.php  1       0
................/core/units/forms/forms/forms_eh.php  12      0
...../core/units/forms/form_fields/form_field_eh.php  1       0
..../core/units/forms/form_fields/form_fields_tp.php  1       0
......................./core/units/skins/skin_eh.php  5       0
.../core/units/languages/languages_tag_processor.php  1       0
............/core/units/languages/languages_item.php  1       0
.../core/units/languages/languages_event_handler.php  21      0
...units/relationship/relationship_event_handler.php  3       0
............../core/units/thesaurus/thesaurus_eh.php  1       0
............../core/units/thesaurus/thesaurus_tp.php  1       0
......./core/units/phrases/phrases_event_handler.php  8       0
...e/units/custom_data/custom_data_event_handler.php  1       0
.../core/units/selectors/selectors_tag_processor.php  2       0
.../core/units/selectors/selectors_event_handler.php  10      0
...ore/units/permission_types/permission_type_eh.php  1       0
.../core/units/scheduled_tasks/scheduled_task_eh.php  11      0
............./core/units/sections/site_config_tp.php  1       0
..../core/units/logs/session_logs/session_log_eh.php  4       0
......../core/units/logs/email_logs/email_log_tp.php  2       0
......../core/units/logs/email_logs/email_log_eh.php  3       0
....../core/units/logs/system_logs/system_log_tp.php  5       0
....../core/units/logs/system_logs/system_log_eh.php  4       0
....../core/units/logs/change_logs/change_log_eh.php  1       0
...s/category_items/category_items_tag_processor.php  1       0
...s/category_items/category_items_event_handler.php  4       0
.........../core/units/theme_files/theme_file_eh.php  10      0
........../core/units/images/image_event_handler.php  8       0
........../core/units/images/image_tag_processor.php  11      0
.........../core/units/users/users_event_handler.php  62      0
..................../core/units/users/users_item.php  4       0
.........../core/units/users/users_tag_processor.php  12      0
...ore/units/translator/translator_event_handler.php  6       0
...e/units/stylesheets/stylesheets_event_handler.php  1       0
......../core/units/stylesheets/stylesheets_item.php  2       0
......................./core/units/files/file_eh.php  5       0
......................./core/units/files/file_tp.php  1       0
.../core/units/email_templates/email_template_tp.php  4       0
.../core/units/email_templates/email_template_eh.php  16      0
......./core/units/mailing_lists/mailing_list_tp.php  3       0
......./core/units/mailing_lists/mailing_list_eh.php  10      0
............/core/units/categories/cache_updater.php  1       0
........../core/units/categories/categories_item.php  4       0
...ore/units/categories/categories_event_handler.php  67      0
...ore/units/categories/categories_tag_processor.php  60      0
...nt_subscriptions/system_event_subscription_tp.php  3       0
...nt_subscriptions/system_event_subscription_eh.php  1       0
.................................../core/install.php  17      0
........................../core/install/upgrades.php  17      0
..................../core/install/upgrade_helper.php  1       0
.................../core/install/install_toolkit.php  17      0
......................../core/kernel/application.php  19      0
....................../core/kernel/event_handler.php  1       0
................/core/kernel/db/db_event_handler.php  75      0
....................../core/kernel/db/cat_dbitem.php  4       0
........................../core/kernel/db/dblist.php  9       0
........................../core/kernel/db/dbitem.php  8       0
.................../core/kernel/db/db_connection.php  2       0
................/core/kernel/db/db_load_balancer.php  1       0
.............../core/kernel/db/cat_tag_processor.php  23      0
.............../core/kernel/db/cat_event_handler.php  72      0
................/core/kernel/db/db_tag_processor.php  52      0
..................../core/kernel/nparser/nparser.php  4       0
.................../core/kernel/nparser/compiler.php  1       0
....................../core/kernel/nparser/ntags.php  1       0
...../core/kernel/managers/rewrite_url_processor.php  3       0
.........../core/kernel/managers/request_manager.php  9       0
.............../core/kernel/managers/url_manager.php  3       0
......./core/kernel/managers/plain_url_processor.php  2       0
....../core/kernel/managers/subscription_manager.php  5       0
..../core/kernel/managers/scheduled_task_manager.php  2       0
............./core/kernel/managers/cache_manager.php  2       0
..................../core/kernel/session/session.php  4       0
....................../core/kernel/event_manager.php  5       0
............................/core/kernel/globals.php  1       0
............/core/kernel/languages/phrases_cache.php  1       0
........../core/kernel/processors/main_processor.php  11      0
.........../core/kernel/processors/tag_processor.php  3       0
................./core/kernel/utility/http_query.php  3       0
.............../core/kernel/utility/temp_handler.php  5       0
....................../core/kernel/utility/email.php  6       0
......./core/kernel/utility/formatters/formatter.php  2       0
...core/kernel/utility/formatters/unit_formatter.php  3       0
...kernel/utility/formatters/multilang_formatter.php  2       0
...re/kernel/utility/formatters/upload_formatter.php  3       0
...................../core/kernel/utility/logger.php  2       0
.................../core/kernel/utility/debugger.php  1       0
....................../core/kernel/utility/event.php  1       0
............................../core/kernel/kbase.php  4       0
......................................./tmp/test.php  1       0
................../tools/internal/phrase_locator.php  1       0
----------------------------------------------------------------------
A TOTAL OF 1832 ERRORS AND 0 WARNINGS WERE FOUND IN 287 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 1832 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Solution

Use "CodingStandard.Commenting.TypeComment" sniff to automatically fix all of these errors.

Related Tasks

INP-1577 - Getting issue details... STATUS