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

ENH Add generic types #1433

Merged
merged 1 commit into from
Jan 18, 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
16 changes: 1 addition & 15 deletions code/Controller/AssetAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ public function apiCreateFile(HTTPRequest $request)
}

// Check parent record
/** @var Folder $parentRecord */
$parentRecord = null;
if (!empty($data['ParentID']) && is_numeric($data['ParentID'])) {
$parentRecord = Folder::get()->byID($data['ParentID']);
Expand Down Expand Up @@ -377,7 +376,6 @@ public function apiUploadFile(HTTPRequest $request)
}

// Check parent record
/** @var File $file */
$file = File::get()->byID($data['ID']);
if (!$file) {
$this->jsonError(404, _t(__CLASS__.'.FILE_NOT_FOUND', 'File not found'));
Expand Down Expand Up @@ -530,7 +528,6 @@ public function apiHistory(HTTPRequest $request)
public function legacyRedirectForEditView(HTTPRequest $request): HTTPResponse
{
$fileID = $request->param('FileID');
/** @var File $file */
$file = File::get()->byID($fileID);
$link = $this->getFileEditLink($file) ?: $this->Link();
return $this->redirect($link);
Expand Down Expand Up @@ -569,15 +566,13 @@ protected function getNameGenerator($filename)
}

/**
* @param bool $unlinked
* @return ArrayList
* @return null
*/
public function breadcrumbs($unlinked = false)
{
return null;
}


/**
* Don't include class namespace in auto-generated CSS class
*/
Expand Down Expand Up @@ -738,7 +733,6 @@ public function fileEditorLinkForm($request = null)
*/
protected function getAbstractFileForm($id, $name, $context = [])
{
/** @var File $file */
$file = File::get()->byID($id);

if (!$file) {
Expand Down Expand Up @@ -849,7 +843,6 @@ public function getFileHistoryForm($context)
return null;
}

/** @var File $file */
$file = Versioned::get_version(File::class, $id, $versionId);
if (!$file) {
$this->jsonError(404);
Expand All @@ -866,7 +859,6 @@ public function getFileHistoryForm($context)
}

$effectiveContext = array_merge($context, ['Record' => $file]);
/** @var FormFactory $scaffolder */
$scaffolder = Injector::inst()->get(FileHistoryFormFactory::class);
$form = $scaffolder->getForm($this, 'fileHistoryForm', $effectiveContext);

Expand Down Expand Up @@ -996,7 +988,6 @@ protected function saveOrPublish(array $data, Form $form, bool $doPublish = fals
}

$id = (int) $data['ID'];
/** @var File $record */
$record = DataObject::get_by_id(File::class, $id);

if (!$record) {
Expand Down Expand Up @@ -1050,7 +1041,6 @@ public function unpublish(array $data, Form $form): HTTPResponse
}

$id = (int) $data['ID'];
/** @var File $record */
$record = DataObject::get_by_id(File::class, $id);

if (!$record) {
Expand Down Expand Up @@ -1093,7 +1083,6 @@ public function getObjectFromData(File $file, $thumbnailLinks = true)
$object['canEdit'] = $file->canEdit();
$object['canDelete'] = ($file->hasMethod('canArchive')) ? $file->canArchive() : $file->canDelete();

/** @var Member $owner */
$owner = $file->Owner();

if ($owner) {
Expand Down Expand Up @@ -1134,7 +1123,6 @@ public function getMinimalistObjectFromData(File $file, $thumbnailLinks = true)
'visibility' => $file->getVisibility()
);

/** @var Folder $parent */
$parent = $file->Parent();

if ($parent) {
Expand All @@ -1145,7 +1133,6 @@ public function getMinimalistObjectFromData(File $file, $thumbnailLinks = true)
);
}

/** @var File $file */
if ($file->getIsImage()) {
$thumbnails = $this->generateThumbnails($file, $thumbnailLinks);

Expand Down Expand Up @@ -1328,7 +1315,6 @@ public function folderCreateForm($request = null)
*/
public function getFolderCreateForm($parentId = 0)
{
/** @var FolderCreateFormFactory $factory */
$factory = Injector::inst()->get(FolderCreateFormFactory::class);
$form = $factory->getForm($this, 'folderCreateForm', [ 'ParentID' => $parentId ]);

Expand Down
4 changes: 4 additions & 0 deletions code/Controller/AssetAdminFieldsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace SilverStripe\AssetAdmin\Controller;

use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Extension;
use SilverStripe\View\Requirements;

/**
* @extends Extension<LeftAndMain>
*/
class AssetAdminFieldsExtension extends Extension
{
public function init()
Expand Down
4 changes: 2 additions & 2 deletions code/Controller/AssetAdminFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Update File dataobjects to be editable in this asset admin
*
* @property File $owner
* @extends DataExtension<File>
*/
class AssetAdminFile extends DataExtension
{
Expand Down Expand Up @@ -176,7 +176,7 @@ public function humanizedChanges($from, $to)
/**
* Get the list of all nested files in use
*
* @return SS_List
* @return SS_List<File>
*/
public function getFilesInUse()
{
Expand Down
4 changes: 3 additions & 1 deletion code/Extensions/CampaignAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\AssetAdmin\Extensions;

use SilverStripe\AssetAdmin\Forms\FileFormFactory;
use SilverStripe\Assets\File;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FormAction;
Expand All @@ -10,7 +11,8 @@
/**
* Extension that updates the Popover menu of `FileFormFactory`.
* This extension will only be applied if the `campaign-admin` module is installed.
* @package SilverStripe\AssetAdmin\Extensions
*
* @extends Extension<FileFormFactory>
*/
class CampaignAdminExtension extends Extension
{
Expand Down
13 changes: 2 additions & 11 deletions code/Extensions/RemoteFileModalExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

/**
* Decorates ModalController with an insert-oembed modal
* @see ModalController
*
* @extends Extension<ModalController>
*/
class RemoteFileModalExtension extends Extension
{
Expand All @@ -30,16 +31,6 @@ class RemoteFileModalExtension extends Extension
'remoteEditFormSchema',
);

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

/**
* @return HTTPRequest
*/
Expand Down
3 changes: 3 additions & 0 deletions code/Extensions/UsedOnTableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\AssetAdmin\Extensions;

use SilverStripe\Admin\Forms\UsedOnTable;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Shortcodes\FileLink;
use SilverStripe\Core\Extension;
Expand All @@ -10,6 +11,8 @@

/**
* Hides several types of DataObjects on the "Used On" tab when viewing files
*
* @extends Extension<UsedOnTable>
*/
class UsedOnTableExtension extends Extension
{
Expand Down
5 changes: 1 addition & 4 deletions code/Forms/AssetFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ protected function getFormFieldTabs($record, $context = [])
protected function getSaveAction($record)
{
if ($record && $record->isInDB() && $record->canEdit()) {
/** @var FormAction $action */
$action = FormAction::create('save', _t(__CLASS__ . '.SAVE', 'Save'))
->setIcon('save')
->setSchemaState([
Expand Down Expand Up @@ -227,10 +226,10 @@ protected function getFormActions(RequestHandler $controller = null, $formName,
*/
protected function getFormFields(RequestHandler $controller = null, $formName, $context = [])
{
/** @var File $record */
$record = isset($context['Record']) ? $context['Record'] : null;

// Build standard fields for all folders / files
/** @var File $record */
$fields = new FieldList(
FieldGroup::create(
HeaderField::create('TitleHeader', $record ? $record->Title : null, 1)
Expand Down Expand Up @@ -302,7 +301,6 @@ protected function getPopoverActions($record)
*/
protected function getFormFieldDetailsTab($record, $context = [])
{
/** @var Tab $tab */
$tab = Tab::create(
'Details',
TextField::create('Name', _t(__CLASS__ . '.FILENAME', 'Filename')),
Expand Down Expand Up @@ -351,7 +349,6 @@ protected function getPath($record, $context = [])
if ($context['ParentID'] === 0) {
return '/';
}
/** @var File $file */
$file = File::get()->byID($context['ParentID']);
if ($file) {
return $file->getFilename();
Expand Down
3 changes: 0 additions & 3 deletions code/Forms/FileFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ protected function getPublishAction($record)

// Build action
$publishText = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.PUBLISH_BUTTON', 'Publish');
/** @var FormAction $action */
$action = FormAction::create('publish', $publishText)
->setIcon('rocket')
->setSchemaState([
Expand Down Expand Up @@ -469,7 +468,6 @@ protected function getInsertAction($record)
{
$action = null;
if ($record && $record->isInDB() && $record->canView()) {
/** @var FormAction $action */
$action = FormAction::create('insert', 'Insert')
->setIcon('plus-circled')
->setSchemaData(['data' => ['buttonStyle' => 'primary']]);
Expand All @@ -485,7 +483,6 @@ protected function getInsertLinkAction($record)
{
$action = null;
if ($record && $record->isInDB() && $record->canView()) {
/** @var FormAction $action */
$action = FormAction::create('insert', _t(__CLASS__ . '.INSERT_LINK', 'Link to file'))
->setSchemaData(['data' => ['buttonStyle' => 'primary']]);
}
Expand Down
2 changes: 0 additions & 2 deletions code/Forms/ImageFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ protected function getSpecsMarkup($record)

protected function getFormFieldAttributesTab($record, $context = [])
{
/** @var Tab $tab */
$tab = parent::getFormFieldAttributesTab($record, $context);

$alignments = [
Expand Down Expand Up @@ -149,7 +148,6 @@ public function getForm(RequestHandler $controller = null, $name = FormFactory::
if (!$record) {
return;
}
/** @var FieldList $fields */
$fields = $form->Fields();

$dimensions = $fields->fieldByName('Editor.Placement.Dimensions');
Expand Down
3 changes: 1 addition & 2 deletions code/Forms/PreviewImageField.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function getSchemaStateDefaults()
{
$defaults = parent::getSchemaStateDefaults();

/** @var File $record */
if ($record = $this->getRecord()) {
$parent = $record->Parent();

Expand Down Expand Up @@ -69,7 +68,7 @@ public function performReadonlyTransformation()
}

/**
* @return DataObject
* @return File|null
*/
public function getRecord()
{
Expand Down
1 change: 0 additions & 1 deletion code/Forms/RemoteFileFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ protected function getEditFormFields($context)
// Get embed
$this->validateUrl($url);

/** @var Embeddable $embed */
$embed = Injector::inst()->create(Embeddable::class, $url);
$this->validateEmbed($embed);

Expand Down
1 change: 0 additions & 1 deletion code/GraphQL/FileFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public static function filterList(Filterable $list, $filter)

// Filter unknown id by known child if search is not applied
if (!$search && isset($filter['anyChildId'])) {
/** @var File $child */
$child = File::get()->byID($filter['anyChildId']);
$id = $child ? ($child->ParentID ?: 0) : 0;
if ($id) {
Expand Down
7 changes: 1 addition & 6 deletions code/GraphQL/Resolvers/AssetAdminResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public static function resolveDeleteFiles($object, array $args, $context, Resolv
}
$idList = $args['ids'];

/** @var DataList $file */
$files = Versioned::get_by_stage(File::class, Versioned::DRAFT)->byIDs($idList);
if ($files->count() < count($idList ?? [])) {
// Find out which files count not be found
Expand Down Expand Up @@ -142,7 +141,6 @@ public static function resolveMoveFiles($object, array $args, $context)
$member = UserContextProvider::get($context);

if ($folderId) {
/** @var Folder $folder */
$folder = Versioned::get_by_stage(Folder::class, Versioned::DRAFT)
->byID($folderId);
if (!$folder) {
Expand All @@ -164,7 +162,6 @@ public static function resolveMoveFiles($object, array $args, $context)
$files = Versioned::get_by_stage(File::class, Versioned::DRAFT)
->byIDs($args['fileIds']);
$errorFiles = [];
/** @var File $file */
foreach ($files as $file) {
if ($file->canEdit($member)) {
$file->ParentID = $folderId;
Expand Down Expand Up @@ -225,7 +222,6 @@ public static function resolveReadDescendantFileCounts($object, array $args, $co
}
$ids = $args['ids'];

/** @var DataList|File[] $files */
$files = Versioned::get_by_stage(File::class, Versioned::DRAFT)->byIDs($ids);
if ($files->count() < count($ids ?? [])) {
$class = File::class;
Expand Down Expand Up @@ -253,7 +249,6 @@ public static function resolveReadFileUsage($object, array $args, $context, Reso
}
$idList = $args['ids'];

/** @var DataList|File[] $files */
$files = Versioned::get_by_stage(File::class, Versioned::DRAFT)->byIDs($idList);
if ($files->count() < count($idList ?? [])) {
// Find out which files count not be found
Expand Down Expand Up @@ -285,7 +280,7 @@ public static function resolveReadFileUsage($object, array $args, $context, Reso
* @param array $args
* @param $context
* @param $info
* @return DataList|Filterable
* @return DataList<File>
* @throws HTTPResponse_Exception
*/
public static function resolveReadFiles($object, array $args = [], $context = [], $info = null)
Expand Down
1 change: 0 additions & 1 deletion code/GraphQL/Resolvers/FolderTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public static function resolveFolderChildren(
));
}

/** @var DataList $list */
$list = Versioned::get_by_stage(File::class, 'Stage');
$filter['parentId'] = $object->ID;
$list = FileFilter::filterList($list, $filter);
Expand Down
1 change: 0 additions & 1 deletion code/Helper/ImageThumbnailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function setMaxImageFileSize($size)
*/
public function run()
{
/** @var File[]|SS_List $files */
$files = File::get();
$totalCount = $files->count();
if (!$totalCount) {
Expand Down
Loading