@@ -27,6 +27,9 @@ final class ObjectDataSet implements RulesProviderInterface, DataSetInterface
2727 private bool $ dataSetProvided ;
2828 private bool $ rulesProvided ;
2929
30+ /**
31+ * @var array<string, array<string, mixed>>
32+ */
3033 #[ArrayShape([
3134 [
3235 'rules ' => 'iterable ' ,
@@ -54,7 +57,10 @@ public function __construct(
5457 public function getRules (): iterable
5558 {
5659 if ($ this ->rulesProvided ) {
57- return $ this ->object ->getRules ();
60+ /** @var RulesProviderInterface $object */
61+ $ object = $ this ->object ;
62+
63+ return $ object ->getRules ();
5864 }
5965
6066 // Providing data set assumes object has its own attributes and rules getting logic. So further parsing of
@@ -64,6 +70,7 @@ public function getRules(): iterable
6470 }
6571
6672 if ($ this ->hasCacheItem ('rules ' )) {
73+ /** @var array<string, RuleInterface> */
6774 return $ this ->getCacheItem ('rules ' );
6875 }
6976
@@ -96,36 +103,52 @@ public function getObject(): object
96103 public function getAttributeValue (string $ attribute ): mixed
97104 {
98105 if ($ this ->dataSetProvided ) {
99- return $ this ->object ->getAttributeValue ($ attribute );
106+ /** @var DataSetInterface $object */
107+ $ object = $ this ->object ;
108+
109+ return $ object ->getAttributeValue ($ attribute );
100110 }
101111
102112 return ($ this ->getReflectionProperties ()[$ attribute ] ?? null )?->getValue($ this ->getObject ());
103113 }
104114
105115 public function hasAttribute (string $ attribute ): bool
106116 {
107- return $ this ->dataSetProvided
108- ? $ this ->object ->hasAttribute ($ attribute )
109- : array_key_exists ($ attribute , $ this ->getReflectionProperties ());
117+ if (!$ this ->dataSetProvided ) {
118+ return array_key_exists ($ attribute , $ this ->getReflectionProperties ());
119+ }
120+
121+ /** @var DataSetInterface $object */
122+ $ object = $ this ->object ;
123+
124+ return $ object ->hasAttribute ($ attribute );
110125 }
111126
112- public function getData (): array
127+ public function getData (): mixed
113128 {
114129 if ($ this ->dataSetProvided ) {
115- return $ this ->object ->getData ();
130+ /** @var DataSetInterface $object */
131+ $ object = $ this ->object ;
132+
133+ return $ object ->getData ();
116134 }
117135
118136 $ data = [];
119137 foreach ($ this ->getReflectionProperties () as $ name => $ property ) {
138+ /** @psalm-suppress MixedAssignment */
120139 $ data [$ name ] = $ property ->getValue ($ this ->object );
121140 }
122141
123142 return $ data ;
124143 }
125144
145+ /**
146+ * @return array<string, ReflectionProperty>
147+ */
126148 private function getReflectionProperties (): array
127149 {
128150 if ($ this ->hasCacheItem ('reflectionProperties ' )) {
151+ /** @var array<string, ReflectionProperty> */
129152 return $ this ->getCacheItem ('reflectionProperties ' );
130153 }
131154
@@ -154,20 +177,33 @@ private function canCache(): bool
154177
155178 private function hasCacheItem (#[ExpectedValues(['rules ' , 'reflectionProperties ' ])] string $ name ): bool
156179 {
180+ if ($ this ->cacheKey === null ) {
181+ return false ;
182+ }
183+
157184 if (!array_key_exists ($ this ->cacheKey , self ::$ cache )) {
158185 return false ;
159186 }
160187
161188 return array_key_exists ($ name , self ::$ cache [$ this ->cacheKey ]);
162189 }
163190
191+ /**
192+ * @psalm-suppress MixedInferredReturnType
193+ * @psalm-suppress MixedReturnStatement
194+ */
164195 private function getCacheItem (#[ExpectedValues(['rules ' , 'reflectionProperties ' ])] string $ name ): array
165196 {
197+ /** @psalm-suppress PossiblyNullArrayOffset */
166198 return self ::$ cache [$ this ->cacheKey ][$ name ];
167199 }
168200
169- private function setCacheItem (#[ExpectedValues(['rules ' , 'reflectionProperties ' ])] string $ name , array $ rules ): void
201+ private function setCacheItem (#[ExpectedValues(['rules ' , 'reflectionProperties ' ])] string $ name , array $ value ): void
170202 {
171- self ::$ cache [$ this ->cacheKey ][$ name ] = $ rules ;
203+ /**
204+ * @psalm-suppress PossiblyNullArrayOffset
205+ * @psalm-suppress MixedAssignment
206+ */
207+ self ::$ cache [$ this ->cacheKey ][$ name ] = $ value ;
172208 }
173209}
0 commit comments