User tests: Successful: Unsuccessful:
Add missing type hint and correct deprecation text.
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.
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.
With phpstan warnings and E_USER_DEPRECATED for the get function is triggered.
Without phpstan warnings and no E_USER_DEPRECATED for the get function is triggered.
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
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
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.
Status | Pending | ⇒ | Ready to Commit |
RTC
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.
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
|
Thx
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.