@@ -78,19 +78,26 @@ public function __construct(Client $caller)
7878 $ this ->useCaller ($ caller );
7979 }
8080
81+ /**
82+ * Associate a Caller with this Response and initialize state from its last HTTP response.
83+ *
84+ * If the caller has a lastCurlResponse, stores it in $rawXML, attempts to load it as XML,
85+ * reads the root `rsp` attributes `state` and `note`, and processes each child `rsp` element
86+ * by delegating to processResponsePackItem().
87+ *
88+ * If there is no lastCurlResponse, sets the response state to "error" and the note to the
89+ * caller's lastCurlError.
90+ */
8191 public function useCaller (Client $ caller ): void
8292 {
8393 $ this ->caller = $ caller ;
8494 if ($ caller ->lastCurlResponse ) {
8595 $ this ->rawXML = $ caller ->lastCurlResponse ;
86- $ xml = simplexml_load_string ($ this ->rawXML , ' SimpleXMLElement ' , \ LIBXML_NONET | \ LIBXML_NOCDATA );
96+ $ xml = simplexml_load_string ($ this ->rawXML );
8797 if ($ xml ) {
88- $ attrsRsp = $ xml ->attributes ('rsp ' , true );
89- $ attrs = $ xml ->attributes ();
90- $ this ->state = (string ) (($ attrsRsp ['state ' ] ?? $ attrs ['state ' ] ?? '' ) );
91- $ this ->note = (string ) (($ attrsRsp ['note ' ] ?? $ attrs ['note ' ] ?? '' ) );
92- $ children = iterator_to_array ($ xml ->children ('rsp ' , true ) ?: $ xml ->children ());
93- foreach ($ children as $ responsePackItem ) {
98+ $ this ->state = (string ) $ xml ->attributes ('rsp ' , true )->state ;
99+ $ this ->note = (string ) $ xml ->attributes ('rsp ' , true )->note ;
100+ foreach ($ xml ->children ('rsp ' , true ) as $ responsePackItem ) {
94101 $ this ->processResponsePackItem ($ responsePackItem );
95102 }
96103 }
@@ -100,11 +107,28 @@ public function useCaller(Client $caller): void
100107 }
101108 }
102109
110+ /**
111+ * No-op placeholder for processing a responsePack XML element; retained for compatibility.
112+ *
113+ * This method intentionally does nothing and is deprecated — response pack items are processed
114+ * via processResponsePackItem() when XML is loaded.
115+ *
116+ * @param \SimpleXMLElement $responsePackData The <responsePack> XML element (ignored).
117+ * @deprecated Use processResponsePackItem(\SimpleXMLElement $responsePackItem) or let useCaller() handle response pack processing.
118+ */
103119 public function processResponsePack (\SimpleXMLElement $ responsePackData ): void
104120 {
105121 // This method is no longer used
106122 }
107123
124+ /**
125+ * Process a single <responsePackItem> XML node: update the overall state and handle its child response nodes.
126+ *
127+ * Reads the node's "state" attribute into the instance state and delegates each child element to
128+ * processResponseData(), which may populate parsed data, producedDetails, and messages.
129+ *
130+ * @param \SimpleXMLElement $responsePackItem XML element representing one responsePackItem.
131+ */
108132 public function processResponsePackItem (\SimpleXMLElement $ responsePackItem ): void
109133 {
110134 $ this ->state = (string ) $ responsePackItem ->attributes ()->state ;
@@ -113,12 +137,36 @@ public function processResponsePackItem(\SimpleXMLElement $responsePackItem): vo
113137 }
114138 }
115139
140+ /**
141+ * Extracts produced detail ID from an `rdc` namespaced XML node and stores it.
142+ *
143+ * Reads the `<rdc:id>` child of the provided SimpleXMLElement, casts it to int,
144+ * sets $this->producedDetails to ['id' => (int)], and synchronizes $this->parsed
145+ * with the same value.
146+ *
147+ * @param \SimpleXMLElement $productDetails XML node containing an `rdc:id` child (uses the `rdc` namespace)
148+ */
116149 public function processProducedDetails (\SimpleXMLElement $ productDetails ): void
117150 {
118151 $ this ->producedDetails = ['id ' => (int ) $ productDetails ->children ('rdc ' , true )->id ];
119152 $ this ->parsed = $ this ->producedDetails ;
120153 }
121154
155+ /**
156+ * Process import-detail nodes from a Pohoda response and record their messages.
157+ *
158+ * Iterates over children in the `rdc` namespace of the provided import details element,
159+ * collects each detail's child elements into an associative array (element name => string value),
160+ * groups those arrays into $this->messages keyed by each detail's `state` value, and updates
161+ * the response state and parsed representation accordingly.
162+ *
163+ * Side effects:
164+ * - Appends parsed detail arrays into $this->messages (keys like 'error' or 'warning').
165+ * - Sets $this->state to 'error' if any error messages exist, otherwise to 'warning' if any warnings exist.
166+ * - Updates $this->parsed to reference the messages array.
167+ *
168+ * @param \SimpleXMLElement $importDetails XML element containing import detail entries (expects children in the `rdc` namespace)
169+ */
122170 public function processImportDetails (\SimpleXMLElement $ importDetails ): void
123171 {
124172 foreach ($ importDetails ->children ('rdc ' , true ) as $ detail ) {
@@ -138,8 +186,15 @@ public function processImportDetails(\SimpleXMLElement $importDetails): void
138186 }
139187
140188 /**
141- * @param \SimpleXMLElement $responseData
142- */
189+ * Process a single <responseData> XML node.
190+ *
191+ * Updates the object's overall state from the node's `state` attribute and, when present,
192+ * delegates processing of child elements `producedDetails` and `importDetails` to
193+ * processProducedDetails() and processImportDetails() respectively. Those handlers
194+ * update internal parsed data, messages, and producedDetails.
195+ *
196+ * @param \SimpleXMLElement $responseData The <responseData> element to process.
197+ */
143198 public function processResponseData (\SimpleXMLElement $ responseData ): void
144199 {
145200 $ this ->state = (string ) $ responseData ->attributes ()->state ;
0 commit comments