cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,67 +1,52 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\TaskBundle\Workflow\Definition;
use Chill\TaskBundle\Entity\AbstractTask;
use Chill\TaskBundle\Entity\SingleTask;
use LogicException;
use Symfony\Component\Workflow\Transition;
use function array_key_exists;
use function array_slice;
use function explode;
use function implode;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class DefaultTaskDefinition implements \Chill\TaskBundle\Workflow\TaskWorkflowDefinition
{
const TRANSITION_METADATA = [
public const DEFINITION_METADATA = [
'name' => 'Default task',
];
public const TRANSITION_METADATA = [
'close' => [
'verb' => 'close',
'class' => 'btn btn-task-label btn-task-close',
'sentence' => '%user% has closed the task',
'sentence_confirmation' => 'Are you sure you want to close this task ?',
'apply_transition_submit_label' => 'Close_verb'
'apply_transition_submit_label' => 'Close_verb',
],
'cancel' => [
'verb' => 'cancel',
'class' => 'btn btn-task-label btn-task-cancel',
'sentence' => '%user% has canceled the task',
'sentence_confirmation' => 'Are you sure you want to cancel this task ?',
'apply_transition_submit_label' => 'Set this task to cancel state'
'apply_transition_submit_label' => 'Set this task to cancel state',
],
'start' => [
'verb' => 'start',
'class' => 'btn btn-task-label btn-task-start',
'sentence' => '%user% has started the task',
'sentence_confirmation' => 'Are you sure you want to start this task ?',
'apply_transition_submit_label' => 'Start_verb'
]
'apply_transition_submit_label' => 'Start_verb',
],
];
const DEFINITION_METADATA = [
'name' => 'Default task'
];
public function supports(AbstractTask $task)
{
return $task instanceof SingleTask
&& $task->getType() === 'task_default';
}
public static function getAssociatedWorkflowName()
{
@@ -73,38 +58,46 @@ class DefaultTaskDefinition implements \Chill\TaskBundle\Workflow\TaskWorkflowDe
string $key,
$metadataSubject = null
) {
$keys = \explode('.', $key);
$keys = explode('.', $key);
switch($keys[0]) {
switch ($keys[0]) {
case 'transition':
if (!$metadataSubject instanceof Transition) {
throw new \LogicException("You must give a transition as metadatasubject");
throw new LogicException('You must give a transition as metadatasubject');
}
return $this->getTransitionMetadata(\implode('.', \array_slice($keys, 1)), $metadataSubject);
return $this->getTransitionMetadata(implode('.', array_slice($keys, 1)), $metadataSubject);
case 'definition':
return self::DEFINITION_METADATA[$keys[1]] ?? $key;
default:
return $key;
}
}
public function isClosed(AbstractTask $task)
{
return array_key_exists('closed', $task->getCurrentStates())
|| array_key_exists('canceled', $task->getCurrentStates());
}
public function supports(AbstractTask $task)
{
return $task instanceof SingleTask
&& $task->getType() === 'task_default';
}
protected function getTransitionMetadata($key, Transition $transition)
{
if (!\array_key_exists($transition->getName(), self::TRANSITION_METADATA)) {
if (!array_key_exists($transition->getName(), self::TRANSITION_METADATA)) {
return $key;
}
if (!\array_key_exists($key, self::TRANSITION_METADATA[$transition->getName()])) {
if (!array_key_exists($key, self::TRANSITION_METADATA[$transition->getName()])) {
return $key;
}
return self::TRANSITION_METADATA[$transition->getName()][$key];
}
public function isClosed(AbstractTask $task)
{
return \array_key_exists('closed', $task->getCurrentStates())
|| \array_key_exists('canceled', $task->getCurrentStates());
}
}

View File

@@ -1,59 +1,47 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\TaskBundle\Workflow\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
/**
*
* Chill is a software for social workers
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\TaskBundle\Workflow\Event;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Workflow\Event\GuardEvent;
class DefaultTaskGuardEvent implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'workflow.task_default.guard' => [
'checkACL'
]
];
}
/**
*
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
{
$this->authorizationChecker = $authorizationChecker;
}
public function checkACL(GuardEvent $event)
{
if (FALSE === $this->authorizationChecker->isGranted(TaskVoter::UPDATE,
$event->getSubject())) {
if (false === $this->authorizationChecker->isGranted(
TaskVoter::UPDATE,
$event->getSubject()
)) {
$event->setBlocked(true);
}
}
public static function getSubscribedEvents(): array
{
return [
'workflow.task_default.guard' => [
'checkACL',
],
];
}
}

View File

@@ -1,27 +1,14 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\TaskBundle\Workflow;
/**
* Chill is a software for social workers
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\TaskBundle\Workflow;
interface TaskWorkflowDefinition
{
}

View File

@@ -1,93 +1,84 @@
<?php
/*
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
/**
* Chill is a software for social workers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\TaskBundle\Workflow;
use Chill\TaskBundle\Entity\AbstractTask;
use LogicException;
use Symfony\Component\Workflow\Event\Event;
use Symfony\Component\Workflow\SupportStrategy\WorkflowSupportStrategyInterface;
use Symfony\Component\Workflow\WorkflowInterface;
use Symfony\Component\Workflow\Event\Event;
use function sprintf;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class TaskWorkflowManager implements WorkflowSupportStrategyInterface
{
/**
*
* @var TaskWorkflowDefinition[]
*/
protected $definitions = array();
public function addDefinition(TaskWorkflowDefinition $definition) {
protected $definitions = [];
public function addDefinition(TaskWorkflowDefinition $definition)
{
$this->definitions[] = $definition;
}
/**
*
* @param AbstractTask $task
* @throws LogicException
*
* @return TaskWorkflowDefinition
* @throws \LogicException
*/
public function getTaskWorkflowDefinition(AbstractTask $task)
{
$definitions = array();
foreach($this->definitions as $tested) {
$definitions = [];
foreach ($this->definitions as $tested) {
if ($tested->supports($task)) {
$definitions[] = $tested;
}
}
$count = count($definitions);
if ($count > 1) {
throw new \LogicException("More than one TaskWorkflowDefinition supports "
. "this task. This should not happens.");
} elseif ($count === 0) {
throw new \LogicException(\sprintf("No taskWorkflowDefinition supports this task type: %s (task id: %s).", $task->getType(), $task->getId()));
if (1 < $count) {
throw new LogicException('More than one TaskWorkflowDefinition supports '
. 'this task. This should not happens.');
}
if (0 === $count) {
throw new LogicException(sprintf('No taskWorkflowDefinition supports this task type: %s (task id: %s).', $task->getType(), $task->getId()));
}
return $definitions[0];
}
public function getWorkflowMetadata(AbstractTask $task, string $key, $metadataSubject = null, ?string $name = null)
{
return $this->getTaskWorkflowDefinition($task)
->getWorkflowMetadata($task, $key, $metadataSubject);
}
public function onTaskStateEntered(Event $e)
{
$task = $e->getSubject();
$definition = $this->getTaskWorkflowDefinition($task);
$task->setClosed($definition->isClosed($task));
}
public function supports(WorkflowInterface $workflow, $subject): bool
{
if (!$subject instanceof AbstractTask) {
return false;
}
return $workflow->getName() === $this
->getTaskWorkflowDefinition($subject)->getAssociatedWorkflowName();
}
public function getWorkflowMetadata(AbstractTask $task, string $key, $metadataSubject = null, string $name = null)
{
return $this->getTaskWorkflowDefinition($task)
->getWorkflowMetadata($task, $key, $metadataSubject);
}
public function onTaskStateEntered(Event $e)
{
$task = $e->getSubject();
$definition = $this->getTaskWorkflowDefinition($task);
$task->setClosed($definition->isClosed($task));
}
}