address phpstan warnings

Created on 3 April 2025, 4 days ago

Problem/Motivation

------ -------------------------------------------------------------------------------
Line custom_field.tokens.inc
------ -------------------------------------------------------------------------------
305 Call to deprecated method renderPlain() of class Drupal\Core\Render\Renderer:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\Render\RendererInterface::renderInIsolation() instead.
------ -------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------------------------------
Line src/Plugin/CustomField/FeedsType/FileTarget.php
------ ------------------------------------------------------------------------------------------------------
87 Fetching deprecated class constant EXISTS_ERROR of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Error instead.
96 Fetching deprecated class constant EXISTS_REPLACE of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Replace instead.
97 Fetching deprecated class constant EXISTS_RENAME of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Rename instead.
98 Fetching deprecated class constant EXISTS_ERROR of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Error instead.
118 Fetching deprecated class constant EXISTS_REPLACE of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Replace instead.
122 Fetching deprecated class constant EXISTS_RENAME of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Rename instead.
126 Fetching deprecated class constant EXISTS_ERROR of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Error instead.
226 Fetching deprecated class constant EXISTS_ERROR of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Error instead.
230 Fetching deprecated class constant EXISTS_REPLACE of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Replace instead.
362 Fetching deprecated class constant EXISTS_RENAME of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Rename instead.
------ ------------------------------------------------------------------------------------------------------

------ ----------------------------------------------------------------------------------------------------
Line src/Plugin/CustomField/FieldType/FileType.php
------ ----------------------------------------------------------------------------------------------------
143 Fetching deprecated class constant EXISTS_ERROR of interface Drupal\Core\File\FileSystemInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\File\FileExists::Error instead.
------ ----------------------------------------------------------------------------------------------------

------ --------------------------------------------------------------------------------------------
Line src/Plugin/CustomField/FieldWidget/FileWidget.php
------ --------------------------------------------------------------------------------------------
278 Call to deprecated method renderPlain() of interface Drupal\Core\Render\RendererInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\Render\RendererInterface::renderInIsolation() instead.
------ --------------------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------
Line src/Plugin/CustomFieldFormatterManager.php
------ ------------------------------------------------------------------------------
64 \Drupal calls should be avoided in classes, use dependency injection instead
------ ------------------------------------------------------------------------------

------ --------------------------------------------------------------------------------------------
Line src/Plugin/DataType/CustomFieldStringLong.php
------ --------------------------------------------------------------------------------------------
57 Call to deprecated method renderPlain() of interface Drupal\Core\Render\RendererInterface:
in drupal:10.3.0 and is removed from drupal:12.0.0. Use
\Drupal\Core\Render\RendererInterface::renderInIsolation() instead.
------ --------------------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------
Line src/Plugin/Field/FieldFormatter/CustomTemplateFormatter.php
------ ------------------------------------------------------------------------------
137 \Drupal calls should be avoided in classes, use dependency injection instead
------ ------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------------------------------------
Line src/Plugin/Field/FieldType/CustomItemList.php
------ ------------------------------------------------------------------------------------------------------------
93 Method Drupal\custom_field\Plugin\Field\FieldType\CustomItemList::postSave() should return bool but return
statement is missing.
------ ------------------------------------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------
Line src/Plugin/views/argument/CustomFieldDate.php
------ ------------------------------------------------------------------------------
51 \Drupal calls should be avoided in classes, use dependency injection instead
------ ------------------------------------------------------------------------------

(I'm ignoring the submodules for now)

Steps to reproduce

phpstan analyse -l0 custom_field

Proposed resolution

  • in custom_field.tokens.inc, FileWidget.php, and CustomFieldStringLong.php, use renderInIsolation()
  • in FileTarget.php and FileType.php, use FileExists constants in place of global constants
  • in CustomFieldFormatterManager.php, CustomTemplateFormatter.php, and CustomFieldDate.php, use dependency injection
  • in CustomItemList.php, return bool

Remaining tasks

make a MR

πŸ“Œ Task
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States BenStallings

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @BenStallings
  • Merge request !113renderInIsolation β†’ (Open) created by BenStallings
  • Pipeline finished with Canceled
    4 days ago
    Total: 618s
    #464832
  • Pipeline finished with Failed
    4 days ago
    Total: 623s
    #464839
  • πŸ‡ΊπŸ‡ΈUnited States BenStallings

    I was not able to inject the dependency in CustomFieldFormatterManager because I don't fully understand what's going on there.

    I did not inject the dependency in CustomFieldDate because that part of the code is already deprecated.

  • Pipeline finished with Failed
    4 days ago
    Total: 579s
    #464851
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    These functions related to file were introduced in 10.3. These changes would therefore break 10.2 sites. I was holding off on these issues for that reason and deeming a new major version would be necessary.

Production build 0.71.5 2024