Skip to content
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

API Strong typing for the view layer #2994

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions code/Model/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,8 @@ public function CMSTreeClasses()

/**
* Use the target page's class name for fetching templates - as we need to take on its appearance
*
* @param string $suffix
* @return array
*/
public function getViewerTemplates($suffix = '')
public function getViewerTemplates(string $suffix = ''): array
{
$copy = $this->CopyContentFrom();
if ($copy && $copy->exists()) {
Expand All @@ -418,11 +415,8 @@ public function getViewerTemplates($suffix = '')
/**
* Allow attributes on the master page to pass
* through to the virtual page
*
* @param string $field
* @return mixed
*/
public function __get($field)
public function __get(string $field): mixed
{
if (parent::hasMethod($funcName = "get$field")) {
return $this->$funcName();
Expand All @@ -436,7 +430,7 @@ public function __get($field)
return null;
}

public function getField($field)
public function getField(string $field): mixed
{
if ($this->isFieldVirtualised($field)) {
return $this->CopyContentFrom()->getField($field);
Expand Down Expand Up @@ -484,17 +478,13 @@ public function __call($method, $args)
}
}

/**
* @param string $field
* @return bool
*/
public function hasField($field)
public function hasField(string $fieldName): bool
{
if (parent::hasField($field)) {
if (parent::hasField($fieldName)) {
return true;
}
$copy = $this->CopyContentFrom();
return $copy && $copy->exists() && $copy->hasField($field);
return $copy && $copy->exists() && $copy->hasField($fieldName);
}

/**
Expand All @@ -513,11 +503,8 @@ public function hasMethod($method)
/**
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
* on this object.
*
* @param string $field
* @return string|null
*/
public function castingHelper($field, bool $useFallback = true)
public function castingHelper(string $field, bool $useFallback = true): ?string
{
$copy = $this->CopyContentFrom();
if ($copy && $copy->exists() && ($helper = $copy->castingHelper($field, $useFallback))) {
Expand Down
1 change: 0 additions & 1 deletion tests/php/Model/VirtualPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class VirtualPageTest extends FunctionalTest
VirtualPageTest_NotRoot::class,
VirtualPageTest_PageExtension::class,
VirtualPageTest_PageWithAllowedChildren::class,
VirtualPageTest_TestDBField::class,
VirtualPageTest_VirtualPageSub::class,
];

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Model/VirtualPageTest_TestDBField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class VirtualPageTest_TestDBField extends DBVarchar implements TestOnly
{
public function forTemplate()
public function forTemplate(): string
{
return strtoupper($this->XML() ?? '');
}
Expand Down
Loading