Skip to content

Commit

Permalink
Merge pull request #24 from tecnocen-com/typecast
Browse files Browse the repository at this point in the history
Typecast
  • Loading branch information
neverabe authored Jul 13, 2019
2 parents 66733bc + 693e63f commit 0b86e99
Show file tree
Hide file tree
Showing 41 changed files with 332 additions and 181 deletions.
28 changes: 7 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

# faster builds on new travis setup not using sudo
sudo: false

language: php

services:
- memcached
- mysql
- postgresql

php:
- 7.1
- 7.2
- 7.3
- nightly

matrix:
Expand All @@ -15,13 +20,7 @@ matrix:
- php: nightly

install:
- |
if [[ $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != hhv* ]]; then
# disable xdebug for performance reasons when code coverage is not needed
# note: xdebug on hhvm is disabled by default
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
fi
- travis_retry composer self-update && composer --version
- travis_retry composer self-update
- travis_retry composer install --prefer-dist --no-interaction

before_script:
Expand All @@ -32,19 +31,6 @@ before_script:
# initialize database
- mysql -e "create database yii2_formgenerator_test"

# enable code coverage on PHP 7.1, only one PHP version needs to generate coverage data
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
CODECEPTION_FLAGS="--coverage-xml"
fi
script:
- composer deploy-tests
- composer run-tests

after_script:
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
travis_retry wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover tests/_output/coverage.xml
fi
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Yii2 Form Generator Change Log
==========================

0.5.0 July 13, 2019

- Brk: Methods now use the typecast supported in php 7.1

0.4.2 December 19, 2018

- Require flowpath on dev

