cs: Enable a couple of risky rules.

This commit is contained in:
Pol Dellaiera 2021-11-24 12:38:18 +01:00
parent acc4647346
commit f531cdc0ec
No known key found for this signature in database
GPG Key ID: D476DFE9C67467CA
51 changed files with 130 additions and 132 deletions

View File

@ -22,14 +22,14 @@ $rules = $config->getRules();
$riskyRules = [
'final_internal_class' => false,
'no_useless_sprintf' => false,
// 'no_useless_sprintf' => false,
'dir_constant' => false,
'no_alias_functions' => false,
'implode_call' => false,
// 'no_alias_functions' => false,
// 'implode_call' => false,
'combine_nested_dirname' => false,
'pow_to_exponentiation' => false,
// 'pow_to_exponentiation' => false,
'comment_to_phpdoc' => false,
'no_unset_on_property' => false,
// 'no_unset_on_property' => false,
'strict_param' => false,
'native_constant_invocation' => false,
'php_unit_test_annotation' => false,
@ -39,19 +39,19 @@ $riskyRules = [
'is_null' => false,
'native_function_invocation' => false,
'ternary_to_elvis_operator' => false,
'no_trailing_whitespace_in_string' => false,
// 'no_trailing_whitespace_in_string' => false,
'no_unreachable_default_argument_value' => false,
'php_unit_test_case_static_method_calls' => false,
'strict_comparison' => false,
'array_push' => false,
// 'array_push' => false,
'ereg_to_preg' => false,
'error_suppression' => false,
'fopen_flag_order' => false,
'fopen_flags' => false,
'logical_operators' => false,
// 'logical_operators' => false,
'modernize_types_casting' => false,
'no_homoglyph_names' => false,
'no_unneeded_final_method' => false,
// 'no_unneeded_final_method' => false,
'non_printable_character' => false,
'ordered_traits' => false,
'php_unit_mock_short_will_return' => false,

View File

@ -9,6 +9,6 @@ parameters:
tasks.license.holder: Champs-Libres
tasks.license.date_from: 2001
tasks.phpcsfixer.allow_risky: false
tasks.phpcsfixer.allow_risky: true
tasks.phpcsfixer.diff: true
tasks.phpstan.level: 1

View File

@ -72,7 +72,7 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali
array_key_exists('activity', $join)
&& !$this->checkJoinAlreadyDefined($join['activity'], 'reasons')
)
or (!array_key_exists('activity', $join))
|| (!array_key_exists('activity', $join))
) {
$qb->add(
'join',

View File

@ -152,7 +152,7 @@ class TimelineActivityProvider implements TimelineProviderInterface
$associationMapping = $metadataActivity->getAssociationMapping('person');
$role = new Role('CHILL_ACTIVITY_SEE');
$reachableScopes = $this->helper->getReachableScopes($this->user, $role->getRole(), $person->getCenter());
$whereClause = sprintf(' {activity.person_id} = ? AND {activity.scope_id} IN ({scopes_ids}) ');
$whereClause = ' {activity.person_id} = ? AND {activity.scope_id} IN ({scopes_ids}) ';
$scopes_ids = [];
// first parameter: activity.person_id

View File

@ -111,7 +111,7 @@ abstract class AbstractElementController extends Controller
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->flush();
@ -146,7 +146,7 @@ abstract class AbstractElementController extends Controller
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($element);
$em->flush();

View File

@ -63,7 +63,7 @@ class BudgetElementVoter extends AbstractChillVoter implements ProvideRoleHierar
protected function supports($attribute, $subject)
{
return (in_array($attribute, self::ROLES) && $subject instanceof AbstractElement)
or ($subject instanceof Person && in_array($attribute, [self::SHOW, self::CREATE]));
|| ($subject instanceof Person && in_array($attribute, [self::SHOW, self::CREATE]));
}
protected function voteOnAttribute($attribute, $subject, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)

View File

@ -160,7 +160,7 @@ class CalendarController extends AbstractController
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
}
if ($form->isSubmitted() and !$form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
}
@ -272,7 +272,7 @@ class CalendarController extends AbstractController
return $this->redirectToRoute('chill_calendar_calendar_list', $params);
}
if ($form->isSubmitted() and !$form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->get('translator')->trans('This form contains errors'));
}

