RTC Pending

User tests: Successful: Unsuccessful:

avatar HLeithner
HLeithner
6 May 2025

Add missing type hint and correct deprecation text.

Summary of Changes

The $state property defined in the StateBehaviorTrait has as type hint the State class which is deprecated. The goal is to replace the State object with a Registry object. This can be done in 5.0+ by initialising the $state in the constructor with a Registry object. The Trait will use this Registry object. If the $state property is not type hinted with the Registry object, phpstan will complain about incorrect use of the $state.

This PR allows to use the correct type (Registry) and solves warnings from the static code analyser.

Testing Instructions

Code Review.

if you use phpstan you should no longer get the following messages:

Initialization of $state with \Joomla\Registry\Registry in the constructor

class YourModel extends ListModel
{
    public function __construct($config = [], ?MVCFactoryInterface $factory = null)
    {
        $this->state = new Registry();
    }
}
Property Joomla\CMS\MVC\Model\BaseModel::$state (Joomla\CMS\MVC\Model\State) does not accept Joomla\Registry\Registry.  
         🪪  assign.propertyType                                                                                                 

Get variable from the $state property when it's a State object

class YourModel extends ListModel
{
    public function getItems()
    {
        return $this->state->get('dummy);
    }
    public function getItems2()
    {
        return $this->getState('dummy);
    }
}
Call to method get() of deprecated class Joomla\CMS\MVC\Model\State:                                                    
         7.0 Use the Registry directly                                                                                           
         🪪  method.deprecatedClass                                                                                              

Also if you run this code against the State object you get a runtime E_USER_DEPRECATED warning.

Actual result BEFORE applying this Pull Request

With phpstan warnings and E_USER_DEPRECATED for the get function is triggered.

Expected result AFTER applying this Pull Request

Without phpstan warnings and no E_USER_DEPRECATED for the get function is triggered.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar HLeithner HLeithner - open - 6 May 2025
avatar HLeithner HLeithner - change - 6 May 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 6 May 2025
Category Libraries
avatar brianteeman brianteeman - test_item - 6 May 2025 - Tested successfully
avatar brianteeman
brianteeman - comment - 6 May 2025

I have tested this item ✅ successfully on aa00dc3

code review


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45437.

avatar Hackwar Hackwar - test_item - 6 May 2025 - Tested successfully
avatar Hackwar
Hackwar - comment - 6 May 2025

I have tested this item ✅ successfully on aa00dc3

Since it is only a change in docblocks, I'm signing of on this. Question is if we can refactor the core components to use Registry instead now.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45437.

avatar Hackwar Hackwar - change - 6 May 2025
Status Pending Ready to Commit
avatar Hackwar
Hackwar - comment - 6 May 2025

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45437.

avatar HLeithner
HLeithner - comment - 6 May 2025

Since it is only a change in docblocks, I'm signing of on this. Question is if we can refactor the core components to use Registry instead now.

nope can't be changed till 7.0 for core components, this would be a b/c break, but now you can use Registry in your own extension as suggested in the deprecation notice.

avatar bembelimen bembelimen - change - 6 May 2025
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2025-05-06 08:51:08
Closed_By bembelimen
Labels Added: RTC
avatar bembelimen bembelimen - close - 6 May 2025
avatar bembelimen bembelimen - merge - 6 May 2025
avatar bembelimen
bembelimen - comment - 6 May 2025

Thx

Add a Comment

Login with GitHub to post a comment