OSS-905 PSR2 compliance

This commit is contained in:
Shoaib Ali 2015-11-07 15:42:22 +13:00
parent eee39bca4e
commit 0a19119114
9 changed files with 185 additions and 197 deletions

View File

@ -5,7 +5,6 @@
* @package widgets * @package widgets
*/ */
class WidgetContentControllerExtension extends Extension { class WidgetContentControllerExtension extends Extension {
/** /**
* *
* @var array * @var array
@ -27,7 +26,9 @@ class WidgetContentControllerExtension extends Extension {
*/ */
public function handleWidget() { public function handleWidget() {
$SQL_id = $this->owner->getRequest()->param('ID'); $SQL_id = $this->owner->getRequest()->param('ID');
if(!$SQL_id) return false; if (!$SQL_id) {
return false;
}
// find WidgetArea relations // find WidgetArea relations
$widgetAreaRelations = array(); $widgetAreaRelations = array();

View File

@ -19,7 +19,6 @@
* @package widgets * @package widgets
*/ */
class WidgetController extends Controller { class WidgetController extends Controller {
/** /**
* @var Widget * @var Widget
*/ */
@ -116,5 +115,4 @@ class WidgetController extends Controller {
* @package widgets * @package widgets
*/ */
class Widget_Controller extends WidgetController { class Widget_Controller extends WidgetController {
} }

View File

@ -9,7 +9,6 @@
* without using this class. * without using this class.
*/ */
class WidgetPageExtension extends DataExtension { class WidgetPageExtension extends DataExtension {
private static $db = array( private static $db = array(
'InheritSideBar' => 'Boolean', 'InheritSideBar' => 'Boolean',
); );
@ -60,7 +59,6 @@ class WidgetPageExtension extends DataExtension {
} }
$duplicatePage->SideBarID = $duplicateWidgetArea->ID; $duplicatePage->SideBarID = $duplicateWidgetArea->ID;
} }
return $duplicatePage; return $duplicatePage;
@ -73,5 +71,4 @@ class WidgetPageExtension extends DataExtension {
//reset the sidebar ID //reset the sidebar ID
$this->owner->SideBarID = 0; $this->owner->SideBarID = 0;
} }
} }

View File

@ -6,7 +6,6 @@
* @package widgets * @package widgets
*/ */
class WidgetAreaEditor extends FormField { class WidgetAreaEditor extends FormField {
/** /**
* @param string $name * @param string $name
* @param array $widgetClasses * @param array $widgetClasses
@ -43,13 +42,11 @@ class WidgetAreaEditor extends FormField {
if (isset($classes['Widget'])) { if (isset($classes['Widget'])) {
unset($classes['Widget']); unset($classes['Widget']);
} } elseif (isset($classes[0]) && $classes[0] == 'Widget') {
else if (isset($classes[0]) && $classes[0] == 'Widget') {
unset($classes[0]); unset($classes[0]);
} }
foreach ($classes as $class) { foreach ($classes as $class) {
$available = Config::inst()->get($class, 'only_available_in'); $available = Config::inst()->get($class, 'only_available_in');
if (!empty($available) && is_array($available)) { if (!empty($available) && is_array($available)) {
@ -119,7 +116,9 @@ class WidgetAreaEditor extends FormField {
} }
} }
if(!$this->getForm()) throw new Exception("no form"); if (!$this->getForm()) {
throw new Exception("no form");
}
$widgetData = $this->getForm()->getRequest()->requestVar('Widget'); $widgetData = $this->getForm()->getRequest()->requestVar('Widget');
if ($widgetData && isset($widgetData[$this->getName()])) { if ($widgetData && isset($widgetData[$this->getName()])) {

View File

@ -11,7 +11,6 @@
* @package widgets * @package widgets
*/ */
class Widget extends DataObject { class Widget extends DataObject {
/** /**
* @var array * @var array
*/ */
@ -271,8 +270,7 @@ class Widget extends DataObject {
if ($field = $fields->dataFieldByName($name)) { if ($field = $fields->dataFieldByName($name)) {
$field->setValue($value); $field->setValue($value);
$field->saveInto($this); $field->saveInto($this);
} } else {
else {
$this->setField($name, $value); $this->setField($name, $value);
} }
} }
@ -293,4 +291,3 @@ class Widget extends DataObject {
$this->write(); $this->write();
} }
} }

View File

@ -6,7 +6,6 @@
* @package widgets * @package widgets
*/ */
class WidgetArea extends DataObject { class WidgetArea extends DataObject {
/** /**
* @var array * @var array
*/ */
@ -80,4 +79,3 @@ class WidgetArea extends DataObject {
} }
} }
} }

View File

