ENH: Prefer dependency injection over use of new keyword. (#333)

* ENH: Prefer dependency injection over use of `new` keyword.

* MNT Fix phpcs linting error.
This commit is contained in:
Guy Sartorelli 2022-02-18 16:44:54 +13:00 committed by GitHub
parent 8e9ee0bace
commit 8c4e924bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 19 deletions

View File

@ -96,7 +96,7 @@ class GridFieldAddExistingSearchHandler extends RequestHandler
{ {
$list = $this->context->getQuery($data, false, false, $this->getSearchList()); $list = $this->context->getQuery($data, false, false, $this->getSearchList());
$list = $list->subtract($this->grid->getList()); $list = $list->subtract($this->grid->getList());
$list = new PaginatedList($list, $this->request); $list = PaginatedList::create($list, $this->request);
$data = $this->customise(array( $data = $this->customise(array(
'SearchForm' => $form, 'SearchForm' => $form,
@ -109,7 +109,7 @@ class GridFieldAddExistingSearchHandler extends RequestHandler
{ {
$list = $this->getSearchList(); $list = $this->getSearchList();
$list = $list->subtract($this->grid->getList()); $list = $list->subtract($this->grid->getList());
$list = new PaginatedList($list, $this->request); $list = PaginatedList::create($list, $this->request);
return $list; return $list;
} }

View File

@ -102,7 +102,7 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
Requirements::javascript('symbiote/silverstripe-gridfieldextensions:javascript/tmpl.js'); Requirements::javascript('symbiote/silverstripe-gridfieldextensions:javascript/tmpl.js');
GridFieldExtensions::include_requirements(); GridFieldExtensions::include_requirements();
$data = new ArrayData(array( $data = ArrayData::create(array(
'Title' => $this->getTitle(), 'Title' => $this->getTitle(),
)); ));
@ -114,7 +114,7 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable) private function getRowTemplate(GridField $grid, GridFieldEditableColumns $editable)
{ {
$columns = new ArrayList(); $columns = ArrayList::create();
$handled = array_keys($editable->getDisplayFields($grid)); $handled = array_keys($editable->getDisplayFields($grid));
if ($grid->getList()) { if ($grid->getList()) {
@ -161,7 +161,7 @@ class GridFieldAddNewInlineButton implements GridField_HTMLProvider, GridField_S
$attrs .= sprintf(' %s="%s"', $attr, Convert::raw2att($val)); $attrs .= sprintf(' %s="%s"', $attr, Convert::raw2att($val));
} }
$columns->push(new ArrayData(array( $columns->push(ArrayData::create(array(
'Content' => $content, 'Content' => $content,
'Attributes' => DBField::create_field('HTMLFragment', $attrs), 'Attributes' => DBField::create_field('HTMLFragment', $attrs),
'IsActions' => $column == 'Actions' 'IsActions' => $column == 'Actions'

View File

@ -244,13 +244,18 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
GridFieldExtensions::include_requirements(); GridFieldExtensions::include_requirements();
$field = new DropdownField(sprintf('%s[%s]', __CLASS__, $grid->getName()), '', $classes, $this->defaultClass); $field = DropdownField::create(
sprintf('%s[%s]', __CLASS__, $grid->getName()),
'',
$classes,
$this->defaultClass
);
if (Config::inst()->get(__CLASS__, 'showEmptyString')) { if (Config::inst()->get(__CLASS__, 'showEmptyString')) {
$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)')); $field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
} }
$field->addExtraClass('no-change-track'); $field->addExtraClass('no-change-track');
$data = new ArrayData(array( $data = ArrayData::create(array(
'Title' => $this->getTitle(), 'Title' => $this->getTitle(),
'Link' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'), 'Link' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'),
'ClassField' => $field 'ClassField' => $field

View File

@ -83,7 +83,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
// Fall back to previous logic // Fall back to previous logic
if (!$field) { if (!$field) {
$rel = (strpos($col, '.') === false); // field references a relation value $rel = (strpos($col, '.') === false); // field references a relation value
$field = ($rel) ? clone $fields->fieldByName($col) : new ReadonlyField($col); $field = ($rel) ? clone $fields->fieldByName($col) : ReadonlyField::create($col);
} }
if (!$field) { if (!$field) {
@ -211,7 +211,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
public function getFields(GridField $grid, DataObjectInterface $record) public function getFields(GridField $grid, DataObjectInterface $record)
{ {
$cols = $this->getDisplayFields($grid); $cols = $this->getDisplayFields($grid);
$fields = new FieldList(); $fields = FieldList::create();
/** @var DataList $list */ /** @var DataList $list */
$list = $grid->getList(); $list = $grid->getList();
@ -263,12 +263,12 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
if ($class && $obj = DataObject::singleton($class)->dbObject($colRelation[0])) { if ($class && $obj = DataObject::singleton($class)->dbObject($colRelation[0])) {
$field = $obj->scaffoldFormField(); $field = $obj->scaffoldFormField();
} else { } else {
$field = new ReadonlyField($colRelation[0]); $field = ReadonlyField::create($colRelation[0]);
} }
} elseif ($class && $obj = DataObject::singleton($class)->dbObject($col)) { } elseif ($class && $obj = DataObject::singleton($class)->dbObject($col)) {
$field = $obj->scaffoldFormField(); $field = $obj->scaffoldFormField();
} else { } else {
$field = new ReadonlyField($col); $field = ReadonlyField::create($col);
} }
} }
@ -301,7 +301,7 @@ class GridFieldEditableColumns extends GridFieldDataColumns implements
{ {
$fields = $this->getFields($grid, $record); $fields = $this->getFields($grid, $record);
$form = new Form($grid, null, $fields, new FieldList()); $form = Form::create($grid, null, $fields, FieldList::create());
$form->loadDataFrom($record); $form->loadDataFrom($record);
$form->setFormAction(Controller::join_links( $form->setFormAction(Controller::join_links(

View File

@ -72,7 +72,7 @@ class GridFieldExternalLink extends GridFieldDataColumns
*/ */
public function getColumnContent($gridField, $record, $columnName) public function getColumnContent($gridField, $record, $columnName)
{ {
$data = new ArrayData(array( $data = ArrayData::create(array(
'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink, 'Link' => $record->hasMethod('getExternalLink') ? $record->getExternalLink() : $record->ExternalLink,
'Text' => $record->hasMethod('getExternalLinkText') ? $record->getExternalLinkText() : 'External Link' 'Text' => $record->hasMethod('getExternalLinkText') ? $record->getExternalLinkText() : 'External Link'
)); ));

View File

@ -83,11 +83,11 @@ abstract class GridFieldRequestHandler extends RequestHandler
*/ */
public function Form() public function Form()
{ {
$form = new Form( $form = Form::create(
$this, $this,
'SilverStripe\\Forms\\Form', 'SilverStripe\\Forms\\Form',
new FieldList($root = new TabSet('Root', new Tab('Main'))), FieldList::create($root = TabSet::create('Root', Tab::create('Main'))),
new FieldList() FieldList::create()
); );
if ($this->getTopLevelController() instanceof LeftAndMain) { if ($this->getTopLevelController() instanceof LeftAndMain) {
@ -136,7 +136,7 @@ abstract class GridFieldRequestHandler extends RequestHandler
if ($controller->hasMethod('Breadcrumbs')) { if ($controller->hasMethod('Breadcrumbs')) {
return $controller->Breadcrumbs(); return $controller->Breadcrumbs();
} else { } else {
return new ArrayList(); return ArrayList::create();
} }
} }

View File

@ -14,12 +14,12 @@ class GridFieldTitleHeader implements GridField_HTMLProvider
public function getHTMLFragments($grid) public function getHTMLFragments($grid)
{ {
$cols = new ArrayList(); $cols = ArrayList::create();
foreach ($grid->getColumns() as $name) { foreach ($grid->getColumns() as $name) {
$meta = $grid->getColumnMetadata($name); $meta = $grid->getColumnMetadata($name);
$cols->push(new ArrayData(array( $cols->push(ArrayData::create(array(
'Name' => $name, 'Name' => $name,
'Title' => $meta['title'] 'Title' => $meta['title']
))); )));