Merge pull request #115 from creative-commoners/pulls/5.0/psr-12

Rename code folder to src, update phpcs rulset to PSR-12 as a base and fix violations
This commit is contained in:
Guy Marriott 2019-03-25 09:13:50 +13:00 committed by GitHub
commit 595e1f3d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 31 deletions

View File

@ -1,9 +1,15 @@
inherit: true
build:
nodes:
analysis:
tests:
override: [php-scrutinizer-run]
checks:
php:
code_rating: true
duplication: true
filter:
paths: [code/*, tests/*]
paths: [src/*, tests/*]

View File

@ -32,7 +32,6 @@ before_script:
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:3.x-dev --no-update; fi
- if [[ $DB == SQLITE ]]; then composer require silverstripe/sqlite3:3.x-dev --no-update; fi
- composer require silverstripe/recipe-core:5.x-dev silverstripe/admin:2.x-dev silverstripe/versioned:2.x-dev --no-update
- if [[ $PHPCS_TEST ]]; then composer global require squizlabs/php_codesniffer:^3 --prefer-dist --no-interaction --no-progress --no-suggest -o; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
script:

View File

@ -26,7 +26,8 @@
"silverstripe/vendor-plugin": "^1"
},
"require-dev": {
"phpunit/phpunit": "^7"
"phpunit/phpunit": "^7",
"squizlabs/php_codesniffer": "^3"
},
"extra": {
"branch-alias": {
@ -38,13 +39,13 @@
},
"autoload": {
"psr-4": {
"SilverStripe\\Reports\\": "code/",
"SilverStripe\\Reports\\": "src/",
"SilverStripe\\Reports\\Tests\\": "tests/"
}
},
"scripts": {
"lint": "phpcs code/ tests/",
"lint-clean": "phpcbf code/ tests/"
"lint": "vendor/bin/phpcs src/ tests/",
"lint-clean": "vendor/bin/phpcbf src/ tests/"
},
"minimum-stability": "dev",
"prefer-stable": true

View File

@ -2,21 +2,10 @@
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- base rules are PSR-12 -->
<rule ref="PSR12" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
</rule>
</ruleset>

View File

@ -59,7 +59,8 @@ use SilverStripe\View\ViewableData;
* 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
{
@ -149,7 +150,11 @@ class Report extends ViewableData
if ($this->hasMethod('sourceRecords')) {
return $this->sourceRecords($params, null, null)->dataQuery();
} else {
user_error("Please override sourceQuery()/sourceRecords() and columns() or, if necessary, override getReportField()", E_USER_ERROR);
user_error(
"Please override sourceQuery()/sourceRecords() and columns() or, if necessary, "
. "override getReportField()",
E_USER_ERROR
);
}
}
@ -313,7 +318,10 @@ class Report extends ViewableData
}
// 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);

View File

@ -174,10 +174,13 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
if ($this->reportObject) {
//build breadcrumb trail to the current report
$items->push(new ArrayData(array(
$items->push(ArrayData::create([
'Title' => $this->reportObject->title(),
'Link' => Controller::join_links($this->Link(), '?' . http_build_query(array('q' => $this->request->requestVar('q'))))
)));
'Link' => Controller::join_links(
$this->Link(),
'?' . http_build_query(['q' => $this->request->requestVar('q')])
)
]));
}
return $items;
@ -226,7 +229,8 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
);
$gridField = new GridField('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'),
));
@ -240,7 +244,9 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
$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);

View File

@ -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();
}

View File

@ -11,8 +11,8 @@ use SilverStripe\View\ViewableData;
*/
class SideReportView extends ViewableData
{
protected $controller, $report;
protected $controller;
protected $report;
protected $parameters;
public function __construct($controller, $report)