View File

@ -197,7 +197,7 @@ class CreateFieldsOnGroupCommand extends Command
$em->persist($cf);
$output->writeln('<info>Adding Custom Field of type '
. $cf->getType() . "\t with slug " . $cf->getSlug() .
"\t and names : " . implode($names, ', ') . '</info>');
"\t and names : " . implode(', ', $names) . '</info>');
} else {
throw new RuntimeException('Error in field ' . $slug);
}

View File

@ -15,6 +15,6 @@ abstract class AbstractCustomField implements CustomFieldInterface
{
public function isEmptyValue($value, CustomField $customField)
{
return empty($value) and false !== $value;
return empty($value) && false !== $value;
}
}

View File

@ -191,7 +191,7 @@ class CustomFieldChoice extends AbstractCustomField
if ($this->allowOtherChoice($cf)) {
$labels = $cf->getOptions()[self::OTHER_VALUE_LABEL];
if (!is_array($labels) or count($labels) === 0) {
if (!is_array($labels) || count($labels) === 0) {
$labels['back'] = 'other value';
}
$choices['_other'] = $this->translatableStringHelper

View File

@ -59,7 +59,7 @@ class CustomFieldNumber extends AbstractCustomField
$options = $customField->getOptions();
//select the type depending to the SCALE
$type = (0 === $options[self::SCALE] or null === $options[self::SCALE]) ?
$type = (0 === $options[self::SCALE] || null === $options[self::SCALE]) ?
IntegerType::class : NumberType::class;
//'integer' : 'number';

View File

@ -63,7 +63,7 @@ class CustomFieldText extends AbstractCustomField
$attrArray = [];
if (array_key_exists(self::MULTIPLE_CF_INLINE, $options)
and $options[self::MULTIPLE_CF_INLINE]) {
&& $options[self::MULTIPLE_CF_INLINE]) {
$attrArray['class'] = 'multiple-cf-inline';
}

View File

@ -104,7 +104,7 @@ class CustomFieldsGroup
foreach ($this->customFields as $cf) {
if ($cf->isActive()) {
array_push($this->activeCustomFields, $cf);
$this->activeCustomFields[] = $cf;
}
}
}

View File

@ -43,12 +43,10 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
if ($id instanceof CustomFieldsGroup) {
throw new TransformationFailedException(
sprintf(
'The transformation failed: the expected argument on '
. 'reverseTransform is an object of type int,'
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. 'given'
)
);
}

View File

@ -33,7 +33,7 @@ class HouseholdMemberSelectionContext implements DocGeneratorContextInterface
$persons = $entity->getAccompanyingPeriodWork()->getPersons();
if (sizeof($persons) > 0) {
if (count($persons) > 0) {
$firstPerson = $persons[0];
$datas['setValues'][] = [

View File

@ -101,7 +101,7 @@ class DocumentAccompanyingCourseController extends AbstractController
);
}
if ($form->isSubmitted() and !$form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
@ -179,7 +179,7 @@ class DocumentAccompanyingCourseController extends AbstractController
return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]);
}
if ($form->isSubmitted() and !$form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}

View File

@ -121,7 +121,7 @@ class DocumentPersonController extends AbstractController
);
}
if ($form->isSubmitted() and !$form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}
@ -222,7 +222,7 @@ class DocumentPersonController extends AbstractController
return $this->redirectToRoute('person_document_index', ['person' => $person->getId()]);
}
if ($form->isSubmitted() and !$form->isValid()) {
if ($form->isSubmitted() && !$form->isValid()) {
$this->addFlash('error', $this->translator->trans('This form contains errors'));
}

View File

@ -742,7 +742,7 @@ class ParticipationController extends AbstractController
$single = $request->query->has('person_id');
$multiple = $request->query->has('persons_ids');
if (true === $single and true === $multiple) {
if (true === $single && true === $multiple) {
// we are not allowed to have both person_id and persons_ids
throw new RuntimeException("You are not allow to provide both 'person_id' and "
. "'persons_ids' simulaneously");

View File

@ -135,7 +135,7 @@ class EventSearch extends AbstractSearch
public function supports($domain, $format)
{
return 'event' === $domain or 'events' === $domain;
return 'event' === $domain || 'events' === $domain;
}
protected function composeQuery(QueryBuilder &$qb, $terms)
@ -171,8 +171,8 @@ class EventSearch extends AbstractSearch
}
if (
(isset($terms['name']) or isset($terms['_default']))
and (!empty($terms['name']) or !empty($terms['_default']))) {
(isset($terms['name']) || isset($terms['_default']))
&& (!empty($terms['name']) || !empty($terms['_default']))) {
// the form with name:"xyz" has precedence
$name = $terms['name'] ?? $terms['_default'];

View File

@ -63,7 +63,7 @@ class FamilyMemberVoter extends AbstractChillVoter implements ProvideRoleHierarc
protected function supports($attribute, $subject)
{
return (in_array($attribute, self::ROLES) && $subject instanceof FamilyMember)
or ($subject instanceof Person && in_array($attribute, [self::SHOW, self::CREATE]));
|| ($subject instanceof Person && in_array($attribute, [self::SHOW, self::CREATE]));
}
protected function voteOnAttribute($attribute, $subject, \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token)

View File

@ -99,11 +99,11 @@ class LoadAndUpdateLanguagesCommand extends Command
$excludeCode = (
(
!$input->getOption(self::INCLUDE_REGIONAL_VERSION)
and strpos($code, '_')
and !in_array($code, $this->regionalVersionToInclude)
) or (
&& strpos($code, '_')
&& !in_array($code, $this->regionalVersionToInclude)
) || (
!$input->getOption(self::INCLUDE_ANCIENT)
and in_array($code, $this->ancientToExclude)
&& in_array($code, $this->ancientToExclude)
)
);

View File

@ -222,20 +222,20 @@ class ExportController extends AbstractController
'csrf_protection' => $isGenerate ? false : true,
]);
if ('centers' === $step or 'generate_centers' === $step) {
if ('centers' === $step || 'generate_centers' === $step) {
$builder->add('centers', PickCenterType::class, [
'export_alias' => $alias,
]);
}
if ('export' === $step or 'generate_export' === $step) {
if ('export' === $step || 'generate_export' === $step) {
$builder->add('export', ExportType::class, [
'export_alias' => $alias,
'picked_centers' => $exportManager->getPickedCenters($data['centers']),
]);
}
if ('formatter' === $step or 'generate_formatter' === $step) {
if ('formatter' === $step || 'generate_formatter' === $step) {
$builder->add('formatter', FormatterType::class, [
'formatter_alias' => $exportManager
->getFormatterAlias($data['export']),
@ -388,7 +388,7 @@ class ExportController extends AbstractController
$dataFormatter = $this->session->get('formatter_step_raw', null);
$dataExport = $this->session->get('export_step_raw', null);
if (null === $dataFormatter and $export instanceof \Chill\MainBundle\Export\ExportInterface) {
if (null === $dataFormatter && $export instanceof \Chill\MainBundle\Export\ExportInterface) {
return $this->redirectToRoute('chill_main_export_new', [
'alias' => $alias, 'step' => $this->getNextStep('generate', $export, true),
]);

View File

@ -353,8 +353,8 @@ class User implements AdvancedUserInterface
public function removeGroupCenter(GroupCenter $groupCenter)
{
if ($this->groupCenters->removeElement($groupCenter) === false) {
throw new RuntimeException(sprintf('The groupCenter could not be removed, '
. 'it seems not to be associated with the user. Aborting.'));
throw new RuntimeException('The groupCenter could not be removed, '
. 'it seems not to be associated with the user. Aborting.');
}
}

View File

@ -346,7 +346,7 @@ class ExportManager
foreach ($this->exports as $export) {
if (!in_array($export->getType(), $existingTypes)) {
array_push($existingTypes, $export->getType());
$existingTypes[] = $export->getType();
}
}
@ -675,7 +675,7 @@ class ExportManager
foreach ($this->retrieveUsedAggregators($data) as $alias => $aggregator) {
if (!in_array($aggregator->applyOn(), $usedTypes)) {
array_push($usedTypes, $aggregator->applyOn());
$usedTypes[] = $aggregator->applyOn();
}
}
@ -718,7 +718,7 @@ class ExportManager
$filter = $this->getFilter($alias);
if (!in_array($filter->applyOn(), $usedTypes)) {
array_push($usedTypes, $filter->applyOn());
$usedTypes[] = $filter->applyOn();
}
}
}

View File

@ -210,7 +210,7 @@ class Paginator implements PaginatorInterface
public function hasPage($number)
{
return 0 < $number
and $this->countPages() >= $number;
&& $this->countPages() >= $number;
}
/**

View File

@ -42,7 +42,7 @@ class UserProvider implements UserProviderInterface
->getSingleResult();
} catch (NoResultException $e) {
throw new UsernameNotFoundException(
sprintf('Bad credentials.'),
'Bad credentials.',
0,
$e
);

View File

@ -141,7 +141,7 @@ class HouseholdApiController extends ApiController
foreach ($allHouseholds as $h) {
if ($h !== $currentHouseholdPerson) {
array_push($households, $h);
$households[] = $h;
}
}

View File

@ -192,7 +192,7 @@ class HouseholdController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator->trans('household.data_saved'));

View File

@ -190,7 +190,7 @@ class PersonAddressController extends AbstractController
$form = $this->createEditForm($person, $address);
$form->handleRequest($request);
if ($form->isSubmitted() and $form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$validatePersonErrors = $this->validatePerson($person);
if (count($validatePersonErrors) !== 0) {

View File

@ -599,7 +599,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
public function checkAccompanyingPeriodsAreNotCollapsing()
{
$periods = $this->getAccompanyingPeriodsOrdered();
$periodsNbr = sizeof($periods);
$periodsNbr = count($periods);
$i = 0;
while ($periodsNbr - 1 > $i) {

View File

@ -310,7 +310,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
foreach ($this->getCustomFields() as $cf) {
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
if ($cfType instanceof CustomFieldChoice && $cfType->isMultiple($cf)) {
foreach ($cfType->getChoices($cf) as $choiceSlug => $label) {
$slug = $this->slugToDQL($cf->getSlug(), 'choice', ['choiceSlug' => $choiceSlug]);
$qb->addSelect(
@ -426,7 +426,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
->render(json_decode($value, true), $cf, 'csv');
};
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
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);
@ -438,7 +438,7 @@ class ListPerson implements ListInterface, ExportElementValidatedInterface
. ' | ' . $label;
}
if ('_other' === $slugChoice and $cfType->isChecked($cf, $choiceSlug, $decoded)) {
if ('_other' === $slugChoice && $cfType->isChecked($cf, $choiceSlug, $decoded)) {
return $cfType->extractOtherValue($cf, $decoded);
}

View File

@ -64,8 +64,8 @@ class AccompanyingPeriodType extends AbstractType
if (
('close' === $options['period_action'])
or ('create' === $options['period_action'])
or ('update' === $options['period_action'] and !$accompanyingPeriod->isOpen())
|| ('create' === $options['period_action'])
|| ('update' === $options['period_action'] && !$accompanyingPeriod->isOpen())
) {
$builder->add('closingDate', DateType::class, [
'required' => true,

View File

@ -226,8 +226,8 @@ class PersonControllerUpdateTest extends WebTestCase
'a element .success is shown'
);
if ('birthdate' == $field or 'memo' == $field or 'countryOfBirth' == $field or 'nationality' == $field
or 'gender' == $field) {
if ('birthdate' == $field || 'memo' == $field || 'countryOfBirth' == $field || 'nationality' == $field
|| 'gender' == $field) {
// we do not perform test on the web page contents.
} else {
$this->assertGreaterThan(0, $crawler->filter('html:contains("' . $value . '")')->count());

View File

@ -160,8 +160,8 @@ class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
'a element .success is shown'
);
if ('birthdate' == $field or 'memo' == $field or 'countryOfBirth' == $field or 'nationality' == $field
or 'gender' == $field) {
if ('birthdate' == $field || 'memo' == $field || 'countryOfBirth' == $field || 'nationality' == $field
|| 'gender' == $field) {
// we do not perform test on the web page contents.
} else {
$this->assertGreaterThan(0, $crawler->filter('html:contains("' . $value . '")')->count());

View File

@ -36,7 +36,7 @@ class Version20160422000000 extends AbstractMigration
}
$this->abortIf(
sizeof($personWithTwoAddressWithSameValidFrom) != 0,
count($personWithTwoAddressWithSameValidFrom) != 0,
'There exists some person with multiple adress with the same validFrom'
);
}

View File

@ -64,7 +64,7 @@ class LoadCustomField extends AbstractFixture implements OrderedFixtureInterface
];
for ($i = 0; 25 >= $i; ++$i) {
$cFType = $cFTypes[rand(0, sizeof($cFTypes) - 1)];
$cFType = $cFTypes[rand(0, count($cFTypes) - 1)];
$customField = (new CustomField())
->setSlug("cf_report_{$i}")

View File

@ -417,7 +417,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
$cfType = $this->customFieldProvider->getCustomFieldByType($cf->getType());
// if is multiple, split into multiple columns
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
if ($cfType instanceof CustomFieldChoice && $cfType->isMultiple($cf)) {
foreach ($cfType->getChoices($cf) as $choiceSlug => $label) {
$slug = $this->slugToDQL($cf->getSlug(), 'choice', ['choiceSlug' => $choiceSlug]);
$qb->addSelect(
@ -525,7 +525,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
->render(json_decode($value, true), $cf, 'csv');
};
if ($cfType instanceof CustomFieldChoice and $cfType->isMultiple($cf)) {
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);
@ -537,7 +537,7 @@ class ReportList implements ListInterface, ExportElementValidatedInterface
. ' | ' . $label;
}
if ('_other' === $slugChoice and $cfType->isChecked($cf, $choiceSlug, $decoded)) {
if ('_other' === $slugChoice && $cfType->isChecked($cf, $choiceSlug, $decoded)) {
return $cfType->extractOtherValue($cf, $decoded);
}

View File

@ -187,7 +187,7 @@ class SingleTaskRepository extends EntityRepository
$this->buildACLQuery($qb, $currentUser);
}
if (array_key_exists('person', $params) and !empty($params['person'])) {
if (array_key_exists('person', $params) && !empty($params['person'])) {
$qb->andWhere($qb->expr()->eq('st.person', ':person'));
$qb->setParameter('person', $params['person']);
} elseif (array_key_exists('center', $params)) {
@ -200,8 +200,8 @@ class SingleTaskRepository extends EntityRepository
}
}
if (array_key_exists('unassigned', $params) and true === $params['unassigned']) {
if (array_key_exists('user', $params) and !empty($params['user'])) {
if (array_key_exists('unassigned', $params) && true === $params['unassigned']) {
if (array_key_exists('user', $params) && !empty($params['user'])) {
throw new UnexpectedValueException('You should not require for '
. 'unassigned tasks and tasks assigned to some user.');
}
@ -209,12 +209,12 @@ class SingleTaskRepository extends EntityRepository
$qb->andWhere($qb->expr()->isNull('st.assignee'));
}
if (array_key_exists('user', $params) and !empty($params['user'])) {
if (array_key_exists('user', $params) && !empty($params['user'])) {
$qb->andWhere($qb->expr()->eq('st.assignee', ':user'));
$qb->setParameter('user', $params['user']);
}
if (array_key_exists('scope', $params) and !empty($params['scope'])) {
if (array_key_exists('scope', $params) && !empty($params['scope'])) {
$qb->andWhere($qb->expr()->eq('st.circle', ':scope'));
$qb->setParameter('scope', $params['scope']);
}
@ -226,7 +226,7 @@ class SingleTaskRepository extends EntityRepository
}
}
if (array_key_exists('date_status', $params) and !empty($params['date_status'])) {
if (array_key_exists('date_status', $params) && !empty($params['date_status'])) {
$this->addTypeFilter($qb, $params);
}

View File

@ -97,7 +97,7 @@ class ThirdPartySearch implements SearchInterface
public function supports($domain, $format): bool
{
return self::NAME === $domain and 'json' === $format;
return self::NAME === $domain && 'json' === $format;
}
protected function count($centers, $terms): int