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,105 +1,98 @@
<?php
/*
* Copyright (C) 2018 Julien Fastré <julien.fastre@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\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Knp\Menu\MenuItem;
use LogicException;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Translation\TranslatorInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class MenuBuilder implements LocalMenuBuilderInterface
{
/**
*
* @var TranslatorInterface
*/
protected $translator;
/**
*
* @var AuthorizationCheckerInterface
*/
protected $authorizationChecker;
/**
* @var TranslatorInterface
*/
protected $translator;
public function __construct(
AuthorizationCheckerInterface $authorizationChecker,
TranslatorInterface $translator)
TranslatorInterface $translator
)
{
$this->translator = $translator;
$this->authorizationChecker = $authorizationChecker;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
public function buildAccompanyingCourseMenu($menu, $parameters)
{
switch($menuId) {
case 'person':
$this->buildPersonMenu($menu, $parameters);
break;
case 'accompanyingCourse':
$this->buildAccompanyingCourseMenu($menu, $parameters);
break;
case 'section':
$menu->setExtras('icons', 'tasks');
break;
default:
throw new \LogicException("this menuid $menuId is not implemented");
$course = $parameters['accompanyingCourse'];
if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $course)) {
$menu->addChild(
$this->translator->trans('Tasks'),
[
'route' => 'chill_task_singletask_by-course_list',
'routeParameters' => ['id' => $course->getId()],
]
)
->setExtra('order', 400);
}
}
public function buildPersonMenu($menu, $parameters){
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
switch ($menuId) {
case 'person':
$this->buildPersonMenu($menu, $parameters);
break;
case 'accompanyingCourse':
$this->buildAccompanyingCourseMenu($menu, $parameters);
break;
case 'section':
$menu->setExtras('icons', 'tasks');
break;
default:
throw new LogicException("this menuid {$menuId} is not implemented");
}
}
public function buildPersonMenu($menu, $parameters)
{
//var $person \Chill\PersonBundle\Entity\Person */
$person = $parameters['person'] ?? null;
if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $person)) {
$menu->addChild(
$this->translator->trans('Tasks'), [
$this->translator->trans('Tasks'),
[
'route' => 'chill_task_singletask_by-person_list',
'routeParameters' =>
[ 'id' => $person->getId() ]
])
'routeParameters' => ['id' => $person->getId()],
]
)
->setExtra('order', 400);
}
}
public function buildAccompanyingCourseMenu($menu, $parameters){
$course = $parameters['accompanyingCourse'];
if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $course)) {
$menu->addChild(
$this->translator->trans('Tasks'), [
'route' => 'chill_task_singletask_by-course_list',
'routeParameters' =>
[ 'id' => $course->getId() ]
])
->setExtra('order', 400);
}
}
public static function getMenuIds(): array
{
return ['person', 'accompanyingCourse'];

View File

@@ -1,47 +1,32 @@
<?php
/*
* Copyright (C) 2018 Julien Fastré <julien.fastre@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\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Symfony\Component\Translation\TranslatorInterface;
/**
*
*
*/
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
/**
*
* @var AuthorizationCheckerInterface
*/
public $authorizationChecker;
/**
*
* @var TranslatorInterface
*/
public $translator;
public function __construct(
AuthorizationCheckerInterface $authorizationChecker,
TranslatorInterface $translator
@@ -49,30 +34,31 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
if (FALSE === $this->authorizationChecker->isGranted(TaskVoter::SHOW)) {
if (false === $this->authorizationChecker->isGranted(TaskVoter::SHOW)) {
return;
}
$menu->addChild(
$this->translator->trans("Tasks"),
$this->translator->trans('Tasks'),
[
'route' => 'chill_task_singletask_list', [
'routeParameters' => [
'hide_form' => false
]
]])
'routeParameters' => [
'hide_form' => false,
],
], ]
)
->setExtras([
'order'=> 50,
'order' => 50,
'icon' => 'exclamation-triangle',
'entryclass' => 'user_menu__entry--warning-entry'
'entryclass' => 'user_menu__entry--warning-entry',
]);
}
public static function getMenuIds(): array
{
return [ 'section' ];
return ['section'];
}
}

View File

@@ -1,42 +1,30 @@
<?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\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Knp\Menu\MenuItem;
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
use Chill\TaskBundle\Templating\UI\CountNotificationTask;
use Knp\Menu\MenuItem;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Translation\TranslatorInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class UserMenuBuilder implements LocalMenuBuilderInterface
{
/**
* @var AuthorizationCheckerInterface
*/
public $authorizationChecker;
/**
*
* @var CountNotificationTask
*/
public $counter;
@@ -47,17 +35,10 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
public $tokenStorage;
/**
*
* @var TranslatorInterface
*/
public $translator;
/**
*
* @var AuthorizationCheckerInterface
*/
public $authorizationChecker;
public function __construct(
CountNotificationTask $counter,
TokenStorageInterface $tokenStorage,
@@ -70,14 +51,9 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
$this->authorizationChecker = $authorizationChecker;
}
public static function getMenuIds(): array
{
return [ 'user' ];
}
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
if (FALSE === $this->authorizationChecker->isGranted(TaskVoter::SHOW)) {
if (false === $this->authorizationChecker->isGranted(TaskVoter::SHOW)) {
return;
}
@@ -85,7 +61,7 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
$ended = $this->counter->countNotificationEnded($user);
$warning = $this->counter->countNotificationWarning($user);
if ($ended > 0) {
if (0 < $ended) {
$this->addItemInMenu(
$menu,
'%number% tasks over deadline',
@@ -96,7 +72,7 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
);
}
if ($warning > 0) {
if (0 < $warning) {
$this->addItemInMenu(
$menu,
'%number% tasks near deadline',
@@ -107,19 +83,23 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
);
}
$menu->addChild("My tasks", [
'route' => 'chill_task_singletask_my_tasks'
])
$menu->addChild('My tasks', [
'route' => 'chill_task_singletask_my_tasks',
])
->setExtras([
'order' => -10,
'icon' => 'tasks'
'icon' => 'tasks',
]);
}
public static function getMenuIds(): array
{
return ['user'];
}
protected function addItemInMenu(MenuItem $menu, $message, $number, $order, array $states = [], array $status = [])
{
if ($number > 0) {
if (0 < $number) {
$menu->addChild(
$this->translator->transChoice($message, $number),
[
@@ -128,15 +108,16 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
'f' => [
'checkboxes' => [
'states' => $states,
'status' => $status
]
]
'status' => $status,
],
],
],
]
])
)
->setExtras([
'order'=> $order,
'order' => $order,
'icon' => 'exclamation-triangle',
'entryclass' => 'user_menu__entry--warning-entry'
'entryclass' => 'user_menu__entry--warning-entry',
]);
}
}