-
-
Notifications
You must be signed in to change notification settings - Fork 452
Add Interfaces to reflect DB types #5104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces data interfaces (PageInterface and BlockInterface) to standardize database field access in the CMS module, replacing hard-coded strings with constants. The changes include implementing these interfaces in the respective model classes with explicit getter/setter methods and updating all references throughout controllers, blocks, helpers, and database setup files.
Key Changes
- Added two new interface files defining constants and method signatures for CMS pages and blocks
- Updated model classes to implement these interfaces with typed getter/setter methods
- Replaced hard-coded field name strings with interface constants across 12+ files
- Enhanced documentation with missing
@throwsannotations
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| app/code/core/Mage/Cms/Api/Data/PageInterface.php | New interface defining constants and method signatures for CMS page entity |
| app/code/core/Mage/Cms/Api/Data/BlockInterface.php | New interface defining constants and method signatures for CMS block entity |
| app/code/core/Mage/Cms/Model/Page.php | Implements PageInterface with explicit getter/setter methods |
| app/code/core/Mage/Cms/Model/Block.php | Implements BlockInterface with explicit getter/setter methods |
| app/code/core/Mage/Cms/sql/cms_setup/install-1.6.0.0.php | Replaces hard-coded column names with interface constants in schema definition |
| app/code/core/Mage/Cms/Model/Resource/Page.php | Updates database queries to use interface constants instead of strings |
| app/code/core/Mage/Cms/controllers/PageController.php | Uses interface constants for request parameter access |
| app/code/core/Mage/Cms/Controller/Router.php | Uses interface constants for request parameter setting |
| app/code/core/Mage/Adminhtml/controllers/Cms/PageController.php | Updates parameter handling with interface constants |
| app/code/core/Mage/Adminhtml/controllers/Cms/BlockController.php | Updates parameter handling with interface constants |
| app/code/core/Mage/Cms/Block/Page.php | Uses interface constants and updates config path references |
| app/code/core/Mage/Cms/Block/Widget/Page/Link.php | Uses interface constants for data access |
| app/code/core/Mage/Cms/Block/Widget/Block.php | Uses interface constants for block ID access |
| app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Design.php | Uses interface constants for form field names |
| app/code/core/Mage/Cms/controllers/IndexController.php | Added missing @throws documentation |
| app/code/core/Mage/Cms/Helper/Page.php | Added missing @throws documentation |
| */ | ||
| public function getStoreId(): ?int | ||
| { | ||
| return (int) $this->getDataByKey(self::DATA_STORE_ID); |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getStoreId() method returns ?int but doesn't handle the case where getDataByKey() returns null. The cast (int) null will return 0, not null. Consider: $storeId = $this->getDataByKey(self::DATA_STORE_ID); return is_null($storeId) ? null : (int) $storeId;
| return (int) $this->getDataByKey(self::DATA_STORE_ID); | |
| $storeId = $this->getDataByKey(self::DATA_STORE_ID); | |
| return $storeId === null ? null : (int) $storeId; |
| $installer->getFkName('cms/page_store', PageInterface::DATA_STORE_ID, 'core/store', PageInterface::DATA_STORE_ID), | ||
| PageInterface::DATA_STORE_ID, | ||
| $installer->getTable('core/store'), | ||
| 'store_id', | ||
| PageInterface::DATA_STORE_ID, |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using PageInterface::DATA_STORE_ID as the foreign key column for the core/store table is incorrect. The core/store table has its own store_id column that should be referenced. While the column names happen to be the same, semantically this should use the constant from the appropriate interface for the store table, not from PageInterface.
| /** | ||
| * @return $this | ||
| */ | ||
| public function setTitle(?string $title) | ||
| { | ||
| return $this->setData(self::DATA_TITLE, $title); | ||
| } |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setTitle() method is missing the @api docblock annotation, while other similar setter methods in the class have it. Consider adding @api annotation for consistency.
| if (Mage::getStoreConfig('web/default/show_cms_breadcrumbs') | ||
| && ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable $breadcrumbs = null; declaration on line 54 has been removed, but the variable is still used in the condition on line 58. This will cause an undefined variable error if the condition short-circuits before the assignment within the condition.
| */ | ||
| public function getStoreId(): ?int | ||
| { | ||
| return $this->getDataByKey(self::DATA_STORE_ID); |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getStoreId() method returns ?int but doesn't handle the case where getDataByKey() returns null. The cast (int) null will return 0, not null. Consider: $storeId = $this->getDataByKey(self::DATA_STORE_ID); return is_null($storeId) ? null : (int) $storeId;
| return $this->getDataByKey(self::DATA_STORE_ID); | |
| $storeId = $this->getDataByKey(self::DATA_STORE_ID); | |
| return $storeId === null ? null : (int) $storeId; |
| BlockInterface::DATA_STORE_ID, | ||
| ), | ||
| BlockInterface::DATA_STORE_ID, | ||
| $installer->getTable('core/store'), | ||
| 'store_id', | ||
| BlockInterface::DATA_STORE_ID, |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using BlockInterface::DATA_STORE_ID as the foreign key column for the core/store table is incorrect. The core/store table has its own store_id column that should be referenced. While the column names happen to be the same, semantically this should use the constant from the appropriate interface for the store table, not from BlockInterface.
| public function getTitle(): ?string | ||
| { | ||
| return $this->getDataByKey(self::DATA_TITLE); | ||
| } |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getTitle() method in the interface is missing an @api docblock annotation, while other similar methods in the implementation have it. Consider adding @api annotation for consistency.
| /** | ||
| * @api | ||
| */ | ||
| public function getIdentifier(): string |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getIdentifier() method has a non-nullable string return type, but getDataByKey() could return null if the identifier is not set. This will cause a TypeError. Consider changing the return type to ?string to match the nullable behavior.
| public function getIdentifier(): string | |
| public function getIdentifier(): ?string |
| public function getIsActive(): int | ||
| { | ||
| return (int) $this->getDataByKey(self::DATA_IS_ACTIVE); | ||
| } |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getIsActive() method returns a non-nullable int but doesn't cast the value before returning. The underlying data could be null or a string from the database, leading to a TypeError. Consider adding an explicit cast: return (int) $this->getDataByKey(self::DATA_IS_ACTIVE);
|
Please retry analysis of this Pull-Request directly on SonarQube Cloud |
Description (*)
Add interface to have ...
Related Pull Requests
@addison74 your idea to trim input/output could be added here.