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
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3204763-4.patch | 5.43 KB | longwave |
Comments
Comment #2
longwaveThis patch fixes all five instances.
Comment #4
longwaveThe fail in #2 refers to the entity type as a field, so the test was incorrect here.
Comment #5
kingdutchThe 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.
Comment #8
larowlanCommitted cdf0726 and pushed to 9.2.x. Thanks!
Backported to 9.1 because there's little risk of disruption here