From c5f42d99a3ad599799df479e102bceb7acdb0519 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 9 Jan 2019 20:56:19 +0100 Subject: [PATCH 1/3] MNT Update phpcs ruleset to use PSR-12 as a base --- phpcs.xml.dist | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index ddad7d2b..44f19d15 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -5,20 +5,9 @@ code tests - - + + - - - - - - - - - - - - + From 213f7167a6304c5c9e4533ff3760d9e0141a2662 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 9 Jan 2019 20:59:28 +0100 Subject: [PATCH 2/3] ENH Fix phpcs violations --- code/Report.php | 11 ++++++++--- code/ReportAdmin.php | 13 ++++++++----- code/ReportWrapper.php | 2 +- code/SideReportView.php | 4 ++-- tests/ReportAdminTest.php | 1 + tests/ReportAdminTest/FakeReport.php | 1 + tests/ReportAdminTest/FakeReport2.php | 1 + tests/ReportTest/FakeTestAbstract.php | 1 - 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/code/Report.php b/code/Report.php index 6120a4c3..45e05c5d 100644 --- a/code/Report.php +++ b/code/Report.php @@ -61,7 +61,8 @@ * Right now, all subclasses of SS_Report will be shown in the ReportAdmin. In SS3 there is only * one place where reports can go, so this class is greatly simplifed from its version in SS2. * - * @method SS_List|DataList sourceRecords($params = [], $sort = null, $limit = null) List of records to show for this report + * @method SS_List|DataList sourceRecords($params = [], $sort = null, $limit = null) + * List of records to show for this report */ class Report extends ViewableData { @@ -158,7 +159,8 @@ public function sourceQuery($params) { if (!$this->hasMethod('sourceRecords')) { throw new \RuntimeException( - 'Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()' + 'Please override sourceQuery()/sourceRecords() and columns() or, ' + . 'if necessary, override getReportField()' ); } @@ -353,7 +355,10 @@ public function getCMSFields() } // Add a search button - $formAction = FormAction::create('updatereport', _t('SilverStripe\\Forms\\GridField\\GridField.Filter', 'Filter')); + $formAction = FormAction::create( + 'updatereport', + _t('SilverStripe\\Forms\\GridField\\GridField.Filter', 'Filter') + ); $formAction->addExtraClass('btn-primary mb-4'); $fields->push($formAction); diff --git a/code/ReportAdmin.php b/code/ReportAdmin.php index 83aa57cb..7d732482 100644 --- a/code/ReportAdmin.php +++ b/code/ReportAdmin.php @@ -181,13 +181,13 @@ public function Breadcrumbs($unlinked = false) } //build breadcrumb trail to the current report - $items->push(new ArrayData(array( + $items->push(ArrayData::create([ 'Title' => $report->title(), 'Link' => Controller::join_links( $this->Link(), - '?' . http_build_query(array('q' => $this->request->requestVar('q'))) + '?' . http_build_query(['q' => $this->request->requestVar('q')]) ) - ))); + ])); } return $items; @@ -236,7 +236,8 @@ public function getEditForm($id = null, $fields = null) ); $gridField = GridField::create('Reports', false, $this->Reports(), $gridFieldConfig); /** @var GridFieldDataColumns $columns */ - $columns = $gridField->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); + $columns = $gridField->getConfig() + ->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns->setDisplayFields(array( 'title' => _t('SilverStripe\\Reports\\ReportAdmin.ReportTitle', 'Title'), )); @@ -250,7 +251,9 @@ public function getEditForm($id = null, $fields = null) $actions = new FieldList(); $form = new Form($this, "EditForm", $fields, $actions); - $form->addExtraClass('panel panel--padded panel--scrollable cms-edit-form cms-panel-padded' . $this->BaseCSSClasses()); + $form->addExtraClass( + 'panel panel--padded panel--scrollable cms-edit-form cms-panel-padded' . $this->BaseCSSClasses() + ); $form->loadDataFrom($this->request->getVars()); $this->extend('updateEditForm', $form); diff --git a/code/ReportWrapper.php b/code/ReportWrapper.php index e6fae9f2..88c1ca89 100644 --- a/code/ReportWrapper.php +++ b/code/ReportWrapper.php @@ -21,7 +21,7 @@ abstract class ReportWrapper extends Report public function __construct($baseReport) { - $this->baseReport = is_string($baseReport) ? new $baseReport : $baseReport; + $this->baseReport = is_string($baseReport) ? new $baseReport() : $baseReport; $this->dataClass = $this->baseReport->dataClass(); parent::__construct(); } diff --git a/code/SideReportView.php b/code/SideReportView.php index d80058b9..e7d627b1 100644 --- a/code/SideReportView.php +++ b/code/SideReportView.php @@ -11,8 +11,8 @@ */ class SideReportView extends ViewableData { - - protected $controller, $report; + protected $controller; + protected $report; protected $parameters; public function __construct($controller, $report) diff --git a/tests/ReportAdminTest.php b/tests/ReportAdminTest.php index f84576b3..dcf7c816 100644 --- a/tests/ReportAdminTest.php +++ b/tests/ReportAdminTest.php @@ -1,4 +1,5 @@ Date: Fri, 22 Mar 2019 13:58:43 +1300 Subject: [PATCH 3/3] Use Injector to instantiate new base report instances --- code/ReportWrapper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/ReportWrapper.php b/code/ReportWrapper.php index 88c1ca89..8c0daec6 100644 --- a/code/ReportWrapper.php +++ b/code/ReportWrapper.php @@ -2,6 +2,8 @@ namespace SilverStripe\Reports; +use SilverStripe\Core\Injector\Injector; + /** * SS_ReportWrapper is a base class for creating report wappers. * @@ -21,7 +23,7 @@ abstract class ReportWrapper extends Report public function __construct($baseReport) { - $this->baseReport = is_string($baseReport) ? new $baseReport() : $baseReport; + $this->baseReport = is_string($baseReport) ? Injector::inst()->create($baseReport) : $baseReport; $this->dataClass = $this->baseReport->dataClass(); parent::__construct(); }