Skip to content

Commit

Permalink
Updated dependencies + PHP strict type
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-eugone committed Jun 30, 2020
1 parent cc3b584 commit 3cb39fe
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 215 deletions.
43 changes: 5 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ Yokai Sonata Workflow
[![Total Downloads](https://poser.pugx.org/yokai/sonata-workflow/downloads)](https://packagist.org/packages/yokai/sonata-workflow)
[![License](https://poser.pugx.org/yokai/sonata-workflow/license)](https://packagist.org/packages/yokai/sonata-workflow)

[![Build Status](https://api.travis-ci.org/yokai-php/sonata-workflow.png?branch=master)](https://travis-ci.org/yokai-php/sonata-workflow)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yokai-php/sonata-workflow/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yokai-php/sonata-workflow/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yokai-php/sonata-workflow/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yokai-php/sonata-workflow/?branch=master)


Introduction
------------
Expand Down Expand Up @@ -44,38 +40,6 @@ Configuration

Let say that you have an entity named `PullRequest` that is under workflow and for which you have an admin.

#### symfony/workflow <4.3
```yaml
# config/packages/workflow.yml
framework:
workflows:
pull_request:
type: state_machine
marking_store:
type: single_state
arguments:
- status
supports:
- App\Entity\PullRequest
places:
- opened
- pending_review
- merged
- closed
initial_place: opened
transitions:
start_review:
from: opened
to: pending_review
merge:
from: pending_review
to: merged
close:
from: pending_review
to: closed
```
#### symfony/workflow ^4.3|^5.0
```yaml
# config/packages/workflow.yml
framework:
Expand Down Expand Up @@ -224,18 +188,21 @@ services:
<?php
// src/Admin/Controller/PullRequestController.php
declare(strict_types=1);
namespace App\Admin\Controller;
use App\Entity\PullRequest;
use App\Form\PullRequest\StartReviewType;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\Response;
use Yokai\SonataWorkflow\Controller\WorkflowControllerTrait;
class PullRequestController extends CRUDController
{
use WorkflowControllerTrait;
protected function preApplyTransition($object, $transition)
protected function preApplyTransition($object, string $transition): ?Response
{
switch ($transition) {
case 'start_review':
Expand All @@ -245,7 +212,7 @@ class PullRequestController extends CRUDController
return null;
}
protected function startReview(PullRequest $object, $transition)
protected function startReview(PullRequest $object, string $transition): ?Response
{
$form = $this->createForm(
StartReviewType::class,
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
}
},
"require": {
"php": "^5.6|^7.0",
"php": "^7.1",
"sonata-project/admin-bundle": "^3.0",
"symfony/workflow": "^3.2|^4.0|^5.0"
"symfony/workflow": "^4.4|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"phpunit/phpunit": "^7.5",
"squizlabs/php_codesniffer": "^3.5"
},
"minimum-stability": "stable",
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<rule ref="PSR12"/>

<file>src/</file>
<file>tests/</file>

<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
colors="true"
bootstrap="vendor/autoload.php"
>
Expand Down
48 changes: 29 additions & 19 deletions src/Admin/Extension/WorkflowExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Yokai\SonataWorkflow\Admin\Extension;

use Knp\Menu\ItemInterface as MenuItemInterface;
Expand Down Expand Up @@ -42,7 +44,7 @@ public function __construct(Registry $registry, array $options = [])
/**
* @inheritdoc
*/
public function configureRoutes(AdminInterface $admin, RouteCollection $collection)
public function configureRoutes(AdminInterface $admin, RouteCollection $collection): void
{
$collection->add(
'workflow_apply_transition',
Expand All @@ -53,7 +55,7 @@ public function configureRoutes(AdminInterface $admin, RouteCollection $collecti
/**
* @inheritdoc
*/
public function alterNewInstance(AdminInterface $admin, $object)
public function alterNewInstance(AdminInterface $admin, $object): void
{
try {
$workflow = $this->getWorkflow($object, $this->options['workflow_name']);
Expand All @@ -72,7 +74,7 @@ public function configureSideMenu(
MenuItemInterface $menu,
$action,
AdminInterface $childAdmin = null
) {
): void {
if (null !== $childAdmin || !in_array($action, $this->options['render_actions'], true)) {
return;
}
Expand Down Expand Up @@ -100,7 +102,7 @@ public function configureSideMenu(
/**
* @inheritdoc
*/
public function getAccessMapping(AdminInterface $admin)
public function getAccessMapping(AdminInterface $admin): array
{
return [
'viewTransitions' => $this->options['view_transitions_role'],
Expand All @@ -115,15 +117,15 @@ public function getAccessMapping(AdminInterface $admin)
* @return Workflow
* @throws InvalidArgumentException
*/
protected function getWorkflow($subject, $workflowName = null)
protected function getWorkflow($subject, string $workflowName = null): Workflow
{
return $this->registry->get($subject, $workflowName);
}

/**
* @param OptionsResolver $resolver
*/
protected function configureOptions(OptionsResolver $resolver)
protected function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefaults([
Expand Down Expand Up @@ -157,7 +159,7 @@ protected function configureOptions(OptionsResolver $resolver)
* @param MenuItemInterface $menu
* @param AdminInterface $admin
*/
protected function noTransitions(MenuItemInterface $menu, AdminInterface $admin)
protected function noTransitions(MenuItemInterface $menu, AdminInterface $admin): void
{
if ($this->options['no_transition_display']) {
$menu->addChild($this->options['no_transition_label'], [
Expand All @@ -173,13 +175,17 @@ protected function noTransitions(MenuItemInterface $menu, AdminInterface $admin)
}

/**
* @param MenuItemInterface $menu
* @param AdminInterface $admin
* @param Transition[] $transitions
* @param object $subject
* @param MenuItemInterface $menu
* @param AdminInterface $admin
* @param iterable|Transition[] $transitions
* @param object $subject
*/
protected function transitionsDropdown(MenuItemInterface $menu, AdminInterface $admin, $transitions, $subject)
{
protected function transitionsDropdown(
MenuItemInterface $menu,
AdminInterface $admin,
iterable $transitions,
$subject
): void {
$workflowMenu = $menu->addChild($this->options['dropdown_transitions_label'], [
'attributes' => [
'dropdown' => true,
Expand All @@ -201,8 +207,12 @@ protected function transitionsDropdown(MenuItemInterface $menu, AdminInterface $
* @param Transition $transition
* @param object $subject
*/
protected function transitionsItem(MenuItemInterface $menu, AdminInterface $admin, Transition $transition, $subject)
{
protected function transitionsItem(
MenuItemInterface $menu,
AdminInterface $admin,
Transition $transition,
$subject
): void {
$options = [
'attributes' => [],
'extras' => [
Expand All @@ -229,7 +239,7 @@ protected function transitionsItem(MenuItemInterface $menu, AdminInterface $admi
*
* @return string|null
*/
protected function getTransitionIcon(Transition $transition)
protected function getTransitionIcon(Transition $transition): ?string
{
if (isset($this->options['transitions_icons'][$transition->getName()])) {
return $this->options['transitions_icons'][$transition->getName()];
Expand All @@ -245,7 +255,7 @@ protected function getTransitionIcon(Transition $transition)
*
* @return string
*/
protected function generateTransitionUri(AdminInterface $admin, Transition $transition, $subject)
protected function generateTransitionUri(AdminInterface $admin, Transition $transition, $subject): string
{
return $admin->generateObjectUrl(
'workflow_apply_transition',
Expand All @@ -260,7 +270,7 @@ protected function generateTransitionUri(AdminInterface $admin, Transition $tran
*
* @return bool
*/
protected function isGrantedView(AdminInterface $admin, $subject)
protected function isGrantedView(AdminInterface $admin, $subject): bool
{
try {
$admin->checkAccess('viewTransitions', $subject);
Expand All @@ -277,7 +287,7 @@ protected function isGrantedView(AdminInterface $admin, $subject)
*
* @return bool
*/
protected function isGrantedApply(AdminInterface $admin, $subject)
protected function isGrantedApply(AdminInterface $admin, $subject): bool
{
try {
$admin->checkAccess('applyTransitions', $subject);
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/WorkflowController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Yokai\SonataWorkflow\Controller;

use Sonata\AdminBundle\Controller\CRUDController;
Expand Down
10 changes: 6 additions & 4 deletions src/Controller/WorkflowControllerTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Yokai\SonataWorkflow\Controller;

use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -43,7 +45,7 @@ trait WorkflowControllerTrait
*
* @required Symfony DI autowiring
*/
public function setWorkflowRegistry(Registry $workflowRegistry)
public function setWorkflowRegistry(Registry $workflowRegistry): void
{
$this->workflowRegistry = $workflowRegistry;
}
Expand All @@ -53,7 +55,7 @@ public function setWorkflowRegistry(Registry $workflowRegistry)
*
* @return Response
*/
public function workflowApplyTransitionAction(Request $request)
public function workflowApplyTransitionAction(Request $request): Response
{
$id = $request->get($this->admin->getIdParameter());

Expand Down Expand Up @@ -153,7 +155,7 @@ public function workflowApplyTransitionAction(Request $request)
* @return Workflow
* @throws InvalidArgumentException
*/
protected function getWorkflow($object)
protected function getWorkflow($object): Workflow
{
$registry = $this->workflowRegistry;
if ($registry === null) {
Expand Down Expand Up @@ -183,7 +185,7 @@ protected function getWorkflow($object)
*
* @return null|Response
*/
protected function preApplyTransition($object, $transition)
protected function preApplyTransition($object, string $transition): ?Response
{
return null;
}
Expand Down
Loading

0 comments on commit 3cb39fe

Please sign in to comment.