1 | <?php |
||
19 | class BandService extends EntityService |
||
20 | { |
||
21 | const ATTRIBUTE_MEMBERS = 'members'; |
||
22 | const CREATOR_DEFAULT_MEMBER_SHORT_DESCRIPTION = 'Founder'; |
||
23 | |||
24 | /** @var BandRepository */ |
||
25 | private $bandRepository; |
||
26 | |||
27 | /** @var BandMemberRepository */ |
||
28 | private $bandMemberRepository; |
||
29 | |||
30 | /** @var UserRepository */ |
||
31 | private $userRepository; |
||
32 | |||
33 | 19 | public function __construct( |
|
42 | |||
43 | 2 | public function processFormAndUpdateBand(FormInterface $form, Band $band, User $creator): FormInterface |
|
47 | |||
48 | /** |
||
49 | * Create or update band. If no Band object passed, new one will be created |
||
50 | */ |
||
51 | 2 | private function createOrUpdateBand(FormInterface $form, User $creator, Band $band = null): FormInterface |
|
58 | |||
59 | 2 | private function createOrUpdateBandUsingForm( |
|
60 | FormInterface $form, |
||
61 | User $creator, |
||
62 | Band $band = null |
||
63 | ) { |
||
64 | 2 | if (!$form->isValid()) { |
|
65 | 1 | return null; |
|
66 | } |
||
67 | |||
68 | 1 | $membersData = $form->get(self::ATTRIBUTE_MEMBERS)->getData(); |
|
69 | |||
70 | 1 | if (!$membersData) { |
|
71 | $form->addError(new FormError(sprintf('Parameter "%s" is mandatory.', self::ATTRIBUTE_MEMBERS))); |
||
72 | |||
73 | return null; |
||
74 | } |
||
75 | |||
76 | 1 | $bandNewName = $form->get('name')->getData(); |
|
77 | 1 | $description = $form->get('description')->getData(); |
|
78 | |||
79 | 1 | if ($this->bandRepository->findOneByName($bandNewName)) { |
|
80 | $form->addError(new FormError(sprintf('Band with name "%s" already exists.', $bandNewName))); |
||
81 | |||
82 | return null; |
||
83 | } |
||
84 | |||
85 | 1 | if ($band) { |
|
86 | 1 | $band->setName($bandNewName); |
|
87 | 1 | $band->setDescription($description); |
|
88 | } else { |
||
89 | $band = new Band($bandNewName, $creator, $description); |
||
90 | $this->bandRepository->persist($band); |
||
91 | } |
||
92 | |||
93 | 1 | $bandMembers = $this->getBandMembersFromForm($band, $form); |
|
94 | 1 | $bandMembers[] = $this->createAmbassadorMemberFromCreator($band, $creator); |
|
95 | |||
96 | 1 | foreach ($bandMembers as $bandMember) { |
|
97 | 1 | $band->addMember($bandMember); |
|
98 | } |
||
99 | 1 | } |
|
100 | |||
101 | /** |
||
102 | * @return BandMember[] |
||
103 | */ |
||
104 | 1 | private function getBandMembersFromForm(Band $band, FormInterface $form): array |
|
130 | |||
131 | 1 | public function processFormAndUpdateBandMember(FormInterface $form, BandMember $bandMember): FormInterface |
|
146 | |||
147 | 4 | public function createAmbassadorMemberFromCreator(Ambassador $ambassador, User $creator): AmbassadorMember |
|
155 | } |
||
156 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: