@@ -30,17 +30,10 @@ class ClassNode
3030 */
3131 private $ interfaces = array ();
3232
33- /**
34- * @var array<string, string>
35- *
36- * @phpstan-var array<string, 'public'|'private'|'protected'>
37- */
38- private $ properties = array ();
39-
4033 /**
4134 * @var array<string, PropertyNode>
4235 */
43- private $ propertyNodes = array () ;
36+ private $ properties = [] ;
4437
4538 /**
4639 * @var list<string>
@@ -111,30 +104,49 @@ public function hasInterface($interface)
111104 * @return array<string, string>
112105 *
113106 * @phpstan-return array<string, 'public'|'private'|'protected'>
107+ *
108+ * @deprecated
114109 */
115110 public function getProperties ()
116111 {
117- return $ this ->properties ;
112+ trigger_deprecation (
113+ 'phpspec/prophecy ' ,
114+ '1.24 ' ,
115+ 'Use getPropertyNodes() instead. It allows you to retrieve the type as well as visibility. '
116+ );
117+
118+ $ propertiesOldFormat = array_map (function ($ property ) {
119+ return $ property ->getVisibility ();
120+ }, $ this ->properties );
121+
122+ return $ propertiesOldFormat ;
118123 }
119124
120125 /**
121126 * @return array<string, PropertyNode>
122127 */
123- public function getPropertyNodes ()
128+ public function getPropertyNodes (): array
124129 {
125- return $ this ->propertyNodes ;
130+ return $ this ->properties ;
126131 }
127132
128133 /**
129- * @param string $name
130- * @param string $visibility
131- *
132- * @return void
133- *
134134 * @phpstan-param 'public'|'private'|'protected' $visibility
135135 */
136- public function addProperty ($ name , $ visibility = 'public ' , ? PropertyTypeNode $ typeNode = null )
136+ public function addProperty (PropertyNode | string $ property , string $ visibility = 'public ' ): void
137137 {
138+ if ($ property instanceof PropertyNode) {
139+ $ this ->properties [$ property ->getName ()] = $ property ;
140+
141+ return ;
142+ }
143+
144+ trigger_deprecation (
145+ 'phpspec/prophecy ' ,
146+ '1.24 ' ,
147+ 'The method addProperty() now expects a PropertyNode object instead of a string '
148+ );
149+
138150 $ visibility = strtolower ($ visibility );
139151
140152 if (!\in_array ($ visibility , array ('public ' , 'private ' , 'protected ' ), true )) {
@@ -143,15 +155,10 @@ public function addProperty($name, $visibility = 'public', ?PropertyTypeNode $ty
143155 ));
144156 }
145157
146- $ propertyNode = new PropertyNode ($ name );
158+ $ propertyNode = new PropertyNode ($ property );
147159 $ propertyNode ->setVisibility ($ visibility );
148- if ($ typeNode ) {
149- $ propertyNode ->setTypeNode ($ typeNode );
150- }
151-
152- $ this ->propertyNodes [$ name ] = $ propertyNode ;
153160
154- $ this ->properties [$ name ] = $ visibility ;
161+ $ this ->properties [$ property ] = $ propertyNode ;
155162 }
156163
157164 /**
0 commit comments