Skip to content

Commit

Permalink
ENH Add generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jan 11, 2024
1 parent a5d2b3b commit 5808f41
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 23 deletions.
15 changes: 10 additions & 5 deletions code/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@
* Subclasses of ContentController are generally instantiated by ModelAsController; this will create
* a controller based on the URLSegment action variable, by looking in the SiteTree table.
*
* @template T of SiteTree
*/
class ContentController extends Controller
{
/**
* @var SiteTree
* @var T
*/
protected $dataRecord;

Expand All @@ -71,7 +72,7 @@ class ContentController extends Controller
* The ContentController will take the URLSegment parameter from the URL and use that to look
* up a SiteTree record.
*
* @param SiteTree $dataRecord
* @param T|null $dataRecord
*/
public function __construct($dataRecord = null)
{
Expand Down Expand Up @@ -110,7 +111,7 @@ public function Link($action = null)
* Return the children of a given page. The parent reference can either be a page link or an ID.
*
* @param string|int $parentRef
* @return SS_List
* @return SS_List<SiteTree>
*/
public function ChildrenOf($parentRef)
{
Expand Down Expand Up @@ -188,7 +189,7 @@ protected function init()
*/
public function handleRequest(HTTPRequest $request): HTTPResponse
{
/** @var SiteTree $child */
/** @var SiteTree|null $child */
$child = null;
$action = $request->param('Action');

Expand Down Expand Up @@ -243,6 +244,7 @@ public function project()

/**
* Returns the associated database record
* @return T
*/
public function data()
{
Expand All @@ -254,7 +256,7 @@ public function data()
/**
* Returns a fixed navigation menu of the given level.
* @param int $level Menu level to return.
* @return ArrayList
* @return ArrayList<SiteTree>
*/
public function getMenu($level = 1)
{
Expand Down Expand Up @@ -294,6 +296,9 @@ public function getMenu($level = 1)
return new ArrayList($visible);
}

/**
* @return ArrayList<SiteTree>
*/
public function Menu($level)
{
return $this->getMenu($level);
Expand Down
4 changes: 4 additions & 0 deletions code/Controllers/LeftAndMainBatchActionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace SilverStripe\CMS\Controllers;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Core\Extension;

/**
* @extends Extension<LeftAndMain>
*/
class LeftAndMainBatchActionsExtension extends Extension
{
public function updateBatchActionsForm(&$form)
Expand Down
4 changes: 3 additions & 1 deletion code/Controllers/LeftAndMainPageIconsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\InvalidArgumentException;
use ReflectionException;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
Expand All @@ -16,10 +17,11 @@

/**
* Extension to include custom page icons
*
* @extends Extension<LeftAndMain>
*/
class LeftAndMainPageIconsExtension extends Extension implements Flushable
{

/**
* @throws InvalidArgumentException
* @throws ReflectionException
Expand Down
4 changes: 3 additions & 1 deletion code/Controllers/OldPageRedirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Extension;

/**
* @extends Extension<Controller>
*/
class OldPageRedirector extends Extension
{

/**
* On every URL that generates a 404, we'll capture it here and see if we can
* find an old URL that it should be redirecting to.
Expand Down
14 changes: 2 additions & 12 deletions code/Forms/InternalLinkModalExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

/**
* Decorates ModalController with insert internal link
* @see ModalController
*
* @extends Extension<ModalController>
*/
class InternalLinkModalExtension extends Extension
{
Expand All @@ -22,17 +23,6 @@ class InternalLinkModalExtension extends Extension
'editorAnchorLink',
];

/**
* @return ModalController
*/
public function getOwner()
{
/** @var ModalController $owner */
$owner = $this->owner;
return $owner;
}


/**
* Form for inserting internal link pages
*
Expand Down
3 changes: 2 additions & 1 deletion code/Model/RedirectorPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Controller for the {@link RedirectorPage}.
*
* @extends PageController<RedirectorPage>
*/
class RedirectorPageController extends PageController
{
Expand All @@ -26,7 +28,6 @@ class RedirectorPageController extends PageController
*/
public function index(HTTPRequest $request)
{
/** @var RedirectorPage $page */
$page = $this->data();

// Redirect if we can
Expand Down
6 changes: 3 additions & 3 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ public function getLiveURLSegment()
/**
* Get the back-link tracking objects that link to this page
*
* @return ArrayList|DataObject[]
* @return ArrayList<DataObject>
*/
public function BackLinkTracking()
{
Expand Down Expand Up @@ -2007,7 +2007,7 @@ public function BackLinkTracking()
* Returns the pages that depend on this page. This includes virtual pages, pages that link to it, etc.
*
* @param bool $includeVirtuals Set to false to exlcude virtual pages.
* @return ArrayList|SiteTree[]
* @return ArrayList<SiteTree>
*/
public function DependentPages($includeVirtuals = true)
{
Expand Down Expand Up @@ -2057,7 +2057,7 @@ public function DependentPages($includeVirtuals = true)
/**
* Return all virtual pages that link to this page.
*
* @return DataList
* @return DataList<SiteTree>
*/
public function VirtualPages()
{
Expand Down
3 changes: 3 additions & 0 deletions code/Model/SiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

/**
* Plug-ins for additional functionality in your SiteTree classes.
*
* @template T of SiteTree
* @extends DataExtension<T>
*/
abstract class SiteTreeExtension extends DataExtension
{
Expand Down
2 changes: 2 additions & 0 deletions code/Model/SiteTreeLinkTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*
* @property DataObject|SiteTreeLinkTracking $owner
* @method ManyManyThroughList<SiteTree> LinkTracking()
*
* @extends DataExtension<DataObject>
*/
class SiteTreeLinkTracking extends DataExtension
{
Expand Down
3 changes: 3 additions & 0 deletions code/Search/ContentControllerSearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\CMS\Search;

use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\TextField;
Expand All @@ -12,6 +13,8 @@

/**
* Extension to provide a search interface when applied to ContentController
*
* @extends Extension<ContentController>
*/
class ContentControllerSearchExtension extends Extension
{
Expand Down

0 comments on commit 5808f41

Please sign in to comment.