0.4.1 November 15, 2018
------------------------

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
],
"require": {
"php": "^7.1",
"tecnocen/yii2-roa": ">0.4.0",
"tecnocen/yii2-roa": "~0.5.0",
"tecnocen/yii2-rmdb": "*",
"yiisoft/yii2": "~2.0.10"
"yiisoft/yii2": "~2.0.21"
},
"require-dev": {
"codeception/base": "^2.2.11",
Expand Down
21 changes: 11 additions & 10 deletions src/behaviors/Positionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace tecnocen\formgenerator\behaviors;

use yii\base\InvalidConfigException;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\db\Expression as DbExpression;
use yii\validators\Validator;
Expand Down Expand Up @@ -121,9 +122,9 @@ public function attachValidators()
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getSiblings()
public function getSiblings(): ActiveQuery
{
return $this->owner->hasMany(get_class($this->owner), [
$this->parentAttribute => $this->parentAttribute
Expand Down Expand Up @@ -190,13 +191,13 @@ public function afterDelete()
* Update the position of siblings on the database.
* @param integer|DbExpression $position the new position.
* @param array $condition the extra condition to update siblings.
* @return integer the number of updated siblings.
* @return int the number of updated siblings.
*/
protected function updateSiblingsPosition(
$position,
array $condition,
array $orderBy = []
) {
): int {
$params = [];
$queryBuilder = $this->owner->getDb()->getQueryBuilder();
return $this->owner->getDb()->createCommand(
Expand All @@ -222,10 +223,10 @@ protected function updateSiblingsPosition(
/**
* Increases the position of siblings by 1.
*
* @var array $conditoin the extra condition to update siblings.
* @return integer the number of updated siblings.
* @param array $conditoin the extra condition to update siblings.
* @return int the number of updated siblings.
*/
protected function increaseSiblingsPosition(array $condition)
protected function increaseSiblingsPosition(array $condition): int
{
return $this->updateSiblingsPosition(
$this->positionIncrease,
Expand All @@ -237,10 +238,10 @@ protected function increaseSiblingsPosition(array $condition)
/**
* Decreases the position of siblings by 1.
*
* @var array $conditoin the extra condition to update siblings.
* @return integer the number of updated siblings.
* @param array $conditoin the extra condition to update siblings.
* @return int the number of updated siblings.
*/
protected function decreaseSiblingsPosition(array $condition)
protected function decreaseSiblingsPosition(array $condition): int
{
return $this->updateSiblingsPosition(
$this->positionDecrease,
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/tables/m170101_000004_field_rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function columns()
return [
'id' => $this->primaryKey(),
'field_id' => $this->normalKey(),
'class' => $this->string(64)->notNull(),
'rule_class' => $this->string(64)->notNull(),
];
}

Expand Down
5 changes: 3 additions & 2 deletions src/models/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace tecnocen\formgenerator\models;

use yii\db\ActiveQuery;
use yii\web\UploadedFile;

/**
Expand Down Expand Up @@ -133,9 +134,9 @@ public function attributeLabels()
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getFields()
public function getFields(): ActiveQuery
{
return $this->hasMany($this->fieldClass, ['data_type_id' => 'id'])
->inverseOf('dataType');
Expand Down
11 changes: 7 additions & 4 deletions src/models/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace tecnocen\formgenerator\models;

use yii\base\Model;
use yii\db\ActiveQuery;

/**
* Model class for table `{{%formgenerator_field}}`
Expand Down Expand Up @@ -82,17 +83,17 @@ public function attributeLabels()
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getDataType()
public function getDataType(): ActiveQuery
{
return $this->hasOne($this->dataTypeClass, ['id' => 'data_type_id']);
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getRules()
public function getRules(): ActiveQuery
{
return $this->hasMany($this->ruleClass, ['field_id' => 'id'])
->inverseOf('field');
Expand All @@ -104,9 +105,11 @@ public function getRules()
public function buildValidators(Model $model, $attributes)
{
$validators = [];

foreach ($this->rules as $rule) {
$validators[] = $rule->buildValidator($model, $attributes);
}

return $validators;
}
}
23 changes: 14 additions & 9 deletions src/models/FieldRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace tecnocen\formgenerator\models;

use yii\base\Model;
use yii\db\ActiveQuery;
use yii\helpers\ArrayHelper;
use yii\validators\Validator;

Expand All @@ -11,7 +12,7 @@
*
* @property integer $id
* @property integer $field_id
* @property string $class
* @property string $rule_class
*
* @property Field $field
* @property FieldRuleProperty[] $properties
Expand Down Expand Up @@ -55,7 +56,7 @@ protected function attributeTypecast()
public function rules()
{
return [
[['field_id', 'class'], 'required'],
[['field_id', 'rule_class'], 'required'],
[['field_id'], 'integer'],
[
['field_id'],
Expand All @@ -64,7 +65,7 @@ public function rules()
'targetClass' => Field::class,
'targetAttribute' => ['field_id' => 'id'],
],
[['class'], 'string', 'min' => 2],
[['rule_class'], 'string', 'min' => 2],
// todo check its a valid validator class
];
}
Expand All @@ -76,31 +77,35 @@ public function attributeLabels()
{
return array_merge([
'field_id' => 'Field ID',
'class' => 'Validator Class',
'rule_class' => 'Rule Class',
], parent::attributeLabels());
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getField()
public function getField(): ActiveQuery
{
return $this->hasOne($this->fieldClass, ['id' => 'field_id']);
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getProperties()
public function getProperties(): ActiveQuery
{
return $this->hasMany($this->propertyClass, ['rule_id' => 'id'])
->inverseOf('rule');
}

/**
* @param Model $model
* @param array $attributes
*/
public function buildValidator(Model $model, $attributes)
{
return Validator::createValidator(
$this->class,
$this->rule_class,
$model,
(array) $attributes,
ArrayHelper::map($this->properties, 'property', 'value')
Expand Down
6 changes: 4 additions & 2 deletions src/models/FieldRuleProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace tecnocen\formgenerator\models;

use yii\db\ActiveQuery;

/**
* Model class for table `{{%formgenerator_field_rule_property}}`
*
Expand Down Expand Up @@ -74,9 +76,9 @@ public function attributeLabels()
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getRule()
public function getRule(): ActiveQuery
{
return $this->hasOne($this->ruleClass, ['id' => 'rule_id']);
}
Expand Down
6 changes: 4 additions & 2 deletions src/models/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace tecnocen\formgenerator\models;

use yii\db\ActiveQuery;

/**
* Model class for table `{{%formgenerator_form}}`
*
Expand Down Expand Up @@ -58,9 +60,9 @@ public function attributeLabels()
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getSections()
public function getSections(): ActiveQuery
{
return $this->hasMany($this->sectionClass, ['form_id' => 'id'])
->inverseOf('form');
Expand Down
13 changes: 7 additions & 6 deletions src/models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace tecnocen\formgenerator\models;

use tecnocen\formgenerator\behaviors\Positionable;
use yii\db\ActiveQuery;

/**
* Model class for table `{{%formgenerator_form_section}}`
Expand Down Expand Up @@ -120,26 +121,26 @@ public function attributeLabels()
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getForm()
public function getForm(): ActiveQuery
{
return $this->hasOne($this->formClass, ['id' => 'form_id']);
}

/**
* @return \yii\db\ActiveQuery
* @return ActiveQuery
*/
public function getSectionFields()
public function getSectionFields(): ActiveQuery
{
return $this->hasMany($this->sectionFieldClass, ['section_id' => 'id'])
->inverseOf('section');
}

/**
* @return \yii\db\ActiveQuery sibling stages for the same workflow
* @return ActiveQuery sibling stages for the same workflow
*/
public function getFields()
public function getFields(): ActiveQuery
{
return $this->hasMany($this->fieldClass, ['id' => 'field_id'])
->via('sectionFields');
Expand Down
Loading

0 comments on commit 0b86e99

Please sign in to comment.