cs: Enable more risky rules.

This commit is contained in:
Pol Dellaiera
2021-11-30 11:37:57 +01:00
parent c8195e6df5
commit a9188355c5
193 changed files with 306 additions and 63 deletions

View File

@@ -127,7 +127,7 @@ class PersonMove
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
}
return \sprintf(
return sprintf(
'DELETE FROM %s WHERE %s',
$this->getTableName($metadata),
implode(' AND ', $conditions)
@@ -151,7 +151,7 @@ class PersonMove
$conditions[] = sprintf('%s = %d', $columns['name'], $from->getId());
}
return \sprintf(
return sprintf(
'UPDATE %s SET %s WHERE %s',
$this->getTableName($metadata),
implode(' ', $sets),

View File

@@ -38,7 +38,11 @@ use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\Form\FormFactoryInterface;
use function array_key_exists;
use function count;
use function file_get_contents;
use function get_class;
use function in_array;
use function is_array;
use function json_decode;
final class ImportPeopleFromCSVCommand extends Command
@@ -352,7 +356,7 @@ final class ImportPeopleFromCSVCommand extends Command
}
// handle address
if (\in_array('postalcode', $headers)) {
if (in_array('postalcode', $headers)) {
if (!empty($postalCodeValue)) {
$address = new Address();
$postalCode = $this->guessPostalCode($postalCodeValue, $localityValue ?? '');
@@ -363,7 +367,7 @@ final class ImportPeopleFromCSVCommand extends Command
$address->setPostcode($postalCode);
if (\in_array('street1', $headers)) {
if (in_array('street1', $headers)) {
$address->setStreetAddress1($street1Value);
}
$address->setValidFrom(new DateTime('today'));
@@ -516,13 +520,13 @@ final class ImportPeopleFromCSVCommand extends Command
->getResult();
if (count($centers) > 1) {
if (\strtolower($centers[0]->getName()) === \strtolower($centerName)) {
if (strtolower($centers[0]->getName()) === strtolower($centerName)) {
return $centers[0];
}
}
$centersByName = [];
$names = \array_map(function (Center $c) use (&$centersByName) {
$names = array_map(function (Center $c) use (&$centersByName) {
$n = $c->getName();
$centersByName[$n] = $c;
@@ -605,7 +609,7 @@ final class ImportPeopleFromCSVCommand extends Command
}
$postalCodeByName = [];
$names = \array_map(function (PostalCode $pc) use (&$postalCodeByName) {
$names = array_map(function (PostalCode $pc) use (&$postalCodeByName) {
$n = $pc->getName();
$postalCodeByName[$n] = $pc;

View File

@@ -9,6 +9,8 @@
namespace Chill\PersonBundle\Config;
use function count;
/**
* Give help to interact with the config for alt names.
*/

View File

@@ -35,6 +35,7 @@ use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Workflow\Registry;
use function array_values;
use function count;
final class AccompanyingCourseApiController extends ApiController
{

View File

@@ -26,6 +26,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function array_filter;
use function count;
/**
* Class AccompanyingPeriodController.

View File

@@ -23,6 +23,8 @@ use Symfony\Component\Security\Core\Security;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use function array_key_exists;
use function count;
/**
* @Route("/{_locale}/person/household")

View File

@@ -25,6 +25,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Exception;
use Symfony\Component\Translation\TranslatorInterface;
use function count;
class HouseholdMemberController extends ApiController
{

View File

@@ -16,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function count;
/**
* Class PersonAddressController

View File

@@ -30,6 +30,7 @@ use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function count;
use function hash;
use function implode;
use function in_array;

View File

@@ -27,6 +27,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\TranslatorInterface;
use function count;
class PersonDuplicateController extends Controller
{

View File

@@ -15,6 +15,7 @@ use Chill\MainBundle\Serializer\Model\Collection;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use function count;
class SocialWorkSocialActionApiController extends ApiController
{

View File

@@ -19,6 +19,7 @@ use DateTimeImmutable;
use Doctrine\Persistence\ObjectManager;
use function array_pop;
use function array_rand;
use function count;
class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Doctrine\Common\DataFixtures\DependentFixtureInterface
{

View File

@@ -40,6 +40,7 @@ use Nelmio\Alice\Loader\NativeLoader;
use Nelmio\Alice\ObjectSet;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Workflow\Registry;
use function count;
use function random_int;
use function ucfirst;
@@ -273,7 +274,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
$this->cacheCenters = $this->centerRepository->findAll();
}
return $this->cacheCenters[\array_rand($this->cacheCenters)];
return $this->cacheCenters[array_rand($this->cacheCenters)];
}
/**
@@ -291,7 +292,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
return null;
}
return $this->cacheCountries[\array_rand($this->cacheCountries)];
return $this->cacheCountries[array_rand($this->cacheCountries)];
}
/**
@@ -475,7 +476,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
private function getPostalCode(): PostalCode
{
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
$ref = LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)];
return $this->getReference($ref);
}
@@ -522,7 +523,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
$this->cacheSocialIssues = $this->socialIssueRepository->findAll();
}
return $this->cacheSocialIssues[\array_rand($this->cacheSocialIssues)];
return $this->cacheSocialIssues[array_rand($this->cacheSocialIssues)];
}
private function getRandomUser(): User
@@ -531,7 +532,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
$this->cacheUsers = $this->userRepository->findAll();
}
return $this->cacheUsers[\array_rand($this->cacheUsers)];
return $this->cacheUsers[array_rand($this->cacheUsers)];
}
/*

View File

@@ -20,6 +20,7 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use function count;
class LoadRelationships extends Fixture implements DependentFixtureInterface
{
@@ -49,7 +50,7 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
->setFromPerson($this->getRandomPerson($this->em))
->setToPerson($this->getRandomPerson($this->em))
->setRelation($this->getReference(LoadRelations::RELATION_KEY .
\random_int(0, count(LoadRelations::RELATIONS) - 1)))
random_int(0, count(LoadRelations::RELATIONS) - 1)))
->setReverse((bool) random_int(0, 1))
->setCreatedBy($user)
->setUpdatedBy($user)

View File

@@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use function array_key_exists;
/**
* Class ChillPersonExtension

View File

@@ -39,6 +39,8 @@ use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\GroupSequenceProviderInterface;
use UnexpectedValueException;
use function count;
use function in_array;
/**
* AccompanyingPeriod Class.

View File

@@ -22,6 +22,7 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function count;
/**
* @ORM\Entity

View File

@@ -40,6 +40,8 @@ use Exception;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function count;
use function in_array;
/**
* Person Class.

View File

@@ -36,6 +36,8 @@ use function addcslashes;
use function array_key_exists;
use function array_keys;
use function array_merge;
use function count;
use function in_array;
use function strtolower;
use function uniqid;
@@ -429,7 +431,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
if ($cfType instanceof CustomFieldChoice && $cfType->isMultiple($cf)) {
return function ($value) use ($cf, $cfType, $key) {
$slugChoice = $this->extractInfosFromSlug($key)['additionnalInfos']['choiceSlug'];
$decoded = \json_decode($value, true);
$decoded = json_decode($value, true);
if ('_header' === $value) {
$label = $cfType->getChoices($cf)[$slugChoice];

View File

@@ -19,8 +19,10 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function array_filter;
use function count;
use function implode;
use function in_array;
use function is_array;
class GenderFilter implements
FilterInterface,

View File

@@ -15,6 +15,7 @@ use RuntimeException;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use function call_user_func;
use function count;
use function in_array;
/**

View File

@@ -15,6 +15,7 @@ use Doctrine\Common\Collections\Collection;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use function array_key_exists;
use function is_array;
class PersonAltNameDataMapper implements DataMapperInterface
{

View File

@@ -26,6 +26,8 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInt
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Translation\TranslatorInterface;
use function in_array;
use function is_array;
/**
* This type allow to pick a person.

View File

@@ -31,6 +31,7 @@ namespace Chill\PersonBundle\Privacy;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\EventDispatcher\Event;
use function count;
/**
* Class PrivacyEvent.

View File

@@ -16,6 +16,7 @@ use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Security\Core\Security;
use function count;
final class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodACLAwareRepositoryInterface
{

View File

@@ -25,6 +25,7 @@ use function array_fill;
use function array_map;
use function array_merge;
use function array_push;
use function count;
use function explode;
use function implode;

View File

@@ -15,6 +15,7 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use Exception;
use function count;
use function in_array;
use function str_replace;

View File

@@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Request;
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || php_sapi_name() === 'cli-server')
|| !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', 'fe80::1', '::1']) || PHP_SAPI === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');

View File

@@ -18,6 +18,7 @@ use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
use Chill\PersonBundle\Repository\PersonRepository;
use Symfony\Component\Security\Core\Security;
use function array_map;
use function count;
use function in_array;
class SearchPersonApiProvider implements SearchApiInterface

View File

@@ -17,6 +17,7 @@ use Chill\PersonBundle\Templating\Entity\PersonRender;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Role\Role;
use function count;
class SimilarPersonMatcher
{

View File

@@ -21,6 +21,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
use function array_key_exists;
use function array_merge;
use function count;
class AccompanyingPeriodResourceNormalizer implements DenormalizerInterface, DenormalizerAwareInterface
{

View File

@@ -25,6 +25,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Expr\Comparison;
use Doctrine\Persistence\ObjectRepository;
use Exception;
use function count;
final class SocialWorkMetadata implements SocialWorkMetadataInterface
{

View File

@@ -25,6 +25,7 @@ use Symfony\Component\HttpFoundation\Request;
use function array_map;
use function array_pop;
use function array_rand;
use function count;
use function json_decode;
use function json_encode;

View File

@@ -19,6 +19,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Iterator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use function array_pop;
use function count;
use function preg_match;
/**

View File

@@ -15,6 +15,7 @@ use DateTime;
use Doctrine\Common\Collections\Criteria;
use LogicalException;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use function array_key_exists;
/**
* Test the creation or deletion of accompanying periods.

View File

@@ -22,6 +22,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use function array_pop;
use function count;
use function json_decode;
use function json_encode;
use function random_int;

View File

@@ -14,6 +14,8 @@ use DateTime;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DomCrawler\Form;
use function count;
use function in_array;
/**
* Test creation and deletion for persons.

View File

@@ -16,7 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
* @internal
* @coversNothing
*/
class PersonControllerViewTestWithHiddenFields extends WebTestCase
class PersonControllerViewWithHiddenFieldsTest extends WebTestCase
{
/**
* @var \Doctrine\ORM\EntityManagerInterface The entity manager

View File

@@ -13,6 +13,7 @@ use Chill\MainBundle\Test\PrepareClientTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
use function array_pop;
use function count;
use function json_decode;
/**

View File

@@ -16,6 +16,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTime;
use DateTimeInterface;
use function count;
/**
* @internal

View File

@@ -12,6 +12,7 @@ namespace Chill\PersonBundle\Tests\Form\Type;
use Chill\PersonBundle\Form\Type\PickPersonType;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use function count;
/**
* @internal

View File

@@ -16,6 +16,7 @@ use Chill\PersonBundle\Household\MembersEditorFactory;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use function count;
/**
* @internal
@@ -91,7 +92,7 @@ class MembersEditorTest extends TestCase
);
$persistables = $editor->getPersistable();
$this->assertEquals(\count($persistables), 1);
$this->assertEquals(count($persistables), 1);
$membership1 = $persistables[0];
$this->assertSame($household1, $membership1->getHousehold());

View File

@@ -19,6 +19,7 @@ use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use function count;
class ParticipationOverlapValidator extends ConstraintValidator
{

View File

@@ -18,6 +18,7 @@ use Doctrine\Common\Collections\Collection;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use function count;
use function in_array;
class ResourceDuplicateCheckValidator extends ConstraintValidator

View File

@@ -15,6 +15,7 @@ use Chill\PersonBundle\Templating\Entity\PersonRender;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use function count;
/**
* Validate that a person does not belong to two household at

View File

@@ -14,6 +14,9 @@ use DateTime;
use LogicException;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use function get_class;
use function gettype;
use function is_object;
class BirthdateValidator extends ConstraintValidator
{

View File

@@ -26,6 +26,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment;
use UnexpectedValueException;
use function array_key_exists;
use function count;
/**
* add a widget with person list.

View File

@@ -11,6 +11,7 @@ namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use function count;
/**
* Check if each person do not have multiple addresses with the same valideFrom.