Problem/Motivation

PHP warnings during static code analysis using phan with messages:

"Expected an object instance when accessing an instance property, but saw an expression $config with type false in metatag.admin.inc and metatag.module

"Expected an object instance when accessing an instance property, but saw an expression $product with type array{metatags:mixed[]} " in metatag.module

"Argument 3 ($metatags) is $metatags of type null but \metatag_metatags_form() takes array defined at jjbos-platform/docroot/profiles/jjbos/modules/contrib/metatag/metatag.module" and "Argument 4 ($options) is $options of type null but \metatag_metatags_form() takes array defined at jjbos-platform/docroot/profiles/jjbos/modules/contrib/metatag/metatag.module" in metatag.module

"Expected an object instance when accessing an instance property, but saw an expression $metatag_config_node with type false", "Expected an object instance when accessing an instance property, but saw an expression $metatag_config_global with type false", "Expected an object instance when accessing an instance property, but saw an expression $metatag_config_taxonomy_term with type false" and "Expected an object instance when accessing an instance property, but saw an expression $metatag_config_user with type false" in metatag_importer/metatag_importer.page_title.inc

Issue fork metatag-3274588

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Dmitrii_Zadorozhnyi created an issue. See original summary.

Dmitrii_Zadorozhnyi’s picture

StatusFileSize
new7.31 KB

I would suggest to apply a patch

Dmitrii_Zadorozhnyi’s picture

StatusFileSize
new6.33 KB

Some fixes for patch

damienmckenna’s picture

Status: Needs review » Needs work

Thank you for working on this.

I think it needs a little work.

 function metatag_config_delete_form_submit($form, &$form_state) {
   $config = metatag_config_load($form_state['values']['instance']);
-  metatag_config_delete($config);
+  if (is_object($config)) {
+    metatag_config_delete($config);

This should display an error message of $config is not a valid object.

 function metatag_config_save($config) {
+  if (!is_object($config)) {

How about just adding the "object" declaration in the function definition, i.e. metatag_config_save(object $config)?

 function metatag_config_delete($config) {
+  if (!is_object($config)) {

Ditto.

@@ -1743,14 +1751,16 @@ function metatag_commerce_product_form_submit($form, &$form_state) {
   // The entity being saved.
   $entity_type = 'commerce_product';
   $product = $form_state[$entity_type];
-  $entity_id = $product->product_id;
-  $revision_id = $product->revision_id;
+  if (is_object($product)) {

This needs an error message.

 function metatag_form_alter(&$form, $form_state, $form_id) {
   if (!empty($form['#metatags']) && !isset($form['metatags'])) {
     extract($form['#metatags']);
-    metatag_metatags_form($form, $instance, $metatags, $options);
+    if (isset($metatags) && isset($options)) {
+      metatag_metatags_form($form, $instance, $metatags, $options);
+    }
     unset($form['#metatags']);
   }
 }

This should just not pass the third and fourth arguments, seeing as they don't exist.

Dmitrii_Zadorozhnyi’s picture

StatusFileSize
new5.47 KB

Add some fixes for patch

hitchshock’s picture

Status: Needs work » Needs review

+1 RTBC, but someone else to review this one too.

damienmckenna’s picture

Status: Needs review » Needs work

It needs some more work to display error messages, or throwing an exception, when the expected objects aren't loaded, e.g. metatag_config_delete_form_submit().

loon’s picture

Version: 7.x-1.x-dev » 7.x-1.30
Status: Needs work » Needs review
StatusFileSize
new5.7 KB

Added error messages

anoopsingh92’s picture

Assigned: Unassigned » anoopsingh92
anoopsingh92’s picture

Assigned: anoopsingh92 » Unassigned
StatusFileSize
new30.34 KB

Hi @loon, Your patch applied cleanly for me. Someone also can review it before moving it to RTBC.
Patch #8
Thanks

damienmckenna’s picture

@anoopsingh92: FYI posting a screenshot that shows a patch applies is not a useful use of your time, please don't post more of them.

damienmckenna’s picture

StatusFileSize
new6.75 KB

How does this work?

damienmckenna’s picture

damienmckenna’s picture

Status: Needs review » Fixed

Committed. Thanks everyone.

  • DamienMcKenna committed 751a2aa on 7.x-1.x
    Issue #3274588 by Dmitrii_Zadorozhnyi, DamienMcKenna, loon: PHP warnings...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.