Skip to content

Conversation

@sreichel
Copy link
Contributor

Description (*)

Add interface to have ...

  • setter/getter for every db field
  • ensures input/output type matches db
  • less hard-coded strings ...

Related Pull Requests

@addison74 your idea to trim input/output could be added here.

Copilot AI review requested due to automatic review settings November 16, 2025 19:03
@github-actions github-actions bot added Component: Cms Relates to Mage_Cms Component: Adminhtml Relates to Mage_Adminhtml labels Nov 16, 2025
Copilot finished reviewing on behalf of sreichel November 16, 2025 19:06
Copy link
Contributor

Copilot AI left a 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 @throws annotations

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);
Copy link

Copilot AI Nov 16, 2025

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;

Suggested change
return (int) $this->getDataByKey(self::DATA_STORE_ID);
$storeId = $this->getDataByKey(self::DATA_STORE_ID);
return $storeId === null ? null : (int) $storeId;

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +191
$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,
Copy link

Copilot AI Nov 16, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +453 to +459
/**
* @return $this
*/
public function setTitle(?string $title)
{
return $this->setData(self::DATA_TITLE, $title);
}
Copy link

Copilot AI Nov 16, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 57 to 58
if (Mage::getStoreConfig('web/default/show_cms_breadcrumbs')
&& ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'))
Copy link

Copilot AI Nov 16, 2025

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.

Copilot uses AI. Check for mistakes.
*/
public function getStoreId(): ?int
{
return $this->getDataByKey(self::DATA_STORE_ID);
Copy link

Copilot AI Nov 16, 2025

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;

Suggested change
return $this->getDataByKey(self::DATA_STORE_ID);
$storeId = $this->getDataByKey(self::DATA_STORE_ID);
return $storeId === null ? null : (int) $storeId;

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +86
BlockInterface::DATA_STORE_ID,
),
BlockInterface::DATA_STORE_ID,
$installer->getTable('core/store'),
'store_id',
BlockInterface::DATA_STORE_ID,
Copy link

Copilot AI Nov 16, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +448 to +451
public function getTitle(): ?string
{
return $this->getDataByKey(self::DATA_TITLE);
}
Copy link

Copilot AI Nov 16, 2025

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.

Copilot uses AI. Check for mistakes.
/**
* @api
*/
public function getIdentifier(): string
Copy link

Copilot AI Nov 16, 2025

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.

Suggested change
public function getIdentifier(): string
public function getIdentifier(): ?string

Copilot uses AI. Check for mistakes.
Comment on lines +332 to +335
public function getIsActive(): int
{
return (int) $this->getDataByKey(self::DATA_IS_ACTIVE);
}
Copy link

Copilot AI Nov 16, 2025

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);

Copilot uses AI. Check for mistakes.
@sreichel sreichel marked this pull request as draft November 16, 2025 19:09
@sonarqubecloud
Copy link

Please retry analysis of this Pull-Request directly on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Adminhtml Relates to Mage_Adminhtml Component: Cms Relates to Mage_Cms new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant