diff --git a/.travis.yml b/.travis.yml index 7e73268..5e262a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ language: php php: - 7.1 - 7.2 + - 7.3 - nightly matrix: diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ae1350..9c517b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Yii2 Workflow Change Log ========================== +0.4.0 July 13, 2019 + +- Brk: Methods now use the typecast supported in php 7.1 + +0.3.2 December 18, 2018 + +- fix version bump for yii2 roa tests + 0.3.1 December 17, 2018 ------------------------ diff --git a/composer.json b/composer.json index b77b38a..0f09c61 100644 --- a/composer.json +++ b/composer.json @@ -29,12 +29,10 @@ } ], "require": { - "php": "^7.0", - "ext-curl": "*", - "tecnocen/yii2-roa": ">0.4.1", + "php": "^7.1", + "tecnocen/yii2-roa": "~0.5.0", "tecnocen/yii2-rmdb": "*", - "yii2tech/ar-softdelete": "*", - "yiisoft/yii2": "~2.0.10" + "yii2tech/ar-softdelete": "*" }, "require-dev": { "codeception/base": "^2.2.11", diff --git a/src/models/Assignment.php b/src/models/Assignment.php index 67b2c89..aa6c636 100644 --- a/src/models/Assignment.php +++ b/src/models/Assignment.php @@ -4,6 +4,7 @@ use tecnocen\rmdb\models\Pivot; use Yii; +use yii\db\ActiveQuery; /** * @property int $process_id @@ -16,7 +17,7 @@ abstract class Assignment extends Pivot /** * @return string class name for the process this worklog is attached to. */ - protected abstract function processClass(); + protected abstract function processClass(): string; /** * @inheritdoc @@ -65,10 +66,11 @@ public function init() } parent::init(); } + /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getProcess() + public function getProcess(): ActiveQuery { return $this->hasOne($this->processClass(), ['id' => 'process_id']); } diff --git a/src/models/Process.php b/src/models/Process.php index 0046589..63f4b88 100644 --- a/src/models/Process.php +++ b/src/models/Process.php @@ -4,6 +4,7 @@ use tecnocen\rmdb\models\Entity; use yii\base\InvalidConfigException; +use yii\db\ActiveQuery; /** * Model class for process which change stages depending on a worklow @@ -32,7 +33,7 @@ abstract class Process extends Entity * @return string full class name of the class to be used for the relation * `getWorkflow()`. */ - public function workflowClass() + public function workflowClass(): string { return Workflow::class; } @@ -41,18 +42,18 @@ public function workflowClass() * @return string full class name of the class to be used to store the * assignment records. */ - protected abstract function assignmentClass(); + protected abstract function assignmentClass(): string; /** * @return string full class name of the class to be used to store the * WorkLog records. */ - protected abstract function WorkLogClass(); + protected abstract function workLogClass(): string; /** * @return int the id of the workflow this process belongs to. */ - public abstract function getWorkflowId(); + public abstract function getWorkflowId(): int; /** * Determines if the current process record has the need of an initial @@ -61,7 +62,7 @@ public abstract function getWorkflowId(); * * @return bool whether the initial worklog was autogenerated. */ - private function hasInitialWorkLog() + private function hasInitialWorkLog(): bool { if (!$this->autogenerateInitialWorklog || !$this->isNewRecord) { return false; @@ -92,10 +93,10 @@ public function load($data, $formName = null) /** * Whether the user is asigned to the process. * - * @param int $userId [description] - * @return boolean + * @param ?int $userId + * @return bool */ - public function userAssigned($userId) + public function userAssigned(?int $userId): bool { return !$this->getAssignments()->exists() || $this->getAssignments() ->andWhere(['user_id' => $userId]); @@ -151,9 +152,9 @@ public function afterSave($insert, $changedAttributes) */ public function init() { - if (!is_subclass_of($this->WorkLogClass(), WorkLog::class)) { + if (!is_subclass_of($this->workLogClass(), WorkLog::class)) { throw new InvalidConfigException( - static::class . '::WorkLogClass() must extend ' + static::class . '::workLogClass() must extend ' . WorkLog::class ); } @@ -169,7 +170,7 @@ public function init() /** * @return Workflow */ - public function getWorkflow() + public function getWorkflow(): Workflow { $workflowClass = $this->workflowClass(); @@ -177,9 +178,9 @@ public function getWorkflow() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getAssignments() + public function getAssignments(): ActiveQuery { return $this->hasMany($this->assignmentClass(), [ 'process_id' => 'id', @@ -187,27 +188,27 @@ public function getAssignments() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getWorkLogs() + public function getWorkLogs(): ActiveQuery { - return $this->hasMany($this->WorkLogClass(), [ + return $this->hasMany($this->workLogClass(), [ 'process_id' => 'id', ])->inverseOf('process'); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery * @see https://dev.mysql.com/doc/refman/5.7/en/example-maximum-column-group-row.html */ - public function getActiveWorkLog() + public function getActiveWorkLog(): ActiveQuery { $query = $this->getWorkLogs()->alias('WorkLog'); $query->multiple = false; - $WorkLogClass = $this->WorkLogClass(); + $workLogClass = $this->workLogClass(); return $query->andWhere([ - 'id' => $WorkLogClass::find() + 'id' => $workLogClass::find() ->select(['MAX(id)']) ->alias('WorkLog_groupwise') ->andWhere('WorkLog.process_id = WorkLog_groupwise.process_id') @@ -222,29 +223,36 @@ public function getActiveWorkLog() * to create said WorkLog. * @param bool $runValidation */ - public function flow(&$WorkLog, $runValidation = true) + public function flow(&$workLog, bool $runValidation = true) { - $WorkLog = $this->ensureWorkLog($WorkLog); - $WorkLog->scenario = WorkLog::SCENARIO_FLOW; + $workLog = $this->ensureWorkLog($workLog); + $workLog->scenario = WorkLog::SCENARIO_FLOW; - return $WorkLog->save($runValidation); + return $workLog->save($runValidation); } - private function ensureWorkLog($WorkLog) + /** + * Ensures that the provided parameter is either an array to create a valid + * instance of the `workLogClass()` class. + * + * @param array|WorkLog $workLog + * @return WorkLog extending the class defined in `workLogClass()` + */ + private function ensureWorkLog($workLog): WorkLog { - $WorkLogClass = $this->WorkLogClass(); - if (is_array($WorkLog)) { - $WorkLog = new $WorkLogClass($WorkLog); - } elseif (!$WorkLog instanceof $WorkLogClass) { + $workLogClass = $this->workLogClass(); + if (is_array($workLog)) { + $workLog = new $workLogClass($workLog); + } elseif (!$workLog instanceof $workLogClass) { throw new InvalidParamException( - "Parameter must be an instance of {$WorkLogClass} or an " + "Parameter must be an instance of {$workLogClass} or an " . 'array to configure an instance' ); } - $WorkLog->process_id = $this->id; - $WorkLog->populateRelation('process', $this); + $workLog->process_id = $this->id; + $workLog->populateRelation('process', $this); - return $WorkLog; + return $workLog; } } diff --git a/src/models/Stage.php b/src/models/Stage.php index 692fbe3..0a57fa8 100644 --- a/src/models/Stage.php +++ b/src/models/Stage.php @@ -1,6 +1,9 @@ hasOne( $this->workflowClass, @@ -100,9 +103,9 @@ public function getWorkflow() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getTransitions() + public function getTransitions(): ActiveQuery { return $this->hasMany( $this->transitionClass, @@ -111,9 +114,9 @@ public function getTransitions() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getDetailTransitions() + public function getDetailTransitions(): ActiveQuery { $query = $this->getTransitions(); $query->multiple = false; @@ -129,15 +132,15 @@ public function getDetailTransitions() /** * @return int */ - public function getTotalTransitions() + public function getTotalTransitions(): int { return (int)$this->detailTransitions['totalTransitions']; } /** - * @return \yii\db\ActiveQuery sibling stages for the same workflow + * @return ActiveQuery sibling stages for the same workflow */ - public function getSiblings() + public function getSiblings(): ActiveQuery { return $this->hasMany(static::class, ['workflow_id' => 'workflow_id']) ->alias('siblings'); diff --git a/src/models/Transition.php b/src/models/Transition.php index 4b03229..2275339 100644 --- a/src/models/Transition.php +++ b/src/models/Transition.php @@ -3,6 +3,7 @@ namespace tecnocen\workflow\models; use Yii; +use yii\db\ActiveQuery; /** * Model class for table `{{%workflow_transition}}` @@ -126,13 +127,14 @@ public function rules() * * @param int $userId * @param Process $process - * @return boolean + * @return bool */ - public function userCan($userId, Process $process) + public function userCan(?int $userId, Process $process): bool { if (!$this->getPermissions()->exists()) { return true; } + $authManager = Yii::$app->authManager; foreach ($this->permissions as $permission) { @@ -160,25 +162,25 @@ public function attributeLabels() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getSourceStage() + public function getSourceStage(): ActiveQuery { return $this->hasOne($this->stageClass, ['id' => 'source_stage_id']); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getTargetStage() + public function getTargetStage(): ActiveQuery { return $this->hasOne($this->stageClass, ['id' => 'target_stage_id']); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getPermissions() + public function getPermissions(): ActiveQuery { return $this->hasMany( $this->permissionClass, diff --git a/src/models/TransitionPermission.php b/src/models/TransitionPermission.php index 12a9351..1deb3b6 100644 --- a/src/models/TransitionPermission.php +++ b/src/models/TransitionPermission.php @@ -2,6 +2,8 @@ namespace tecnocen\workflow\models; +use yii\db\ActiveQuery; + /** * Model class for table `{{%workflow_transition}}` * @@ -116,25 +118,25 @@ public function attributeLabels() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getSourceStage() + public function getSourceStage(): ActiveQuery { return $this->hasOne($this->stageClass, ['id' => 'source_stage_id']); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getTargetStage() + public function getTargetStage(): ActiveQuery { return $this->hasOne($this->stageClass, ['id' => 'target_stage_id']); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getTransition() + public function getTransition(): ActiveQuery { return $this->hasOne( $this->transitionClass, diff --git a/src/models/WorkLog.php b/src/models/WorkLog.php index d01ffc6..a25f4d4 100644 --- a/src/models/WorkLog.php +++ b/src/models/WorkLog.php @@ -4,6 +4,7 @@ use tecnocen\rmdb\models\Pivot; use Yii; +use yii\db\ActiveQuery; use yii\web\ForbiddenHttpException; use yii\web\BadRequestHttpException; @@ -22,7 +23,7 @@ abstract class WorkLog extends Pivot /** * @return string class name for the process this worklog is attached to. */ - protected abstract function processClass(); + protected abstract function processClass(): string; /** * @inheritdoc @@ -138,9 +139,9 @@ public function init() parent::init(); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getProcess() + public function getProcess(): ActiveQuery { return $this->hasOne($this->processClass(), ['id' => 'process_id']); } diff --git a/src/models/Workflow.php b/src/models/Workflow.php index 176dc88..e9b53f8 100644 --- a/src/models/Workflow.php +++ b/src/models/Workflow.php @@ -2,6 +2,8 @@ namespace tecnocen\workflow\models; +use yii\db\ActiveQuery; + /** * Model class for table `{{%workflow}}` * @@ -58,18 +60,18 @@ public function attributeLabels() } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getStages() + public function getStages(): ActiveQuery { return $this->hasMany($this->stageClass, ['workflow_id' => 'id']) ->inverseOf('workflow'); } /** - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getDetailStages() + public function getDetailStages(): ActiveQuery { $query = $this->getStages(); $query->multiple = false; @@ -85,7 +87,7 @@ public function getDetailStages() /** * @return int */ - public function getTotalStages() + public function getTotalStages(): int { return (int)$this->detailStages['totalStages']; } diff --git a/src/roa/models/Stage.php b/src/roa/models/Stage.php index a266a1c..d863247 100644 --- a/src/roa/models/Stage.php +++ b/src/roa/models/Stage.php @@ -8,9 +8,6 @@ /** * ROA contract to handle workflow stage records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() */ class Stage extends base\Stage implements Contract { @@ -18,14 +15,6 @@ class Stage extends base\Stage implements Contract getLinks as getContractLinks; } - /** - * @inheritdoc - */ - public function fields() - { - return array_merge($this->attributes(), ['totalTransitions']); - } - /** * @inheritdoc */ @@ -39,7 +28,7 @@ public function fields() /** * @inheritdoc */ - public function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'resourceName' => 'stage', diff --git a/src/roa/models/StageSearch.php b/src/roa/models/StageSearch.php index 42c04cd..df642f0 100644 --- a/src/roa/models/StageSearch.php +++ b/src/roa/models/StageSearch.php @@ -2,6 +2,7 @@ namespace tecnocen\workflow\roa\models; +use tecnocen\roa\ResourceSearch; use yii\data\ActiveDataProvider; use yii\web\NotFoundHttpException; @@ -12,7 +13,6 @@ */ class StageSearch extends Stage implements \tecnocen\roa\ResourceSearch { - /** * @inhertidoc */ @@ -27,15 +27,19 @@ public function rules() /** * @inhertidoc */ - public function search(array $params, $formName = '') - { + public function search( + array $params, + ?string $formName = '' + ): ?ActiveDataProvider { $this->load($params, $formName); if (!$this->validate()) { return null; } + if (null === $this->workflow) { throw new NotFoundHttpException('Unexistant workflow path.'); } + $class = get_parent_class(); return new ActiveDataProvider([ 'query' => $class::find()->andFilterWhere([ diff --git a/src/roa/models/Transition.php b/src/roa/models/Transition.php index 82ea1a1..c630bee 100644 --- a/src/roa/models/Transition.php +++ b/src/roa/models/Transition.php @@ -8,9 +8,6 @@ /** * ROA contract to handle workflow transitions records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() */ class Transition extends base\Transition implements Contract { @@ -31,7 +28,7 @@ class Transition extends base\Transition implements Contract /** * @inheritdoc */ - protected function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'resourceName' => 'transition', diff --git a/src/roa/models/TransitionPermission.php b/src/roa/models/TransitionPermission.php index 073cdf2..0ba790f 100644 --- a/src/roa/models/TransitionPermission.php +++ b/src/roa/models/TransitionPermission.php @@ -8,15 +8,10 @@ /** * ROA contract to handle workflow transition permissions records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() */ class TransitionPermission extends base\TransitionPermission implements Contract { - use ContractTrait { - getLinks as getContractLinks; - } + use ContractTrait; /** * @inheritdoc @@ -31,7 +26,7 @@ class TransitionPermission extends base\TransitionPermission implements Contract /** * @inheritdoc */ - public function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'idAttribute' => 'permission', @@ -40,14 +35,6 @@ public function slugBehaviorConfig() ]; } - /** - * @inheritdoc - */ - public function getLinks() - { - return array_merge($this->getContractLinks()); - } - /** * @inheritdoc */ diff --git a/src/roa/models/TransitionPermissionSearch.php b/src/roa/models/TransitionPermissionSearch.php index fc36d84..53aeb1a 100644 --- a/src/roa/models/TransitionPermissionSearch.php +++ b/src/roa/models/TransitionPermissionSearch.php @@ -2,6 +2,7 @@ namespace tecnocen\workflow\roa\models; +use tecnocen\roa\ResourceSearch; use yii\data\ActiveDataProvider; use yii\web\NotFoundHttpException; @@ -10,10 +11,9 @@ * * @author Angel (Faryshta) Guevara */ -class TransitionPermissionSearch extends TransitionPermission - implements \tecnocen\roa\ResourceSearch +class TransitionPermissionSearch extends TransitionPermission implements + ResourceSearch { - /** * @inhertidoc */ @@ -28,8 +28,10 @@ public function rules() /** * @inhertidoc */ - public function search(array $params, $formName = '') - { + public function search( + array $params, + ?string $formName = '' + ): ?ActiveDataProvider { $this->load($params, $formName); if (!$this->validate()) { return null; diff --git a/src/roa/models/TransitionSearch.php b/src/roa/models/TransitionSearch.php index f52d954..a29899d 100644 --- a/src/roa/models/TransitionSearch.php +++ b/src/roa/models/TransitionSearch.php @@ -28,8 +28,10 @@ public function rules() /** * @inhertidoc */ - public function search(array $params, $formName = '') - { + public function search( + array $params, + ?string $formName = '' + ): ?ActiveDataProvider { $this->load($params, $formName); if (!$this->validate()) { return null; diff --git a/src/roa/models/Workflow.php b/src/roa/models/Workflow.php index c410fb5..7d13385 100644 --- a/src/roa/models/Workflow.php +++ b/src/roa/models/Workflow.php @@ -9,9 +9,6 @@ /** * ROA contract to handle workflow records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() */ class Workflow extends base\Workflow implements Contract { @@ -19,14 +16,6 @@ class Workflow extends base\Workflow implements Contract getLinks as getContractLinks; } - /** - * @inheritdoc - */ - public function fields() - { - return array_merge($this->attributes(), ['totalStages']); - } - /** * @inheritdoc */ @@ -35,7 +24,7 @@ public function fields() /** * @inheritdoc */ - public function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'resourceName' => 'workflow', @@ -44,10 +33,10 @@ public function slugBehaviorConfig() && $this->id != $params['workflow_id'] ) { throw new NotFoundHttpException( - 'Workflow not associated to element.' + 'Workflow not associated to element.' ); } - } + }, ]; } diff --git a/src/roa/models/WorkflowSearch.php b/src/roa/models/WorkflowSearch.php index 62ee7c1..a49e969 100644 --- a/src/roa/models/WorkflowSearch.php +++ b/src/roa/models/WorkflowSearch.php @@ -2,6 +2,7 @@ namespace tecnocen\workflow\roa\models; +use tecnocen\roa\ResourceSearch; use yii\data\ActiveDataProvider; /** @@ -9,9 +10,8 @@ * * @author Angel (Faryshta) Guevara */ -class WorkflowSearch extends Workflow implements \tecnocen\roa\ResourceSearch +class WorkflowSearch extends Workflow implements ResourceSearch { - /** * @inhertidoc */ @@ -26,12 +26,15 @@ public function rules() /** * @inhertidoc */ - public function search(array $params, $formName = '') - { + public function search( + array $params, + ?string $formName = '' + ): ?ActiveDataProvider { $this->load($params, $formName); if (!$this->validate()) { return null; } + $class = get_parent_class(); return new ActiveDataProvider([ 'query' => $class::find()->andFilterWhere([ diff --git a/src/roa/modules/Version.php b/src/roa/modules/Version.php index 862238f..7f9c370 100644 --- a/src/roa/modules/Version.php +++ b/src/roa/modules/Version.php @@ -2,10 +2,12 @@ namespace tecnocen\workflow\roa\modules; -use tecnocen\workflow\roa\resources\PermissionResource; -use tecnocen\workflow\roa\resources\StageResource; -use tecnocen\workflow\roa\resources\TransitionResource; -use tecnocen\workflow\roa\resources\WorkflowResource; +use tecnocen\workflow\roa\resources\{ + PermissionResource, + StageResource, + TransitionResource, + WorkflowResource +}; class Version extends \tecnocen\roa\modules\ApiVersion { diff --git a/src/roa/resources/PermissionResource.php b/src/roa/resources/PermissionResource.php index 0a28f47..7b312d5 100644 --- a/src/roa/resources/PermissionResource.php +++ b/src/roa/resources/PermissionResource.php @@ -2,16 +2,16 @@ namespace tecnocen\workflow\roa\resources; -use Yii; use tecnocen\workflow\roa\models\TransitionPermission; use tecnocen\workflow\roa\models\TransitionPermissionSearch; +use tecnocen\roa\controllers\Resource; /** * Resource to assign permissions to a transition. * * @author Angel (Faryshta) Guevara */ -class PermissionResource extends \tecnocen\roa\controllers\Resource +class PermissionResource extends Resource { /** * @inheritdoc diff --git a/src/roa/resources/StageResource.php b/src/roa/resources/StageResource.php index cebebf8..1aa0850 100644 --- a/src/roa/resources/StageResource.php +++ b/src/roa/resources/StageResource.php @@ -2,15 +2,16 @@ namespace tecnocen\workflow\roa\resources; -use Yii; -use yii\web\NotFoundHttpException; +use tecnocen\roa\controllers\Resource; use tecnocen\workflow\roa\models\Stage; use tecnocen\workflow\roa\models\StageSearch; /** - * Resource to + * Resource to handle `Stage` records. + * + * @author Angel (Faryshta) Guevara */ -class StageResource extends \tecnocen\roa\controllers\Resource +class StageResource extends Resource { /** * @inheritdoc diff --git a/src/roa/resources/TransitionResource.php b/src/roa/resources/TransitionResource.php index 15477cd..4f69e74 100644 --- a/src/roa/resources/TransitionResource.php +++ b/src/roa/resources/TransitionResource.php @@ -2,16 +2,16 @@ namespace tecnocen\workflow\roa\resources; -use Yii; +use tecnocen\roa\controllers\Resource; use tecnocen\workflow\roa\models\Transition; use tecnocen\workflow\roa\models\TransitionSearch; /** - * Resource to handle transition records. + * Resource to handle `Transition` records. * * @author Angel (Faryshta) Guevara */ -class TransitionResource extends \tecnocen\roa\controllers\Resource +class TransitionResource extends Resource { /** * @inhertidoc diff --git a/src/roa/resources/WorkflowResource.php b/src/roa/resources/WorkflowResource.php index 752178b..ce2d282 100644 --- a/src/roa/resources/WorkflowResource.php +++ b/src/roa/resources/WorkflowResource.php @@ -2,14 +2,16 @@ namespace tecnocen\workflow\roa\resources; +use tecnocen\roa\controllers\Resource; use tecnocen\workflow\roa\models\Workflow; use tecnocen\workflow\roa\models\WorkflowSearch; /** - * CRUD resource for `Workflow` records + * Resource to handle `Workflow` records + * * @author Angel (Faryshta) Guevara */ -class WorkflowResource extends \tecnocen\roa\controllers\Resource +class WorkflowResource extends Resource { /** * @inheritdoc diff --git a/tests/_app/api/models/Credit.php b/tests/_app/api/models/Credit.php index c65b5a2..d69ad2f 100644 --- a/tests/_app/api/models/Credit.php +++ b/tests/_app/api/models/Credit.php @@ -2,28 +2,31 @@ namespace app\api\models; +use app\models as base; use tecnocen\roa\hal\Contract; use tecnocen\roa\hal\ContractTrait; -use yii\web\NotFoundHttpException; /** * ROA contract to handle credit records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() */ -class Credit extends \app\models\Credit implements Contract +class Credit extends base\Credit implements Contract { use ContractTrait { getLinks as getContractLinks; } - protected function assignmentClass() + /** + * @inheritdoc + */ + protected function assignmentClass(): string { return CreditAssignment::class; } - protected function workLogClass() + /** + * @inheritdoc + */ + protected function workLogClass(): string { return CreditWorklog::class; } @@ -31,7 +34,7 @@ protected function workLogClass() /** * @inheritdoc */ - public function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'resourceName' => 'credit', diff --git a/tests/_app/api/models/CreditAssignment.php b/tests/_app/api/models/CreditAssignment.php index 2579821..a67bc5f 100644 --- a/tests/_app/api/models/CreditAssignment.php +++ b/tests/_app/api/models/CreditAssignment.php @@ -2,33 +2,28 @@ namespace app\api\models; +use app\models as base; use tecnocen\roa\hal\Contract; use tecnocen\roa\hal\ContractTrait; -use yii\web\NotFoundHttpException; /** - * ROA contract to handle credit_worklog records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() + * ROA contract to handle credit_assignment records. */ -class CreditAssignment extends \app\models\CreditAssignment implements Contract +class CreditAssignment extends base\CreditAssignment implements Contract { - use ContractTrait { - getLinks as getContractLinks; - } + use ContractTrait; /** * @inheritdoc */ - protected function processClass() + protected function processClass(): string { return Credit::class; } /** * @inheritdoc */ - protected function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'resourceName' => 'assignment', @@ -36,11 +31,4 @@ protected function slugBehaviorConfig() 'idAttribute' => 'user_id' ]; } - /** - * @inheritdoc - */ - public function getLinks() - { - return $this->getSlugLinks(); - } } diff --git a/tests/_app/api/models/CreditSearch.php b/tests/_app/api/models/CreditSearch.php index b80727c..1120a08 100644 --- a/tests/_app/api/models/CreditSearch.php +++ b/tests/_app/api/models/CreditSearch.php @@ -2,9 +2,10 @@ namespace app\api\models; +use tecnocen\roa\ResourceSearch; use yii\data\ActiveDataProvider; -class CreditSearch extends Credit implements \tecnocen\roa\ResourceSearch +class CreditSearch extends Credit implements ResourceSearch { /** * @inhertidoc @@ -24,12 +25,15 @@ public function rules() /** * @inhertidoc */ - public function search(array $params, $formName = '') - { + public function search( + array $params, + ?string $formName = '' + ): ?ActiveDataProvider { $this->load($params, $formName); if (!$this->validate()) { return null; } + $class = get_parent_class(); return new ActiveDataProvider([ 'query' => $class::find()->andFilterWhere([ diff --git a/tests/_app/api/models/CreditWorklog.php b/tests/_app/api/models/CreditWorklog.php index b799a18..e47425e 100644 --- a/tests/_app/api/models/CreditWorklog.php +++ b/tests/_app/api/models/CreditWorklog.php @@ -2,26 +2,21 @@ namespace app\api\models; +use app\models as base; use tecnocen\roa\hal\Contract; use tecnocen\roa\hal\ContractTrait; -use yii\web\NotFoundHttpException; /** * ROA contract to handle credit_worklog records. - * - * @method string[] getSlugLinks() - * @method string getSelfLink() */ -class CreditWorklog extends \app\models\CreditWorklog implements Contract +class CreditWorklog extends base\CreditWorklog implements Contract { - use ContractTrait { - getLinks as getContractLinks; - } - + use ContractTrait; + /** * @inheritdoc */ - protected function processClass() + protected function processClass(): string { return Credit::class; } @@ -29,21 +24,11 @@ protected function processClass() /** * @inheritdoc */ - public function slugBehaviorConfig() + protected function slugBehaviorConfig(): array { return [ 'resourceName' => 'worklog', 'parentSlugRelation' => 'process' ]; } - - /** - * @inheritdoc - */ - public function getLinks() - { - return array_merge($this->getContractLinks(), [ - 'creditWorklogs' => $this->getSelfLink() . '/worklog', - ]); - } } diff --git a/tests/_app/api/modules/Version.php b/tests/_app/api/modules/Version.php index e357c4c..b0cc0dc 100644 --- a/tests/_app/api/modules/Version.php +++ b/tests/_app/api/modules/Version.php @@ -2,9 +2,11 @@ namespace app\api\modules; -use app\api\resources\CreditResource; -use app\api\resources\CreditWorklogResource; -use app\api\resources\CreditAssignmentResource; +use app\api\resources\{ + CreditResource, + CreditWorklogResource, + CreditAssignmentResource +}; class Version extends \tecnocen\roa\modules\ApiVersion { diff --git a/tests/_app/api/resources/CreditAssignmentResource.php b/tests/_app/api/resources/CreditAssignmentResource.php index 224f8d8..3c8e375 100644 --- a/tests/_app/api/resources/CreditAssignmentResource.php +++ b/tests/_app/api/resources/CreditAssignmentResource.php @@ -2,15 +2,14 @@ namespace app\api\resources; -use Yii; -use yii\web\NotFoundHttpException; use app\api\models\CreditAssignment; +use tecnocen\roa\controllers\Resource; /** * CRUD resource for `Credit Assignment` records * @author Carlos (neverabe) Llamosas */ -class CreditAssignmentResource extends \tecnocen\roa\controllers\Resource +class CreditAssignmentResource extends Resource { /** * @inheritdoc diff --git a/tests/_app/api/resources/CreditResource.php b/tests/_app/api/resources/CreditResource.php index 569fcad..cf6b802 100644 --- a/tests/_app/api/resources/CreditResource.php +++ b/tests/_app/api/resources/CreditResource.php @@ -2,16 +2,15 @@ namespace app\api\resources; -use Yii; -use yii\web\NotFoundHttpException; use app\api\models\Credit; use app\api\models\CreditSearch; +use tecnocen\roa\controllers\Resource; /** * CRUD resource for `Credit` records * @author Carlos (neverabe) Llamosas */ -class CreditResource extends \tecnocen\roa\controllers\Resource +class CreditResource extends Resource { /** * @inheritdoc diff --git a/tests/_app/api/resources/CreditWorklogResource.php b/tests/_app/api/resources/CreditWorklogResource.php index 7fea2a8..652f414 100644 --- a/tests/_app/api/resources/CreditWorklogResource.php +++ b/tests/_app/api/resources/CreditWorklogResource.php @@ -2,15 +2,14 @@ namespace app\api\resources; -use Yii; -use yii\web\NotFoundHttpException; use app\api\models\CreditWorklog; +use tecnocen\roa\controllers\Resource; /** * CRUD resource for `Credit Worklog` records * @author Carlos (neverabe) Llamosas */ -class CreditWorklogResource extends \tecnocen\roa\controllers\Resource +class CreditWorklogResource extends Resource { /** * @inheritdoc diff --git a/tests/_app/models/Credit.php b/tests/_app/models/Credit.php index 243a4da..04535a1 100644 --- a/tests/_app/models/Credit.php +++ b/tests/_app/models/Credit.php @@ -21,17 +21,17 @@ public static function tableName() return '{{%credit}}'; } - protected function assignmentClass() + protected function assignmentClass(): string { return CreditAssignment::class; } - protected function workLogClass() + protected function workLogClass():string { return CreditWorklog::class; } - public function getWorkflowId() + public function getWorkflowId(): int { return $this->workflow_id; } diff --git a/tests/_app/models/CreditAssignment.php b/tests/_app/models/CreditAssignment.php index ad74621..817ebab 100644 --- a/tests/_app/models/CreditAssignment.php +++ b/tests/_app/models/CreditAssignment.php @@ -4,11 +4,18 @@ class CreditAssignment extends \tecnocen\workflow\models\Assignment { + /** + * @inheritdoc + */ public static function tableName() { return '{{%credit_assignment}}'; } - protected function processClass() + + /** + * @inheritdoc + */ + protected function processClass(): string { return Credit::class; } diff --git a/tests/_app/models/CreditWorklog.php b/tests/_app/models/CreditWorklog.php index bb8c6b9..8ef2fb2 100644 --- a/tests/_app/models/CreditWorklog.php +++ b/tests/_app/models/CreditWorklog.php @@ -9,7 +9,7 @@ public static function tableName() return '{{%credit_worklog}}'; } - protected function processClass() + protected function processClass(): string { return Credit::class; } diff --git a/tests/api/WorkflowCest.php b/tests/api/WorkflowCest.php index 94c494a..0d64065 100644 --- a/tests/api/WorkflowCest.php +++ b/tests/api/WorkflowCest.php @@ -106,18 +106,20 @@ protected function viewDataProvider() 'stages' => [ ['id' => 1], ], + 'totalStages' => 3, ], ], ], 'field total stages' => [ 'urlParams' => [ 'id' => '1', - 'fields' => 'id,name,totalStages' + 'fields' => 'id,name' ], 'httpCode' => HttpCode::OK, 'response' => [ - 'totalStages' => 3, - ] + 'id' => 1, + 'name' => 'workflow 1', + ], ], ]; }