@ -22,7 +22,7 @@ class WidgetAreaEditorTest extends SapphireTest {
) )
); );
function testFillingOneArea() { public function testFillingOneArea() {
$data = array( $data = array(
'Widget' => array( 'Widget' => array(
'BottomBar' => array( 'BottomBar' => array(
@ -53,7 +53,7 @@ class WidgetAreaEditorTest extends SapphireTest {
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0); $this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
} }
function testFillingTwoAreas() { public function testFillingTwoAreas() {
$data = array( $data = array(
'Widget' => array( 'Widget' => array(
'SideBar' => array( 'SideBar' => array(
@ -96,7 +96,7 @@ class WidgetAreaEditorTest extends SapphireTest {
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom'); $this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
} }
function testDeletingOneWidgetFromOneArea() { public function testDeletingOneWidgetFromOneArea() {
// First get some widgets in there // First get some widgets in there
$data = array( $data = array(
'Widget' => array( 'Widget' => array(
@ -162,7 +162,7 @@ class WidgetAreaEditorTest extends SapphireTest {
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0); $this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
} }
function testDeletingAWidgetFromEachArea() { public function testDeletingAWidgetFromEachArea() {
// First get some widgets in there // First get some widgets in there
$data = array( $data = array(
'Widget' => array( 'Widget' => array(
@ -222,7 +222,7 @@ class WidgetAreaEditorTest extends SapphireTest {
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0); $this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
} }
function testEditingOneWidget() { public function testEditingOneWidget() {
// First get some widgets in there // First get some widgets in there
$data = array( $data = array(
'Widget' => array( 'Widget' => array(
@ -294,7 +294,7 @@ class WidgetAreaEditorTest extends SapphireTest {
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited'); $this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
} }
function testEditingAWidgetFromEachArea() { public function testEditingAWidgetFromEachArea() {
// First get some widgets in there // First get some widgets in there
$data = array( $data = array(
'Widget' => array( 'Widget' => array(
@ -366,7 +366,7 @@ class WidgetAreaEditorTest extends SapphireTest {
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited'); $this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
} }
function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea() { public function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea() {
// First get some widgets in there // First get some widgets in there
$data = array( $data = array(
'Widget' => array( 'Widget' => array(

View File

@ -4,7 +4,6 @@
* @subpackage tests * @subpackage tests
*/ */
class WidgetControllerTest extends FunctionalTest { class WidgetControllerTest extends FunctionalTest {
protected static $fixture_file = 'WidgetControllerTest.yml'; protected static $fixture_file = 'WidgetControllerTest.yml';
protected $extraDataObjects = array( protected $extraDataObjects = array(
@ -12,7 +11,7 @@ class WidgetControllerTest extends FunctionalTest {
'WidgetControllerTest_Widget', 'WidgetControllerTest_Widget',
); );
function testWidgetFormRendering() { public function testWidgetFormRendering() {
$page = $this->objFromFixture('WidgetControllerTestPage', 'page1'); $page = $this->objFromFixture('WidgetControllerTestPage', 'page1');
$page->publish('Stage', 'Live'); $page->publish('Stage', 'Live');
@ -28,7 +27,7 @@ class WidgetControllerTest extends FunctionalTest {
); );
} }
function testWidgetFormSubmission() { public function testWidgetFormSubmission() {
$page = $this->objFromFixture('WidgetControllerTestPage', 'page1'); $page = $this->objFromFixture('WidgetControllerTestPage', 'page1');
$page->publish('Stage', 'Live'); $page->publish('Stage', 'Live');
@ -64,13 +63,13 @@ class WidgetControllerTest_Widget extends Widget implements TestOnly {
* @package widgets * @package widgets
* @subpackage tests * @subpackage tests
*/ */
class WidgetControllerTest_WidgetController extends WidgetController implements TestOnly { class WidgetControllerTest_WidgetController extends WidgetController implements TestOnly
{
private static $allowed_actions = array( private static $allowed_actions = array(
'Form' 'Form'
); );
function Form() { public function Form() {
$widgetform = new Form( $widgetform = new Form(
$this, $this,
'Form', 'Form',
@ -85,7 +84,7 @@ class WidgetControllerTest_WidgetController extends WidgetController implements
return $widgetform; return $widgetform;
} }
function doAction($data, $form) { public function doAction($data, $form) {
return sprintf('TestValue: %s\nWidget ID: %d', return sprintf('TestValue: %s\nWidget ID: %d',
$data['TestValue'], $data['TestValue'],
$this->widget->ID $this->widget->ID

View File

@ -14,12 +14,11 @@ class WidgetControllerTestPage extends Page implements TestOnly {
* @subpackage tests * @subpackage tests
*/ */
class WidgetControllerTestPage_Controller extends Page_Controller implements TestOnly { class WidgetControllerTestPage_Controller extends Page_Controller implements TestOnly {
/** /**
* Template selection doesnt work in test folders, * Template selection doesnt work in test folders,
* so we enforce a template name. * so we enforce a template name.
*/ */
function getViewer($action) { public function getViewer($action) {
$templates = array('WidgetControllerTestPage'); $templates = array('WidgetControllerTestPage');
return new SSViewer($templates); return new SSViewer($templates);