From 09db0d33d2802069ea7aa33a264e509b0b82f9ed Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 16:30:08 +1200 Subject: [PATCH] ENH Use class name instead of self --- code/Company.php | 2 +- .../ArbitraryDataAdmin.php | 18 ++++++++--------- .../ArbitraryDataModel.php | 8 ++++---- code/TestPage.php | 4 ++-- code/tasks/FTFileMakerTask.php | 20 +++++++++---------- code/tasks/FTPageMakerTask.php | 6 +++--- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/code/Company.php b/code/Company.php index 6356f1b..5e27c21 100644 --- a/code/Company.php +++ b/code/Company.php @@ -365,7 +365,7 @@ public function data() public function scaffoldSearchField() { - return DropdownField::create('CompanyID', 'Company', self::get()->map())->setEmptyString(''); + return DropdownField::create('CompanyID', 'Company', Company::get()->map())->setEmptyString(''); } } diff --git a/code/GridFieldArbitraryData/ArbitraryDataAdmin.php b/code/GridFieldArbitraryData/ArbitraryDataAdmin.php index 9d1bdc9..d16fc9d 100644 --- a/code/GridFieldArbitraryData/ArbitraryDataAdmin.php +++ b/code/GridFieldArbitraryData/ArbitraryDataAdmin.php @@ -56,10 +56,10 @@ protected function init() // accessing the admin directly if ($this->tab === null) { - $this->tab = self::TAB_ARRAYDATA; + $this->tab = ArbitraryDataAdmin::TAB_ARRAYDATA; } - if ($this->tab !== self::TAB_ARRAYDATA && $this->tab !== self::TAB_CUSTOM_MODEL) { + if ($this->tab !== ArbitraryDataAdmin::TAB_ARRAYDATA && $this->tab !== ArbitraryDataAdmin::TAB_CUSTOM_MODEL) { throw new RuntimeException("Unexpected url segment: {$this->tab}"); } } @@ -69,12 +69,12 @@ public function getList() $list = ArrayList::create(); switch ($this->tab) { - case self::TAB_ARRAYDATA: - foreach (self::getInitialRecords() as $stub) { + case ArbitraryDataAdmin::TAB_ARRAYDATA: + foreach (ArbitraryDataAdmin::getInitialRecords() as $stub) { $list->add(ArrayData::create($stub)); } break; - case self::TAB_CUSTOM_MODEL: + case ArbitraryDataAdmin::TAB_CUSTOM_MODEL: $rawData = SQLSelect::create()->setFrom(ArbitraryDataModel::TABLE_NAME)->execute(); foreach ($rawData as $record) { $list->add(ArbitraryDataModel::create($record)); @@ -105,14 +105,14 @@ public static function getInitialRecords() protected function getGridFieldConfig(): GridFieldConfig { - if ($this->tab === self::TAB_CUSTOM_MODEL) { + if ($this->tab === ArbitraryDataAdmin::TAB_CUSTOM_MODEL) { $config = GridFieldConfig_RecordEditor::create(); } else { // This is effectively the same as a GridFieldConfig_RecordViewer, but without removing the GridFieldFilterHeader. $config = GridFieldConfig_Base::create(); $config->addComponent(GridFieldViewButton::create()); $config->addComponent(GridFieldDetailForm::create()); - $fieldNames = array_keys(self::getInitialRecords()[0]); + $fieldNames = array_keys(ArbitraryDataAdmin::getInitialRecords()[0]); $config->getComponentByType(GridFieldDataColumns::class)->setDisplayFields(array_combine($fieldNames, $fieldNames)); $fields = array_map(fn ($name) => $name === 'ID' ? HiddenField::create($name) : TextField::create($name), $fieldNames); $config->getComponentByType(GridFieldDetailForm::class)->setFields(FieldList::create($fields)); @@ -188,8 +188,8 @@ public function getEditForm($id = null, $fields = null) protected function getManagedTabs() { $tabs = [ - self::TAB_ARRAYDATA => 'ArrayData', - self::TAB_CUSTOM_MODEL => 'Custom Model', + ArbitraryDataAdmin::TAB_ARRAYDATA => 'ArrayData', + ArbitraryDataAdmin::TAB_CUSTOM_MODEL => 'Custom Model', ]; $forms = new ArrayList(); diff --git a/code/GridFieldArbitraryData/ArbitraryDataModel.php b/code/GridFieldArbitraryData/ArbitraryDataModel.php index 60784f7..56bfbec 100644 --- a/code/GridFieldArbitraryData/ArbitraryDataModel.php +++ b/code/GridFieldArbitraryData/ArbitraryDataModel.php @@ -61,7 +61,7 @@ public function write() } // Remove anything that isn't storable in the DB, such as Security ID - $dbColumns = DB::field_list(self::TABLE_NAME); + $dbColumns = DB::field_list(ArbitraryDataModel::TABLE_NAME); foreach ($record as $fieldName => $value) { if (!array_key_exists($fieldName, $dbColumns)) { unset($record[$fieldName]); @@ -76,11 +76,11 @@ public function write() if (!$isNew) { $manipulation['id'] = $this->ID; } - DB::manipulate([self::TABLE_NAME => $manipulation]); + DB::manipulate([ArbitraryDataModel::TABLE_NAME => $manipulation]); if ($isNew) { // Must save the ID in this object so GridField knows what URL to redirect to. - $this->ID = DB::get_generated_id(self::TABLE_NAME); + $this->ID = DB::get_generated_id(ArbitraryDataModel::TABLE_NAME); } } @@ -89,7 +89,7 @@ public function delete() if (!$this->ID) { throw new LogicException('DataObject::delete() called on a record without an ID'); } - SQLDelete::create()->setFrom(self::TABLE_NAME)->setWhere(['ID' => $this->ID])->execute(); + SQLDelete::create()->setFrom(ArbitraryDataModel::TABLE_NAME)->setWhere(['ID' => $this->ID])->execute(); $this->ID = 0; } diff --git a/code/TestPage.php b/code/TestPage.php index 67c166b..607d9fd 100644 --- a/code/TestPage.php +++ b/code/TestPage.php @@ -36,7 +36,7 @@ public function canCreate($member = null, $context = array()) public function requireDefaultRecords() { - if (static::class === self::class) { + if (static::class === TestPage::class) { return; } @@ -46,7 +46,7 @@ public function requireDefaultRecords() Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () { // Create actual page $page = new static(); - $page->Title = str_replace(self::class, "", static::class); + $page->Title = str_replace(TestPage::class, "", static::class); $page->ShowInMenus = 0; $parent = static::getOrCreateParentPage(); $page->ParentID = $parent->ID; diff --git a/code/tasks/FTFileMakerTask.php b/code/tasks/FTFileMakerTask.php index 51e32a3..c23dfd1 100644 --- a/code/tasks/FTFileMakerTask.php +++ b/code/tasks/FTFileMakerTask.php @@ -228,7 +228,7 @@ public function run($request) return (int) trim($int ?? ''); }, $counts ?? []); } else { - $this->fileCounts = self::config()->get('fileCountByDepth'); + $this->fileCounts = FTFileMakerTask::config()->get('fileCountByDepth'); } $folderCounts = $request->getVar('folderCounts'); @@ -238,13 +238,13 @@ public function run($request) return (int) trim($int ?? ''); }, $counts ?? []); } else { - $this->folderCounts = self::config()->get('folderCountByDepth'); + $this->folderCounts = FTFileMakerTask::config()->get('folderCountByDepth'); } echo "Downloading fixtures" . $this->lineBreak; $fixtureFilePaths = $this->downloadFixtureFiles(); - if (!self::config()->get('documentsOnly')) { + if (!FTFileMakerTask::config()->get('documentsOnly')) { echo "Generate thumbnails" . $this->lineBreak; $this->generateThumbnails($fixtureFilePaths); } @@ -252,7 +252,7 @@ public function run($request) echo "Generate files" . $this->lineBreak; $this->generateFiles($fixtureFilePaths); - if (!self::config()->get('doPutProtectedFilesInPublicStore')) { + if (!FTFileMakerTask::config()->get('doPutProtectedFilesInPublicStore')) { echo "Incorrectly putting protected files into public asset store on purpose" . $this->lineBreak; $this->putProtectedFilesInPublicAssetStore(); } @@ -276,7 +276,7 @@ protected function downloadFixtureFiles() $client = new Client(['base_uri' => $this->fixtureFileBaseUrl]); $fixtureFileNames = $this->fixtureFileNames; - if (self::config()->get('documentsOnly')) { + if (FTFileMakerTask::config()->get('documentsOnly')) { $fixtureFileNames = array_filter($fixtureFileNames ?? [], function($v) { return (bool) preg_match('%\.(docx|xlsx|pdf)$%', $v ?? ''); }); @@ -337,12 +337,12 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $ $folderCount = $this->folderCounts[$depth]; $fileCount = $this->fileCounts[$depth]; - $doSetFolderPermissions = (bool) self::config()->get('doSetFolderPermissions'); + $doSetFolderPermissions = (bool) FTFileMakerTask::config()->get('doSetFolderPermissions'); - $doSetOldCreationDate = (bool) self::config()->get('doSetOldCreationDate'); - $doRandomlyPublish = (bool) self::config()->get('doRandomlyPublish'); + $doSetOldCreationDate = (bool) FTFileMakerTask::config()->get('doSetOldCreationDate'); + $doRandomlyPublish = (bool) FTFileMakerTask::config()->get('doRandomlyPublish'); - $uniqueImages = (bool) self::config()->get('uniqueImages'); + $uniqueImages = (bool) FTFileMakerTask::config()->get('uniqueImages'); $watermarkPath = ModuleResourceLoader::singleton()->resolvePath( 'silverstripe/frameworktest: images/silverstripe.png' ); @@ -424,7 +424,7 @@ protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $ } } - if ($depth < self::config()->get('depth') - 1) { + if ($depth < FTFileMakerTask::config()->get('depth') - 1) { $this->generateFiles($fixtureFilePaths, $depth + 1, "{$prefix}-{$i}", $folder->ID); } } diff --git a/code/tasks/FTPageMakerTask.php b/code/tasks/FTPageMakerTask.php index 8ac0d71..4d8b276 100644 --- a/code/tasks/FTPageMakerTask.php +++ b/code/tasks/FTPageMakerTask.php @@ -43,9 +43,9 @@ class FTPageMakerTask extends BuildTask * @config */ private static $block_generators = [ - 'DNADesign\Elemental\Models\ElementContent' => [self::class, 'generateContentBlock'], - 'SilverStripe\ElementalBannerBlock\Block\BannerBlock' => [self::class, 'generateBannerBlock'], - 'SilverStripe\ElementalFileBlock\Block\FileBlock' => [self::class, 'generateFileBlock'], + 'DNADesign\Elemental\Models\ElementContent' => [FTPageMakerTask::class, 'generateContentBlock'], + 'SilverStripe\ElementalBannerBlock\Block\BannerBlock' => [FTPageMakerTask::class, 'generateBannerBlock'], + 'SilverStripe\ElementalFileBlock\Block\FileBlock' => [FTPageMakerTask::class, 'generateFileBlock'], ]; public function run($request)