Skip to content

Commit

Permalink
added DOC BLOCK comments and type hinting for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
buttflattery committed Mar 7, 2020
1 parent 43b1343 commit b5c2540
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
16 changes: 9 additions & 7 deletions src/FormWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Yii;
use yii\web\View;
use yii\base\Model;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Json;
Expand Down Expand Up @@ -721,7 +722,7 @@ public function createFormWizard()
*
* @return array
*/
public function createStep($index, $step)
public function createStep($index, array $step)
{
//step title
$stepTitle = ArrayHelper::getValue($step, 'title', 'Step-' . ($index + 1));
Expand Down Expand Up @@ -779,7 +780,7 @@ public function createTabs($index, $stepDescription, $stepTitle)
*
* @return HTML $html
*/
public function createBody($index, $formInfoText, $step)
public function createBody($index, $formInfoText, array $step)
{
$html = '';

Expand Down Expand Up @@ -850,7 +851,7 @@ public function createBody($index, $formInfoText, $step)
*
* @return HTML
*/
public function createStepFields($stepIndex, $step, $isTabularStep, $limitRows)
public function createStepFields($stepIndex, array $step, $isTabularStep, $limitRows)
{

$htmlFields = '';
Expand Down Expand Up @@ -932,7 +933,7 @@ function ($element) use ($model, $isTabularStep, $modelIndex) {
*
* @return \yii\widgets\ActiveField
*/
public function createCustomInput($model, $attribute, $fieldConfig)
public function createCustomInput(Model $model, $attribute, array $fieldConfig)
{

//get the options
Expand Down Expand Up @@ -982,12 +983,13 @@ public function createCustomInput($model, $attribute, $fieldConfig)
/**
* Registers the necessary AssetBundles for the widget
*
* @param array $pluginOptions the plugin options initialized for the runtime
* @param boolean $isBs3 is bootstrapV3 loaded
* @param array $pluginOptions the plugin options initialized for the runtime
* @param boolean $isBs3 is bootstrapV3 loaded
* @param string $jsOptionsPersistence the json string for the persistence option
*
* @return null
*/
public function registerScripts($pluginOptions, $isBs3, $jsOptionsPersistence)
public function registerScripts(array $pluginOptions, $isBs3, $jsOptionsPersistence)
{
//get the container id
$wizardContainerId = $this->wizardContainerId;
Expand Down
77 changes: 41 additions & 36 deletions src/traits/WizardTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
namespace buttflattery\formwizard\traits;

use yii\base\Model;
use yii\helpers\Html;
use yii\web\JsExpression;
use yii\helpers\ArrayHelper;
Expand All @@ -25,7 +26,7 @@ trait WizardTrait
*
* @return null
*/
public function sortFields($fieldConfig, &$attributes, $step)
public function sortFields(array $fieldConfig, array &$attributes, array $step)
{
$defaultOrder = $fieldConfig !== false ? array_keys($fieldConfig) : false;
$fieldOrder = ArrayHelper::getValue($step, 'fieldOrder', $defaultOrder);
Expand Down Expand Up @@ -61,7 +62,7 @@ public function sortFields($fieldConfig, &$attributes, $step)
* @return null
* @throws ArgException
*/
private function _checkTabularConstraints($models)
private function _checkTabularConstraints(array $models)
{
$classes = [];
foreach ($models as $model) {
Expand All @@ -86,7 +87,7 @@ private function _checkTabularConstraints($models)
*
* @return null
*/
private function _addTabularEvents($attributeConfig, $modelIndex, $attributeId, $index)
private function _addTabularEvents(array $attributeConfig, $modelIndex, $attributeId, $index)
{
//get the tabular events for the field
$tabularEvents = ArrayHelper::getValue($attributeConfig, 'tabularEvents', false);
Expand All @@ -110,11 +111,11 @@ private function _addTabularEvents($attributeConfig, $modelIndex, $attributeId,
/**
* Binds the tabular events provided by the user
*
* @param string $eventName the name of the event to bind
* @param callable $eventCallBack the callback event provided by the user
* @param string $formId the id of the form
* @param integer $index the current model index
* @param string $attributeId the attribute id to triger the event for
* @param string $eventName the name of the event to bind
* @param string $eventCallBack the js callback event provided by the user
* @param string $formId the id of the form
* @param integer $index the current model index
* @param string $attributeId the attribute id to triger the event for
*
* @return null
*/
Expand Down Expand Up @@ -149,7 +150,7 @@ private function _bindEvents($eventName, $eventCallBack, $formId, $index, $attri
*
* @return null
*/
private function _addRestoreEvents($attributeConfig, $attributeId)
private function _addRestoreEvents(array $attributeConfig, $attributeId)
{
$persistenceEvents = ArrayHelper::getValue($attributeConfig, 'persistencEvents', []);
$formId = $this->formOptions['id'];
Expand All @@ -171,7 +172,7 @@ private function _addRestoreEvents($attributeConfig, $attributeId)
*
* @return yii\widgets\ActiveField;
*/
private function _createField($fieldType, $fieldTypeOptions, $hintText = false)
private function _createField($fieldType, array $fieldTypeOptions, $hintText = false)
{
$defaultFieldTypes = [
'text' => function ($params) {
Expand Down Expand Up @@ -276,17 +277,16 @@ private function _createField($fieldType, $fieldTypeOptions, $hintText = false)
/**
* Generates Html for the tabular step fields
*
* @param array $attributes the attributes to iterate
* @param integer $modelIndex the index of the current model
* @param integer $index the index of the current step
* @param object $model the model object
* @param boolean $isTabularStep if the current step is tabular
* @param array $fieldConfig customer field confitigurations
* @param boolean|string $stepHeadings the headings for the current step
* @param array $attributes the attributes to iterate
* @param integer $modelIndex the index of the current model
* @param integer $index the index of the current step
* @param object $model the model object
* @param array $fieldConfig customer field confitigurations
* @param array $stepHeadings the headings for the current step
*
* @return mixed
*/
private function _createTabularStepHtml($attributes, $modelIndex, $index, $model, $fieldConfig, $stepHeadings)
private function _createTabularStepHtml(array $attributes, $modelIndex, $index, Model $model, array $fieldConfig, array $stepHeadings)
{
$htmlFields = '';

Expand Down Expand Up @@ -362,7 +362,7 @@ private function _createTabularStepHtml($attributes, $modelIndex, $index, $model
*
* @return null
*/
private function _addDependentInputScript($dependentInput, $attributeId, $model, $modelIndex)
private function _addDependentInputScript(array $dependentInput, $attributeId, Model $model, $modelIndex)
{
$dependentAttribute = $dependentInput['attribute'];
$dependentValue = $model->$dependentAttribute;
Expand Down Expand Up @@ -395,10 +395,14 @@ private function _addDependentInputScript($dependentInput, $attributeId, $model,
}

/**
* @param $stepHeadings
* @param $attribute
* Adds the Heading for the Step
*
* @param array $stepHeadings the step headings configurations array
* @param string $attribute the name of the attribute
*
* @return mixed
*/
public function addHeading($stepHeadings, $attribute)
public function addHeading(array $stepHeadings, $attribute)
{
$headingFields = ArrayHelper::getColumn($stepHeadings, 'before', true);
if (in_array($attribute, $headingFields)) {
Expand All @@ -414,15 +418,13 @@ public function addHeading($stepHeadings, $attribute)
/**
* Generates Html for normal steps fields
*
* @param array $attributes the attributes to iterate
* @param integer $index the index of the current step
* @param boolean $isTabularStep if the current step is tabular
* @param array $fieldConfig customer field confitigurations
* @param boolean|string $stepHeadings the headings for the current step
* @param array $attributes the attributes to iterate
* @param array $fieldConfig customer field confitigurations
* @param array $stepHeadings the headings for the current step
*
* @return mixed
*/
private function _createStepHtml($attributes, $fieldConfig, $stepHeadings)
private function _createStepHtml(array $attributes, array $fieldConfig, array $stepHeadings)
{
$htmlFields = '';
foreach ($attributes as $row) {
Expand Down Expand Up @@ -485,7 +487,7 @@ private function _createStepHtml($attributes, $fieldConfig, $stepHeadings)
*
* @return HTML
*/
private function _addHeading($headingConfig)
private function _addHeading(array $headingConfig)
{
$headingText = $headingConfig['text'];
$headingClass = ArrayHelper::getValue($headingConfig, 'className', 'field-heading');
Expand All @@ -501,7 +503,7 @@ private function _addHeading($headingConfig)
*
* @return array
*/
private function _parseFieldConfig($fieldConfig)
private function _parseFieldConfig(array $fieldConfig)
{
//options
$options = ArrayHelper::getValue($fieldConfig, 'options', []);
Expand Down Expand Up @@ -564,9 +566,9 @@ private function _parseFieldConfig($fieldConfig)
* @return \yii\widgets\ActiveField
*/
public function createField(
$model,
Model $model,
$attribute,
$fieldOptions = [],
array $fieldOptions = [],
$isMulti = false
) {
return $this->_form->field(
Expand All @@ -585,7 +587,7 @@ public function createField(
*
* @return \yii\widgets\ActiveField
*/
public function createDefaultInput($model, $attribute)
public function createDefaultInput(Model $model, $attribute)
{
//create field
$field = $this->createField($model, $attribute);
Expand All @@ -601,7 +603,7 @@ public function createDefaultInput($model, $attribute)
*
* @return array $fields
*/
public function getStepFields($model, $onlyFields = [], $disabledFields = [])
public function getStepFields(Model $model, array $onlyFields = [], array $disabledFields = [])
{
//return $onlyFields list
if (!empty($onlyFields)) {
Expand Down Expand Up @@ -638,8 +640,11 @@ function ($item) use ($disabledFields) {
*
* @return boolean
*/
protected function addTabularRow($model, $modelIndex, $stepIndex, &$htmlFields, $fieldConfig, $attributes, $limitRows, $stepHeadings)
{
protected function addTabularRow(
Model $model, $modelIndex, $stepIndex, &$htmlFields,
array $fieldConfig, array $attributes, $limitRows,
array $stepHeadings
) {
//limit not exceeded
if ($limitRows === self::ROWS_UNLIMITED || $limitRows > $modelIndex) {
//start the row constainer
Expand Down

0 comments on commit b5c2540

Please sign in to comment.