Skip to content

[Issue] Corrected scope of _construct to protected #29643

Open
@m2-assistant

Description

This issue is automatically created based on existing pull request: #25537: Corrected scope of _construct to protected


Description

Corrects the scope of _construct() method in Magento\Cron\Model\ResourceModel\Schedule.php.

_construct() is intended to act as a "mock" constructor and not supposed to be accessed outside of the context of $this

Fixed Issues (if relevant)

None.

Manual testing scenarios (*)

No tests performed. However I did perform a scan of the code base to ensure _construct() is never currently called outside of the context of $this.

grep -r \>_construct .
./lib/internal/Magento/Framework/View/Element/AbstractBlock.php:        $this->_construct();
./lib/internal/Magento/Framework/Model/ResourceModel/Db/Collection/AbstractCollection.php:        $this->_construct();
./lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php:        $this->_construct();
./lib/internal/Magento/Framework/Model/AbstractModel.php:        $this->_construct();
./lib/internal/Magento/Framework/Data/Form/AbstractForm.php:        $this->_construct();
./app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php:        $this->_construct();

Questions or comments

This should really be a PR into 2.4-develop as this is a non-backwards compatible change. However no such branch exists for me to open a PR to.

While this does not break any functionality within Magento itself, it is potentially possible that developers have (against best practices) performed in their code something similar to the following:

<?php

namespace VendorName\ModuleName\Model\FooBar;

class BadPractice
{
    private $schedule;

    public function __construct(\Magento\Core\Model\Cron\ResourceModel\Schedule $schedule)
    {
        $this->schedule = $schedule;
    }

    public function notSureWhyAnyoneWouldEverDoThis()
    {
        $this->schedule->_construct();
    }

    // ... remaining class contents...
}

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Metadata

Assignees

Labels

Area: FrameworkComponent: CronIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedPriority: P4No current plan to fix. Fixing can be deferred as a logical part of more important work.Progress: PR in progressReported on 2.4.0Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S4Affects aesthetics, professional look and feel, “quality” or “usability”.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions