@@ -60,6 +60,27 @@ class TypeProcessor
60
60
*/
61
61
protected $ _types = [];
62
62
63
+ /**
64
+ * @var NameFinder
65
+ */
66
+ private $ nameFinder ;
67
+
68
+ /**
69
+ * The getter function to get the new NameFinder dependency
70
+ *
71
+ * @return NameFinder
72
+ *
73
+ * @deprecated
74
+ */
75
+ private function getNameFinder ()
76
+ {
77
+ if ($ this ->nameFinder === null ) {
78
+ $ this ->nameFinder = \Magento \Framework \App \ObjectManager::getInstance ()
79
+ ->get ('\Magento\Framework\Reflection\NameFinder ' );
80
+ }
81
+ return $ this ->nameFinder ;
82
+ }
83
+
63
84
/**
64
85
* Retrieve processed types data.
65
86
*
@@ -195,11 +216,11 @@ protected function _processMethod(\Zend\Code\Reflection\MethodReflection $method
195
216
/** Field will not be added to WSDL if getter has params */
196
217
if ($ isGetter && !$ methodReflection ->getNumberOfRequiredParameters ()) {
197
218
$ returnMetadata = $ this ->getGetterReturnType ($ methodReflection );
198
- $ fieldName = $ this ->dataObjectGetterNameToFieldName ($ methodReflection ->getName ());
219
+ $ fieldName = $ this ->getNameFinder ()-> dataObjectGetterNameToFieldName ($ methodReflection ->getName ());
199
220
if ($ returnMetadata ['description ' ]) {
200
221
$ description = $ returnMetadata ['description ' ];
201
222
} else {
202
- $ description = $ this ->dataObjectGetterDescriptionToFieldDescription (
223
+ $ description = $ this ->getNameFinder ()-> dataObjectGetterDescriptionToFieldDescription (
203
224
$ methodReflection ->getDocBlock ()->getShortDescription ()
204
225
);
205
226
}
@@ -237,33 +258,25 @@ public function getDescription(\Zend\Code\Reflection\DocBlockReflection $doc)
237
258
*
238
259
* @param string $getterName
239
260
* @return string
261
+ *
262
+ * @deprecated
240
263
*/
241
264
public function dataObjectGetterNameToFieldName ($ getterName )
242
265
{
243
- if ((strpos ($ getterName , 'get ' ) === 0 )) {
244
- /** Remove 'get' prefix and make the first letter lower case */
245
- $ fieldName = substr ($ getterName , strlen ('get ' ));
246
- } elseif ((strpos ($ getterName , 'is ' ) === 0 )) {
247
- /** Remove 'is' prefix and make the first letter lower case */
248
- $ fieldName = substr ($ getterName , strlen ('is ' ));
249
- } elseif ((strpos ($ getterName , 'has ' ) === 0 )) {
250
- /** Remove 'has' prefix and make the first letter lower case */
251
- $ fieldName = substr ($ getterName , strlen ('has ' ));
252
- } else {
253
- $ fieldName = $ getterName ;
254
- }
255
- return lcfirst ($ fieldName );
266
+ return $ this ->getNameFinder ()->dataObjectGetterNameToFieldName ($ getterName );
256
267
}
257
268
258
269
/**
259
270
* Convert Data Object getter short description into field description.
260
271
*
261
272
* @param string $shortDescription
262
273
* @return string
274
+ *
275
+ * @deprecated
263
276
*/
264
277
protected function dataObjectGetterDescriptionToFieldDescription ($ shortDescription )
265
278
{
266
- return ucfirst ( substr ( strstr ( $ shortDescription, " " ), 1 ) );
279
+ return $ this -> getNameFinder ()-> dataObjectGetterDescriptionToFieldDescription ( $ shortDescription );
267
280
}
268
281
269
282
/**
@@ -578,12 +591,12 @@ public function getParamDescription(ParameterReflection $param)
578
591
* @param string $camelCaseProperty
579
592
* @return string processed method name
580
593
* @throws \Exception If $camelCaseProperty has no corresponding getter method
594
+ *
595
+ * @deprecated
581
596
*/
582
597
public function findGetterMethodName (ClassReflection $ class , $ camelCaseProperty )
583
598
{
584
- $ getterName = 'get ' . $ camelCaseProperty ;
585
- $ boolGetterName = 'is ' . $ camelCaseProperty ;
586
- return $ this ->findAccessorMethodName ($ class , $ camelCaseProperty , $ getterName , $ boolGetterName );
599
+ return $ this ->getNameFinder ()->findGetterMethodName ($ class , $ camelCaseProperty );
587
600
}
588
601
589
602
/**
@@ -614,12 +627,12 @@ protected function setType(&$value, $type)
614
627
* @param string $camelCaseProperty
615
628
* @return string processed method name
616
629
* @throws \Exception If $camelCaseProperty has no corresponding setter method
630
+ *
631
+ * @deprecated
617
632
*/
618
633
public function findSetterMethodName (ClassReflection $ class , $ camelCaseProperty )
619
634
{
620
- $ setterName = 'set ' . $ camelCaseProperty ;
621
- $ boolSetterName = 'setIs ' . $ camelCaseProperty ;
622
- return $ this ->findAccessorMethodName ($ class , $ camelCaseProperty , $ setterName , $ boolSetterName );
635
+ return $ this ->getNameFinder ()->findSetterMethodName ($ class , $ camelCaseProperty );
623
636
}
624
637
625
638
/**
@@ -631,28 +644,17 @@ public function findSetterMethodName(ClassReflection $class, $camelCaseProperty)
631
644
* @param bool $boolAccessorName
632
645
* @return string processed method name
633
646
* @throws \Exception If $camelCaseProperty has no corresponding setter method
647
+ *
648
+ * @deprecated
634
649
*/
635
650
protected function findAccessorMethodName (
636
651
ClassReflection $ class ,
637
652
$ camelCaseProperty ,
638
653
$ accessorName ,
639
654
$ boolAccessorName
640
655
) {
641
- if ($ this ->classHasMethod ($ class , $ accessorName )) {
642
- $ methodName = $ accessorName ;
643
- return $ methodName ;
644
- } elseif ($ this ->classHasMethod ($ class , $ boolAccessorName )) {
645
- $ methodName = $ boolAccessorName ;
646
- return $ methodName ;
647
- } else {
648
- throw new \LogicException (
649
- sprintf (
650
- 'Property "%s" does not have corresponding setter in class "%s". ' ,
651
- $ camelCaseProperty ,
652
- $ class ->getName ()
653
- )
654
- );
655
- }
656
+ return $ this ->getNameFinder ()
657
+ ->findAccessorMethodName ($ class , $ camelCaseProperty , $ accessorName , $ boolAccessorName );
656
658
}
657
659
658
660
/**
@@ -663,10 +665,12 @@ protected function findAccessorMethodName(
663
665
* @param ClassReflection $class
664
666
* @param string $methodName
665
667
* @return bool
668
+ *
669
+ * @deprecated
666
670
*/
667
671
protected function classHasMethod (ClassReflection $ class , $ methodName )
668
672
{
669
- return $ class -> hasMethod ( $ methodName ) && ( $ class -> getMethod ( $ methodName )-> getName () == $ methodName );
673
+ return $ this -> getNameFinder ()-> classHasMethod ( $ class , $ methodName );
670
674
}
671
675
672
676
/**
0 commit comments