fix: SA: Fix "Call to sprintf" rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 11:52:52 +01:00
parent f8aeb08594
commit a3eb23478a
4 changed files with 62 additions and 116 deletions

View File

@@ -1,22 +1,4 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2019, Champs Libres Cooperative SCRLFS, <http://www.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\MainBundle\CRUD\Controller;
@@ -37,58 +19,38 @@ use Chill\MainBundle\Pagination\PaginatorInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Serializer\SerializerInterface;
/**
* Class CRUDController
*
* @package Chill\MainBundle\CRUD\Controller
*/
class CRUDController extends AbstractController
{
/**
* The crud configuration
*
* This configuration si defined by `chill_main['crud']`.
*
* @var array
*/
protected $crudConfig;
protected array $crudConfig;
/**
* @param array $config
*/
public function setCrudConfig(array $config)
public function setCrudConfig(array $config): void
{
$this->crudConfig = $config;
}
/**
* @param $parameter
* @return Response
*/
public function CRUD($parameter)
public function CRUD(?string $parameter): Response
{
return new Response($parameter);
}
/**
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function delete(Request $request, $id)
public function delete(Request $request, $id): Response
{
return $this->deleteAction('delete', $request, $id);
}
/**
* @param string $action
* @param Request $request
* @param $id
* @param null $formClass
* @return null|\Symfony\Component\HttpFoundation\RedirectResponse|Response|void
*/
protected function deleteAction(string $action, Request $request, $id, $formClass = null)
protected function deleteAction(string $action, Request $request, $id, $formClass = null): Response
{
$this->onPreDelete($action, $request, $id);
@@ -101,8 +63,13 @@ class CRUDController extends AbstractController
}
if (NULL === $entity) {
throw $this->createNotFoundException(sprintf("The %s with id %s "
. "is not found"), $this->getCrudName(), $id);
throw $this->createNotFoundException(
sprintf(
'The %s with id %s is not found',
$this->getCrudName(),
$id
)
);
}
$response = $this->checkACL($action, $entity);
@@ -141,7 +108,9 @@ class CRUDController extends AbstractController
return $this->redirectToRoute('chill_crud_'.$this->getCrudName().'_view', ['id' => $entity->getId()]);
} elseif ($form->isSubmitted()) {
}
if ($form->isSubmitted()) {
$this->addFlash('error', $this->generateFormErrorMessage($action, $form));
}
@@ -505,8 +474,13 @@ class CRUDController extends AbstractController
}
if (NULL === $entity) {
throw $this->createNotFoundException(sprintf("The %s with id %s "
. "is not found", $this->getCrudName(), $id));
throw $this->createNotFoundException(
sprintf(
'The %s with id %s is not found',
$this->getCrudName(),
$id
)
);
}
$response = $this->checkACL($action, $entity);
@@ -598,8 +572,13 @@ class CRUDController extends AbstractController
$entity = $this->getEntity($action, $id, $request);
if (NULL === $entity) {
throw $this->createNotFoundException(sprintf("The %s with id %s "
. "is not found", $this->getCrudName(), $id));
throw $this->createNotFoundException(
sprintf(
'The %s with id %s is not found',
$this->getCrudName(),
$id
)
);
}
$response = $this->checkACL($action, $entity);