Merge pull request #50 from spekulatius/codestyle

MINOR codestyle to improve readibility
This commit is contained in:
Damian Mooyman 2015-11-25 11:34:50 +13:00
commit eb554a568c
3 changed files with 30 additions and 28 deletions

View File

@ -127,8 +127,8 @@ abstract class MultiForm extends Form {
$actionNames = static::$actions_exempt_from_validation;
if( $actionNames ) {
foreach( $actionNames as $exemptAction) {
if($actionNames) {
foreach ($actionNames as $exemptAction) {
if(!empty($_REQUEST[$exemptAction])) {
$applyValidation = false;
break;
@ -182,7 +182,10 @@ abstract class MultiForm extends Form {
$startStepClass = static::$start_step;
// Check if there was a start step defined on the subclass of MultiForm
if(!isset($startStepClass)) user_error('MultiForm::init(): Please define a $start_step on ' . $this->class, E_USER_ERROR);
if(!isset($startStepClass)) user_error(
'MultiForm::init(): Please define a $start_step on ' . $this->class,
E_USER_ERROR
);
// Determine whether we use the current step, or create one if it doesn't exist
$currentStep = null;
@ -295,10 +298,10 @@ abstract class MultiForm extends Form {
* If you want a full chain of steps regardless if they've already been saved
* to the database, use {@link getAllStepsLinear()}.
*
* @param String $filter SQL WHERE statement
* @param string $filter SQL WHERE statement
* @return DataObjectSet|boolean A set of MultiFormStep subclasses
*/
function getSavedSteps($filter = null) {
public function getSavedSteps($filter = null) {
$filter .= ($filter) ? ' AND ' : '';
$filter .= sprintf("\"SessionID\" = '%s'", $this->session->ID);
return DataObject::get('MultiFormStep', $filter);
@ -312,7 +315,7 @@ abstract class MultiForm extends Form {
* @param string $className Classname of a {@link MultiFormStep} subclass
* @return MultiFormStep
*/
function getSavedStepByClass($className) {
public function getSavedStepByClass($className) {
return DataObject::get_one(
'MultiFormStep',
sprintf("\"SessionID\" = '%s' AND \"ClassName\" = '%s'",
@ -341,7 +344,7 @@ abstract class MultiForm extends Form {
* @param $currentStep Subclass of MultiFormStep
* @return FieldList of FormAction objects
*/
function actionsFor($step) {
public function actionsFor($step) {
// Create default multi step actions (next, prev), and merge with extra actions, if any
$actions = (class_exists('FieldList')) ? new FieldList() : new FieldSet();
@ -379,7 +382,7 @@ abstract class MultiForm extends Form {
*
* @return SSViewer object to render the template with
*/
function forTemplate() {
public function forTemplate() {
$return = $this->renderWith(array(
$this->getCurrentStep()->class,
'MultiFormStep',
@ -416,7 +419,6 @@ abstract class MultiForm extends Form {
$this->controller->redirectBack();
return false;
}
}
/**
@ -531,7 +533,7 @@ abstract class MultiForm extends Form {
*
* @return string
*/
function FormAction() {
public function FormAction() {
$action = parent::FormAction();
$action .= (strpos($action, '?')) ? '&' : '?';
$action .= "MultiFormSessionID={$this->session->Hash}";
@ -643,6 +645,7 @@ abstract class MultiForm extends Form {
*/
public function getCompletedStepCount() {
$steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->session->ID} && \"Data\" IS NOT NULL");
return $steps ? $steps->Count() : 0;
}
@ -663,7 +666,6 @@ abstract class MultiForm extends Form {
* @return float
*/
public function getCompletedPercent() {
return (float)$this->getCompletedStepCount() * 100 / $this->getTotalStepCount();
return (float) $this->getCompletedStepCount() * 100 / $this->getTotalStepCount();
}
}

View File

@ -208,7 +208,7 @@ class MultiFormStep extends DataObject {
/**
* Returns the first value of $next_step
*
* @return String Classname of a {@link MultiFormStep} subclass
* @return string Classname of a {@link MultiFormStep} subclass
*/
public function getNextStep() {
$nextSteps = static::$next_steps;
@ -265,7 +265,7 @@ class MultiFormStep extends DataObject {
* To determine if there is a previous step, we check the database to see if there's
* a previous step for this multi form session ID.
*
* @return String Classname of a {@link MultiFormStep} subclass
* @return string Classname of a {@link MultiFormStep} subclass
*/
public function getPreviousStep() {
$steps = DataObject::get('MultiFormStep', "\"SessionID\" = {$this->SessionID}", '"LastEdited" DESC');

View File

@ -23,24 +23,24 @@ class MultiFormTest extends FunctionalTest {
protected $controller;
function setUp() {
public function setUp() {
parent::setUp();
$this->controller = new MultiFormTest_Controller();
$this->form = $this->controller->Form();
}
function testInitialisingForm() {
public function testInitialisingForm() {
$this->assertTrue(is_numeric($this->form->getCurrentStep()->ID) && ($this->form->getCurrentStep()->ID > 0));
$this->assertTrue(is_numeric($this->form->getSession()->ID) && ($this->form->getSession()->ID > 0));
$this->assertEquals('MultiFormTest_StepOne', $this->form->getStartStep());
}
function testSessionGeneration() {
public function testSessionGeneration() {
$this->assertTrue($this->form->session->ID > 0);
}
function testMemberLogging() {
public function testMemberLogging() {
// Grab any user to fake being logged in as, and ensure that after a session is written it has
// that user as the submitter.
$userId = Member::get_one("Member")->ID;
@ -52,27 +52,27 @@ class MultiFormTest extends FunctionalTest {
$this->assertEquals($userId, $session->SubmitterID);
}
function testSecondStep() {
public function testSecondStep() {
$this->assertEquals('MultiFormTest_StepTwo', $this->form->getCurrentStep()->getNextStep());
}
function testParentForm() {
public function testParentForm() {
$currentStep = $this->form->getCurrentStep();
$this->assertEquals($currentStep->getForm()->class, $this->form->class);
}
function testTotalStepCount() {
public function testTotalStepCount() {
$this->assertEquals(3, $this->form->getAllStepsLinear()->Count());
}
function testCompletedSession() {
public function testCompletedSession() {
$this->form->setCurrentSessionHash($this->form->session->Hash);
$this->assertInstanceOf('MultiFormSession', $this->form->getCurrentSession());
$this->form->session->markCompleted();
$this->assertNull($this->form->getCurrentSession());
}
function testIncorrectSessionIdentifier() {
public function testIncorrectSessionIdentifier() {
$this->form->setCurrentSessionHash('sdfsdf3432325325sfsdfdf'); // made up!
// A new session is generated, even though we made up the identifier
@ -87,7 +87,7 @@ class MultiFormTest extends FunctionalTest {
*/
class MultiFormTest_Controller extends Controller implements TestOnly {
function Link() {
public function Link() {
return 'MultiFormTest_Controller';
}
@ -106,7 +106,7 @@ class MultiFormTest_Form extends MultiForm implements TestOnly {
public static $start_step = 'MultiFormTest_StepOne';
function getStartStep() {
public function getStartStep() {
return self::$start_step;
}
@ -120,7 +120,7 @@ class MultiFormTest_StepOne extends MultiFormStep implements TestOnly {
public static $next_steps = 'MultiFormTest_StepTwo';
function getFields() {
public function getFields() {
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
return new $class(
new TextField('FirstName', 'First name'),
@ -138,7 +138,7 @@ class MultiFormTest_StepTwo extends MultiFormStep implements TestOnly {
public static $next_steps = 'MultiFormTest_StepThree';
function getFields() {
public function getFields() {
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
return new $class(
new TextareaField('Comments', 'Tell us a bit about yourself...')
@ -154,7 +154,7 @@ class MultiFormTest_StepThree extends MultiFormStep implements TestOnly {
public static $is_final_step = true;
function getFields() {
public function getFields() {
$class = (class_exists('FieldList')) ? 'FieldList' : 'FieldSet';
return new $class(
new TextField('Test', 'Anything else you\'d like to tell us?')