1 | <?php |
||
22 | class LeadToOpportunityProvider |
||
23 | { |
||
24 | /** |
||
25 | * @var PropertyAccessor |
||
26 | */ |
||
27 | protected $accessor; |
||
28 | |||
29 | /** |
||
30 | * @var B2bGuesser |
||
31 | */ |
||
32 | protected $b2bGuesser; |
||
33 | |||
34 | /** |
||
35 | * @var ChangeLeadStatus |
||
36 | */ |
||
37 | protected $changeLeadStatus; |
||
38 | |||
39 | /** @var bool */ |
||
40 | protected $isLeadWorkflowEnabled; |
||
41 | |||
42 | /** |
||
43 | * @var EntityFieldProvider |
||
44 | */ |
||
45 | protected $entityFieldProvider; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $addressFields = [ |
||
51 | 'properties' => [ |
||
52 | 'firstName' => 'firstName', |
||
53 | 'lastName' => 'lastName', |
||
54 | 'middleName' => 'middleName', |
||
55 | 'namePrefix' => 'namePrefix', |
||
56 | 'nameSuffix' => 'nameSuffix', |
||
57 | 'city' => 'city', |
||
58 | 'country' => 'country', |
||
59 | 'label' => 'label', |
||
60 | 'organization' => 'organization', |
||
61 | 'postalCode' => 'postalCode', |
||
62 | 'region' => 'region', |
||
63 | 'regionText' => 'regionText', |
||
64 | 'street' => 'street', |
||
65 | 'street2' => 'street2', |
||
66 | 'primary' => 'primary' |
||
67 | ] |
||
68 | ]; |
||
69 | |||
70 | /** |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $contactFields = [ |
||
74 | 'properties' => [ |
||
75 | 'firstName' => 'firstName', |
||
76 | 'jobTitle' => 'jobTitle', |
||
77 | 'lastName' => 'lastName', |
||
78 | 'middleName' => 'middleName', |
||
79 | 'namePrefix' => 'namePrefix', |
||
80 | 'nameSuffix' => 'nameSuffix', |
||
81 | 'twitter' => 'twitter', |
||
82 | 'linkedIn' => 'linkedIn', |
||
83 | 'owner' => 'owner', |
||
84 | 'source' => 'source' |
||
85 | ], |
||
86 | 'extended_properties' => [ |
||
87 | 'source' => 'enum' |
||
88 | ] |
||
89 | ]; |
||
90 | |||
91 | /** |
||
92 | * @param B2bGuesser $b2bGuesser |
||
93 | * @param EntityFieldProvider $entityFieldProvider |
||
94 | * @param ChangeLeadStatus $changeLeadStatus |
||
95 | * @param WorkflowRegistry $workflowRegistry |
||
96 | */ |
||
97 | public function __construct( |
||
111 | |||
112 | /** |
||
113 | * @return array |
||
114 | */ |
||
115 | protected function prepareEntityFields() |
||
133 | |||
134 | protected function validateContactFields() |
||
148 | |||
149 | /** |
||
150 | * @param object $filledEntity |
||
151 | * @param array $properties |
||
152 | * @param object $sourceEntity |
||
153 | */ |
||
154 | protected function fillEntityProperties($filledEntity, array $properties, $sourceEntity) |
||
163 | |||
164 | /** |
||
165 | * @param Lead $lead |
||
166 | * |
||
167 | * @return Contact |
||
168 | */ |
||
169 | protected function prepareContactToOpportunity(Lead $lead) |
||
211 | |||
212 | /** |
||
213 | * @param Lead $lead |
||
214 | * @param bool $isGetRequest |
||
215 | * |
||
216 | * @return Opportunity |
||
217 | */ |
||
218 | public function prepareOpportunityForForm(Lead $lead, $isGetRequest = true) |
||
240 | |||
241 | /** |
||
242 | * @param Opportunity $opportunity |
||
243 | * @param callable $errorMessageCallback |
||
244 | * |
||
245 | * @return bool |
||
246 | */ |
||
247 | public function saveOpportunity(Opportunity $opportunity, callable $errorMessageCallback) |
||
263 | |||
264 | /** |
||
265 | * @param B2bCustomer $customer |
||
266 | * @param Opportunity $opportunity |
||
267 | */ |
||
268 | protected function prepareCustomerToSave(B2bCustomer $customer, Opportunity $opportunity) |
||
279 | |||
280 | /** |
||
281 | * @param Lead $lead |
||
282 | * @param Opportunity $opportunity |
||
283 | */ |
||
284 | protected function setContactAndAccountToLeadFromOpportunity(Lead $lead, Opportunity $opportunity) |
||
289 | |||
290 | /** |
||
291 | * @param Lead $lead |
||
292 | * |
||
293 | * @return bool |
||
294 | */ |
||
295 | public function isDisqualifyAndConvertAllowed(Lead $lead) |
||
301 | } |
||
302 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: