DX: more code style fixes

This commit is contained in:
Julien Fastré 2022-11-02 14:06:10 +01:00
parent 5655f953d7
commit 055acbf43c
21 changed files with 131 additions and 47 deletions

View File

@ -369,8 +369,12 @@ final class ActivityControllerTest extends WebTestCase
$center $center
); );
$reachableScopesId = array_intersect( $reachableScopesId = array_intersect(
array_map(static function ($s) { return $s->getId(); }, $reachableScopesDelete), array_map(static function ($s) {
array_map(static function ($s) { return $s->getId(); }, $reachableScopesUpdate) return $s->getId();
}, $reachableScopesDelete),
array_map(static function ($s) {
return $s->getId();
}, $reachableScopesUpdate)
); );
if (count($reachableScopesId) === 0) { if (count($reachableScopesId) === 0) {

View File

@ -188,7 +188,9 @@ final class ActivityTypeTest extends KernelTestCase
// map all the values in an array // map all the values in an array
$values = array_map( $values = array_map(
static function ($choice) { return $choice->value; }, static function ($choice) {
return $choice->value;
},
$view['activity']['durationTime']->vars['choices'] $view['activity']['durationTime']->vars['choices']
); );

View File

@ -31,7 +31,9 @@ class ConfigRepository
public function getChargesKeys(bool $onlyActive = false): array public function getChargesKeys(bool $onlyActive = false): array
{ {
return array_map(static function ($element) { return $element['key']; }, $this->getCharges($onlyActive)); return array_map(static function ($element) {
return $element['key'];
}, $this->getCharges($onlyActive));
} }
/** /**
@ -50,7 +52,9 @@ class ConfigRepository
public function getResourcesKeys(bool $onlyActive = false): array public function getResourcesKeys(bool $onlyActive = false): array
{ {
return array_map(static function ($element) { return $element['key']; }, $this->getResources($onlyActive)); return array_map(static function ($element) {
return $element['key'];
}, $this->getResources($onlyActive));
} }
/** /**
@ -70,14 +74,18 @@ class ConfigRepository
private function getCharges(bool $onlyActive = false): array private function getCharges(bool $onlyActive = false): array
{ {
return $onlyActive ? return $onlyActive ?
array_filter($this->charges, static function ($el) { return $el['active']; }) array_filter($this->charges, static function ($el) {
return $el['active'];
})
: $this->charges; : $this->charges;
} }
private function getResources(bool $onlyActive = false): array private function getResources(bool $onlyActive = false): array
{ {
return $onlyActive ? return $onlyActive ?
array_filter($this->resources, static function ($el) { return $el['active']; }) array_filter($this->resources, static function ($el) {
return $el['active'];
})
: $this->resources; : $this->resources;
} }

View File

@ -61,7 +61,9 @@ class SummaryBudget implements SummaryBudgetInterface
]; ];
} }
$personIds = $household->getCurrentPersons()->map(static function (Person $p) { return $p->getId(); }); $personIds = $household->getCurrentPersons()->map(static function (Person $p) {
return $p->getId();
});
$ids = implode(', ', array_fill(0, count($personIds), '?')); $ids = implode(', ', array_fill(0, count($personIds), '?'));
$parameters = [...$personIds, $household->getId()]; $parameters = [...$personIds, $household->getId()];

View File

@ -239,7 +239,9 @@ final class ParticipationControllerTest extends WebTestCase
$this->personsIdsCache = array_merge( $this->personsIdsCache = array_merge(
$this->personsIdsCache, $this->personsIdsCache,
$event->getParticipations()->map( $event->getParticipations()->map(
static function ($p) { return $p->getPerson()->getId(); } static function ($p) {
return $p->getPerson()->getId();
}
) )
->toArray() ->toArray()
); );
@ -303,7 +305,9 @@ final class ParticipationControllerTest extends WebTestCase
$event = $this->getRandomEventWithMultipleParticipations(); $event = $this->getRandomEventWithMultipleParticipations();
$persons_id = implode(',', $event->getParticipations()->map( $persons_id = implode(',', $event->getParticipations()->map(
static function ($p) { return $p->getPerson()->getId(); } static function ($p) {
return $p->getPerson()->getId();
}
)->toArray()); )->toArray());
$crawler = $this->client->request( $crawler = $this->client->request(
@ -329,7 +333,9 @@ final class ParticipationControllerTest extends WebTestCase
$nbParticipations = $event->getParticipations()->count(); $nbParticipations = $event->getParticipations()->count();
// get the persons_id participating on this event // get the persons_id participating on this event
$persons_id = $event->getParticipations()->map( $persons_id = $event->getParticipations()->map(
static function ($p) { return $p->getPerson()->getId(); } static function ($p) {
return $p->getPerson()->getId();
}
)->toArray(); )->toArray();
// exclude the existing persons_ids from the new person // exclude the existing persons_ids from the new person
$this->personsIdsCache = array_merge($this->personsIdsCache, $persons_id); $this->personsIdsCache = array_merge($this->personsIdsCache, $persons_id);

View File

@ -177,7 +177,9 @@ class ExportAddressHelper
$prefixes = array_merge( $prefixes = array_merge(
$prefixes, $prefixes,
array_map( array_map(
static function ($item) use ($prefix) { return $prefix . $item; }, static function ($item) use ($prefix) {
return $prefix . $item;
},
self::COLUMN_MAPPING[$key] self::COLUMN_MAPPING[$key]
) )
); );

View File

@ -51,7 +51,9 @@ class EntityToJsonTransformer implements DataTransformerInterface
} }
return array_map( return array_map(
function ($item) { return $this->denormalizeOne($item); }, function ($item) {
return $this->denormalizeOne($item);
},
$denormalized $denormalized
); );
} }

View File

@ -66,7 +66,9 @@ class ScopePickerType extends AbstractType
$options['role'] instanceof Role ? $options['role']->getRole() : $options['role'], $options['role'] instanceof Role ? $options['role']->getRole() : $options['role'],
$options['center'] $options['center']
), ),
static function (Scope $s) { return $s->isActive(); } static function (Scope $s) {
return $s->isActive();
}
); );
if (0 === count($items)) { if (0 === count($items)) {

View File

@ -134,7 +134,9 @@ final class NotificationTest extends KernelTestCase
$this->assertEquals($senderId, $notification->getSender()->getId()); $this->assertEquals($senderId, $notification->getSender()->getId());
$this->assertCount(count($addressesIds), $notification->getUnreadBy()); $this->assertCount(count($addressesIds), $notification->getUnreadBy());
$unreadIds = $notification->getUnreadBy()->map(static function (User $u) { return $u->getId(); }); $unreadIds = $notification->getUnreadBy()->map(static function (User $u) {
return $u->getId();
});
foreach ($addressesIds as $addresseeId) { foreach ($addressesIds as $addresseeId) {
$this->assertContains($addresseeId, $unreadIds); $this->assertContains($addresseeId, $unreadIds);

View File

@ -96,7 +96,9 @@ final class ScopePickerTypeTest extends TypeTestCase
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class); $translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
$translatableStringHelper->localize(Argument::type('array'))->will( $translatableStringHelper->localize(Argument::type('array'))->will(
static function ($args) { return $args[0]['fr']; } static function ($args) {
return $args[0]['fr'];
}
); );
$type = new ScopePickerType( $type = new ScopePickerType(

View File

@ -211,7 +211,9 @@ final class AuthorizationHelperTest extends KernelTestCase
$centerA $centerA
); );
$usernames = array_map(static function (User $u) { return $u->getUsername(); }, $users); $usernames = array_map(static function (User $u) {
return $u->getUsername();
}, $users);
$this->assertContains('center a_social', $usernames); $this->assertContains('center a_social', $usernames);
} }

View File

@ -33,7 +33,7 @@ final class DefaultScopeResolverTest extends TestCase
public function testHasScopeInterface() public function testHasScopeInterface()
{ {
$scope = new Scope(); $scope = new Scope();
$entity = new class($scope) implements HasScopeInterface { $entity = new class ($scope) implements HasScopeInterface {
public function __construct(Scope $scope) public function __construct(Scope $scope)
{ {
$this->scope = $scope; $this->scope = $scope;
@ -52,7 +52,7 @@ final class DefaultScopeResolverTest extends TestCase
public function testHasScopesInterface() public function testHasScopesInterface()
{ {
$entity = new class($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface { $entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface {
public function __construct(Scope $scopeA, Scope $scopeB) public function __construct(Scope $scopeA, Scope $scopeB)
{ {
$this->scopes = [$scopeA, $scopeB]; $this->scopes = [$scopeA, $scopeB];

View File

@ -34,7 +34,7 @@ final class ScopeResolverDispatcherTest extends TestCase
public function testHasScopeInterface() public function testHasScopeInterface()
{ {
$scope = new Scope(); $scope = new Scope();
$entity = new class($scope) implements HasScopeInterface { $entity = new class ($scope) implements HasScopeInterface {
public function __construct(Scope $scope) public function __construct(Scope $scope)
{ {
$this->scope = $scope; $this->scope = $scope;
@ -52,7 +52,7 @@ final class ScopeResolverDispatcherTest extends TestCase
public function testHasScopesInterface() public function testHasScopesInterface()
{ {
$entity = new class($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface { $entity = new class ($scopeA = new Scope(), $scopeB = new Scope()) implements HasScopesInterface {
public function __construct(Scope $scopeA, Scope $scopeB) public function __construct(Scope $scopeA, Scope $scopeB)
{ {
$this->scopes = [$scopeA, $scopeB]; $this->scopes = [$scopeA, $scopeB];

View File

@ -107,7 +107,9 @@ class NotificationOnTransition implements EventSubscriberInterface
'dest' => $subscriber, 'dest' => $subscriber,
'place' => $place, 'place' => $place,
'workflow' => $workflow, 'workflow' => $workflow,
'is_dest' => in_array($subscriber->getId(), array_map(static function (User $u) { return $u->getId(); }, $entityWorkflow->futureDestUsers), true), 'is_dest' => in_array($subscriber->getId(), array_map(static function (User $u) {
return $u->getId();
}, $entityWorkflow->futureDestUsers), true),
]; ];
$notification = new Notification(); $notification = new Notification();

View File

@ -114,7 +114,7 @@ final class AccompanyingPeriodSocialIssueConsistencyEntityListenerTest extends T
protected function generateClass(AccompanyingPeriod $period, Collection $socialIssues): AccompanyingPeriodLinkedWithSocialIssuesEntityInterface protected function generateClass(AccompanyingPeriod $period, Collection $socialIssues): AccompanyingPeriodLinkedWithSocialIssuesEntityInterface
{ {
return new class($period, $socialIssues) implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface { return new class ($period, $socialIssues) implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface {
public Collection $socialIssues; public Collection $socialIssues;
public AccompanyingPeriod $period; public AccompanyingPeriod $period;

View File

@ -342,7 +342,9 @@ final class AccompanyingCourseApiControllerTest extends WebTestCase
// check that the person id is contained // check that the person id is contained
$participationsPersonsIds = array_map( $participationsPersonsIds = array_map(
static function ($participation) { return $participation->person->id; }, static function ($participation) {
return $participation->person->id;
},
$data->participations $data->participations
); );

View File

@ -294,23 +294,49 @@ final class PersonControllerUpdateTest extends WebTestCase
public function validTextFieldsProvider() public function validTextFieldsProvider()
{ {
return [ return [
['firstName', 'random Value', static function (Person $person) { return $person->getFirstName(); }], ['firstName', 'random Value', static function (Person $person) {
['lastName', 'random Value', static function (Person $person) { return $person->getLastName(); }], return $person->getFirstName();
}],
['lastName', 'random Value', static function (Person $person) {
return $person->getLastName();
}],
// reminder: this value is capitalized // reminder: this value is capitalized
['placeOfBirth', 'A PLACE', static function (Person $person) { return $person->getPlaceOfBirth(); }], ['placeOfBirth', 'A PLACE', static function (Person $person) {
['birthdate', '1980-12-15', static function (Person $person) { return $person->getBirthdate()->format('Y-m-d'); }], return $person->getPlaceOfBirth();
}],
['birthdate', '1980-12-15', static function (Person $person) {
return $person->getBirthdate()->format('Y-m-d');
}],
// TODO test on phonenumber update // TODO test on phonenumber update
// ['phonenumber', '+32123456789', static function (Person $person) { return $person->getPhonenumber(); }], // ['phonenumber', '+32123456789', static function (Person $person) { return $person->getPhonenumber(); }],
['memo', 'jfkdlmq jkfldmsq jkmfdsq', static function (Person $person) { return $person->getMemo(); }], ['memo', 'jfkdlmq jkfldmsq jkmfdsq', static function (Person $person) {
['countryOfBirth', 'BE', static function (Person $person) { return $person->getCountryOfBirth()->getCountryCode(); }], return $person->getMemo();
['nationality', 'FR', static function (Person $person) { return $person->getNationality()->getCountryCode(); }], }],
['placeOfBirth', '', static function (Person $person) { return $person->getPlaceOfBirth(); }], ['countryOfBirth', 'BE', static function (Person $person) {
['birthdate', '', static function (Person $person) { return $person->getBirthdate(); }], return $person->getCountryOfBirth()->getCountryCode();
}],
['nationality', 'FR', static function (Person $person) {
return $person->getNationality()->getCountryCode();
}],
['placeOfBirth', '', static function (Person $person) {
return $person->getPlaceOfBirth();
}],
['birthdate', '', static function (Person $person) {
return $person->getBirthdate();
}],
//['phonenumber', '', static function (Person $person) { return $person->getPhonenumber(); }], //['phonenumber', '', static function (Person $person) { return $person->getPhonenumber(); }],
['memo', '', static function (Person $person) { return $person->getMemo(); }], ['memo', '', static function (Person $person) {
['countryOfBirth', null, static function (Person $person) { return $person->getCountryOfBirth(); }], return $person->getMemo();
['nationality', null, static function (Person $person) { return $person->getNationality(); }], }],
['gender', Person::FEMALE_GENDER, static function (Person $person) { return $person->getGender(); }], ['countryOfBirth', null, static function (Person $person) {
return $person->getCountryOfBirth();
}],
['nationality', null, static function (Person $person) {
return $person->getNationality();
}],
['gender', Person::FEMALE_GENDER, static function (Person $person) {
return $person->getGender();
}],
]; ];
} }

View File

@ -197,12 +197,24 @@ final class PersonControllerUpdateWithHiddenFieldsTest extends WebTestCase
public function validTextFieldsProvider() public function validTextFieldsProvider()
{ {
return [ return [
['firstName', 'random Value', static function (Person $person) { return $person->getFirstName(); }], ['firstName', 'random Value', static function (Person $person) {
['lastName', 'random Value', static function (Person $person) { return $person->getLastName(); }], return $person->getFirstName();
['birthdate', '15-12-1980', static function (Person $person) { return $person->getBirthdate()->format('d-m-Y'); }], }],
['memo', 'jfkdlmq jkfldmsq jkmfdsq', static function (Person $person) { return $person->getMemo(); }], ['lastName', 'random Value', static function (Person $person) {
['birthdate', '', static function (Person $person) { return $person->getBirthdate(); }], return $person->getLastName();
['gender', Person::FEMALE_GENDER, static function (Person $person) { return $person->getGender(); }], }],
['birthdate', '15-12-1980', static function (Person $person) {
return $person->getBirthdate()->format('d-m-Y');
}],
['memo', 'jfkdlmq jkfldmsq jkmfdsq', static function (Person $person) {
return $person->getMemo();
}],
['birthdate', '', static function (Person $person) {
return $person->getBirthdate();
}],
['gender', Person::FEMALE_GENDER, static function (Person $person) {
return $person->getGender();
}],
]; ];
} }

View File

@ -111,7 +111,9 @@ final class MembersEditorTest extends TestCase
$this->assertCount(1, $notSharing); $this->assertCount(1, $notSharing);
$this->assertCount(1, $sharings); $this->assertCount(1, $sharings);
$getPerson = static function (HouseholdMember $m) { return $m->getPerson(); }; $getPerson = static function (HouseholdMember $m) {
return $m->getPerson();
};
$this->assertContains($person, $notSharing->map($getPerson)); $this->assertContains($person, $notSharing->map($getPerson));
} }
@ -151,7 +153,9 @@ final class MembersEditorTest extends TestCase
$this->assertCount(1, $notSharing); $this->assertCount(1, $notSharing);
$this->assertCount(0, $sharings); $this->assertCount(0, $sharings);
$getPerson = static function (HouseholdMember $m) { return $m->getPerson(); }; $getPerson = static function (HouseholdMember $m) {
return $m->getPerson();
};
$this->assertContains($person, $notSharing->map($getPerson)); $this->assertContains($person, $notSharing->map($getPerson));
} }

View File

@ -118,7 +118,9 @@ final class RelationshipDocGenNormalizerTest extends TestCase
{ {
$translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class); $translatableStringHelper = $this->prophesize(TranslatableStringHelperInterface::class);
$translatableStringHelper->localize(Argument::type('array'))->will( $translatableStringHelper->localize(Argument::type('array'))->will(
static function ($args) { return $args[0][array_keys($args[0])[0]]; } static function ($args) {
return $args[0][array_keys($args[0])[0]];
}
); );
$normalizer = new RelationshipDocGenNormalizer( $normalizer = new RelationshipDocGenNormalizer(

View File

@ -67,7 +67,9 @@ final class TimelineProviderTest extends WebTestCase
self::$em self::$em
->getRepository(\Chill\MainBundle\Entity\Scope::class) ->getRepository(\Chill\MainBundle\Entity\Scope::class)
->findAll(), ->findAll(),
static function (Scope $scope) { return $scope->getName()['en'] === 'social'; } static function (Scope $scope) {
return $scope->getName()['en'] === 'social';
}
); );
$report = (new Report()) $report = (new Report())