Problem/Motivation

Discovered when starting to get PHPStan running against Drupal core in #3178534: Start running PHPStan on Drupal core (level 0), the following errors were reported relating to sprintf calls:

 ------ ------------------------------------------------------------------- 
  Line   core/modules/block/src/Plugin/migrate/process/BlockVisibility.php  
 ------ ------------------------------------------------------------------- 
  126    Call to sprintf contains 2 placeholders, 3 values given.           
 ------ -------------------------------------------------------------------

 ------ ------------------------------------------------------------------- 
  Line   core/modules/file/src/Plugin/rest/resource/FileUploadResource.php  
 ------ ------------------------------------------------------------------- 
  267    Call to sprintf contains 1 placeholder, 0 values given.            
 ------ ------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------- 
  Line   core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php  
 ------ --------------------------------------------------------------------------- 
  182    Call to sprintf contains 1 placeholder, 0 values given.                    
 ------ --------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------- 
  Line   core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php  
 ------ ---------------------------------------------------------------------------------- 
  78     Call to sprintf contains 1 placeholder, 3 values given.                           
 ------ ---------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------- 
  Line   core/modules/views/src/Plugin/views/field/FieldPluginBase.php  
 ------ --------------------------------------------------------------- 
  189    Call to sprintf contains 2 placeholders, 3 values given.       
 ------ --------------------------------------------------------------- 

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#4 3204763-4.patch5.43 KBlongwave
#2 3204763-2.patch4.54 KBlongwave

Comments

longwave created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
StatusFileSize
new4.54 KB

This patch fixes all five instances.

Status: Needs review » Needs work

The last submitted patch, 2: 3204763-2.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new5.43 KB

The fail in #2 refers to the entity type as a field, so the test was incorrect here.

kingdutch’s picture

Status: Needs review » Reviewed & tested by the community

The changes remove or add the values so that the strings work, under the assumption that the messages are correct but the arguments were not.

Looking at the changes made this looks correct and the most sensible thing to do.

  • larowlan committed cdf0726 on 9.2.x
    Issue #3204763 by longwave: Fix mismatched sprintf calls
    

  • larowlan committed 73be6ab on 9.1.x
    Issue #3204763 by longwave: Fix mismatched sprintf calls
    
    (cherry picked...
larowlan’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed cdf0726 and pushed to 9.2.x. Thanks!

Backported to 9.1 because there's little risk of disruption here

Status: Fixed » Closed (fixed)

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