Skip to content

Commit

Permalink
ENH Add generic types (#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 17, 2024
1 parent 4a97f0b commit 75b51fc
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

// Enable SilverStripe insert link dialog on the rich text editor
$module = ModuleLoader::inst()->getManifest()->getModule('silverstripe/admin');
/** @var TinyMCEConfig $editorConfig */
$editorConfig = TinyMCEConfig::get('cms');
$editorConfig
->enablePlugins([
Expand Down
4 changes: 4 additions & 0 deletions code/AdminErrorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\Extension;

/**
* @extends Extension<RequestHandler>
*/
class AdminErrorExtension extends Extension
{
/**
Expand Down
2 changes: 1 addition & 1 deletion code/CMSBatchActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected function actionByName($name)
* - Link
* - Title
*
* @return ArrayList
* @return ArrayList<ArrayData>
*/
public function batchActionList()
{
Expand Down
6 changes: 5 additions & 1 deletion code/CMSEditLinkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
*
* If the cms_edit_owner is a has_one relation, the class on the other end
* of the relation must have a CMSEditLink() method.
*
* @template T of LeftAndMain|DataObject
* @extends Extension<T&static>
*/
class CMSEditLinkExtension extends Extension
{
Expand All @@ -40,7 +43,7 @@ class CMSEditLinkExtension extends Extension
/**
* Get the ModelAdmin, LeftAndMain, or DataObject which owns this object for CMS editing purposes.
*
* @return LeftAndMain|DataObject|null
* @return DataObject|LeftAndMain|null
*/
public function getCMSEditOwner()
{
Expand Down Expand Up @@ -71,6 +74,7 @@ public function getCMSEditLinkForManagedDataObject(DataObject $obj, string $reci
*/
public function CMSEditLink(): string
{
/** @var DataObject|LeftAndMain|null $owner */
$owner = $this->owner->getCMSEditOwner();
if (!$owner || !$owner->exists()) {
return '';
Expand Down
2 changes: 1 addition & 1 deletion code/CMSMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static function get_menu_items()
* Defaults to {@link Security::getCurrentUser()}.
*
* @param Member $member
* @return array
* @return array<CMSMenuItem>
*/
public static function get_viewable_menu_items($member = null)
{
Expand Down
1 change: 0 additions & 1 deletion code/CMSMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function getAttributesHTML($attrs = null)
$parts[] = sprintf('%s="%s"', Convert::raw2att($name), Convert::raw2att($value));
}

/** @var DBHTMLText $fragment */
$fragment = DBField::create_field('HTMLFragment', implode(' ', $parts));
return $fragment;
}
Expand Down
1 change: 0 additions & 1 deletion code/CMSProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function save(array $data, Form $form): HTTPResponse
* in the breadcrumbs.
*
* @param bool $unlinked
* @return ArrayList
*/
public function Breadcrumbs($unlinked = false)
{
Expand Down
2 changes: 2 additions & 0 deletions code/Forms/FormMessageBootstrapAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Will convert a SilverStripe message type into a Bootstrap alert type
*
* @extends Extension<Form|FormField>
*/
class FormMessageBootstrapExtension extends Extension
{
Expand Down
4 changes: 4 additions & 0 deletions code/Forms/GridFieldDetailFormPreviewExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
use SilverStripe\Admin\Navigator\SilverStripeNavigator;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\CMSPreviewable;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\View\SSViewer;

/**
* @extends Extension<GridFieldDetailForm_ItemRequest>
*/
class GridFieldDetailFormPreviewExtension extends Extension
{
public function updateItemEditForm(Form $form): void
Expand Down
4 changes: 4 additions & 0 deletions code/Forms/GridFieldPrintButtonExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
namespace SilverStripe\Admin\Forms;

use SilverStripe\Core\Extension;
use SilverStripe\Forms\GridField\GridFieldPrintButton;
use SilverStripe\View\Requirements;

/**
* @extends Extension<GridFieldPrintButton>
*/
class GridFieldPrintButtonExtension extends Extension
{
public function updatePrintData($data)
Expand Down
1 change: 0 additions & 1 deletion code/Forms/LinkFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function getForm(RequestHandler $controller = null, $name = FormFactory::
$fields = $this->getFormFields($controller, $name, $context);
$actions = $this->getFormActions($controller, $name, $context);
$validator = $this->getValidator($controller, $name, $context);
/** @var Form $form */
$form = Form::create($controller, $name, $fields, $actions, $validator);
$form->addExtraClass('form--no-dividers');

Expand Down
1 change: 0 additions & 1 deletion code/Forms/UsedOnTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function usage(HTTPRequest $request)
{
$usage = ArrayList::create();

/** @var DataObject $record */
$record = $this->getRecord() ?: DataObject::create();
if ($record->canView()) {
// Exclude classes from being queried and showing in the results via an extension hook
Expand Down
3 changes: 1 addition & 2 deletions code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ public function MainMenu($cached = true)
$menuIconStyling = '';

if ($menuItems) {
/** @var CMSMenuItem $menuItem */
foreach ($menuItems as $code => $menuItem) {
// alternate permission checks (in addition to LeftAndMain->canView())
if (isset($menuItem->controller)
Expand Down Expand Up @@ -1192,7 +1191,7 @@ public function getRecord($id)

/**
* @param bool $unlinked
* @return ArrayList
* @return ArrayList<ArrayData>
*/
public function Breadcrumbs($unlinked = false)
{
Expand Down
3 changes: 3 additions & 0 deletions code/LeftAndMainExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

/**
* Plug-ins for additional functionality in your LeftAndMain classes.
*
* @template T of LeftAndMain
* @extends Extension<T>
*/
abstract class LeftAndMainExtension extends Extension
{
Expand Down
5 changes: 0 additions & 5 deletions code/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ function ($form) {
// Validation
if (singleton($this->modelClass)->hasMethod('getCMSCompositeValidator')) {
$detailValidator = singleton($this->modelClass)->getCMSCompositeValidator();
/** @var GridFieldDetailForm $detailform */
$detailform = $config->getComponentByType(GridFieldDetailForm::class);
$detailform->setValidator($detailValidator);
}
Expand Down Expand Up @@ -708,10 +707,6 @@ public function import(array $data, Form $form): HTTPResponse
return $this->redirectBack();
}

/**
* @param bool $unlinked
* @return ArrayList
*/
public function Breadcrumbs($unlinked = false)
{
$items = parent::Breadcrumbs($unlinked);
Expand Down
1 change: 0 additions & 1 deletion code/SecurityAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ protected function getGridFieldConfig(): GridFieldConfig
$config->removeComponentsByType(GridFieldImportButton::class);
return $config;
}
/** @var GridFieldImportButton $importButton */
$importButton = $config->getComponentByType(GridFieldImportButton::class);
if ($importButton) {
$modalTitle = match ($this->modelClass) {
Expand Down
1 change: 0 additions & 1 deletion code/SudoModeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class SudoModeController extends LeftAndMain

public function getClientConfig()
{
/** @var HTTPRequest $request */
$request = Injector::inst()->get(HTTPRequest::class);

return array_merge_recursive(parent::getClientConfig(), [
Expand Down

0 comments on commit 75b51fc

Please sign in to comment.