55 */
66namespace Magento \AdminNotification \Model ;
77
8- use Magento \Framework \Escaper ;
8+ use Magento \AdminNotification \Model \InboxFactory ;
9+ use Magento \Backend \App \ConfigInterface ;
10+ use Magento \Framework \App \DeploymentConfig ;
911use Magento \Framework \App \ObjectManager ;
12+ use Magento \Framework \App \ProductMetadataInterface ;
1013use Magento \Framework \Config \ConfigOptionsListConstants ;
14+ use Magento \Framework \Data \Collection \AbstractDb ;
15+ use Magento \Framework \Escaper ;
16+ use Magento \Framework \HTTP \Adapter \Curl ;
17+ use Magento \Framework \HTTP \Adapter \CurlFactory ;
18+ use Magento \Framework \Model \AbstractModel ;
19+ use Magento \Framework \Model \Context ;
20+ use Magento \Framework \Model \ResourceModel \AbstractResource ;
21+ use Magento \Framework \Registry ;
22+ use Magento \Framework \UrlInterface ;
23+ use SimpleXMLElement ;
1124
1225/**
1326 * AdminNotification Feed model
1629 * @api
1730 * @since 100.0.2
1831 */
19- class Feed extends \ Magento \ Framework \ Model \ AbstractModel
32+ class Feed extends AbstractModel
2033{
21- const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https ' ;
34+ public const XML_USE_HTTPS_PATH = 'system/adminnotification/use_https ' ;
2235
23- const XML_FEED_URL_PATH = 'system/adminnotification/feed_url ' ;
36+ public const XML_FEED_URL_PATH = 'system/adminnotification/feed_url ' ;
2437
25- const XML_FREQUENCY_PATH = 'system/adminnotification/frequency ' ;
38+ public const XML_FREQUENCY_PATH = 'system/adminnotification/frequency ' ;
2639
27- const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update ' ;
40+ public const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update ' ;
2841
2942 /**
3043 * @var Escaper
3144 */
3245 private $ escaper ;
3346
3447 /**
35- * Feed url
36- *
3748 * @var string
3849 */
3950 protected $ _feedUrl ;
4051
4152 /**
42- * @var \Magento\Backend\App\ ConfigInterface
53+ * @var ConfigInterface
4354 */
4455 protected $ _backendConfig ;
4556
4657 /**
47- * @var \Magento\AdminNotification\Model\ InboxFactory
58+ * @var InboxFactory
4859 */
4960 protected $ _inboxFactory ;
5061
5162 /**
52- * @var \Magento\Framework\HTTP\Adapter\ CurlFactory
63+ * @var CurlFactory
5364 *
5465 */
5566 protected $ curlFactory ;
5667
5768 /**
5869 * Deployment configuration
5970 *
60- * @var \Magento\Framework\App\ DeploymentConfig
71+ * @var DeploymentConfig
6172 */
6273 protected $ _deploymentConfig ;
6374
6475 /**
65- * @var \Magento\Framework\App\ ProductMetadataInterface
76+ * @var ProductMetadataInterface
6677 */
6778 protected $ productMetadata ;
6879
6980 /**
70- * @var \Magento\Framework\ UrlInterface
81+ * @var UrlInterface
7182 */
7283 protected $ urlBuilder ;
7384
7485 /**
75- * @param \Magento\Framework\Model\ Context $context
76- * @param \Magento\Framework\ Registry $registry
77- * @param \Magento\Backend\App\ ConfigInterface $backendConfig
86+ * @param Context $context
87+ * @param Registry $registry
88+ * @param ConfigInterface $backendConfig
7889 * @param InboxFactory $inboxFactory
79- * @param \Magento\Framework\HTTP\Adapter\ CurlFactory $curlFactory
80- * @param \Magento\Framework\App\ DeploymentConfig $deploymentConfig
81- * @param \Magento\Framework\App\ ProductMetadataInterface $productMetadata
82- * @param \Magento\Framework\ UrlInterface $urlBuilder
83- * @param \Magento\Framework\Model\ResourceModel\ AbstractResource $resource
84- * @param \Magento\Framework\Data\Collection\ AbstractDb $resourceCollection
90+ * @param CurlFactory $curlFactory
91+ * @param DeploymentConfig $deploymentConfig
92+ * @param ProductMetadataInterface $productMetadata
93+ * @param UrlInterface $urlBuilder
94+ * @param AbstractResource|null $resource
95+ * @param AbstractDb|null $resourceCollection
8596 * @param array $data
8697 * @param Escaper|null $escaper
8798 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
8899 */
89100 public function __construct (
90- \ Magento \ Framework \ Model \ Context $ context ,
91- \ Magento \ Framework \ Registry $ registry ,
92- \ Magento \ Backend \ App \ ConfigInterface $ backendConfig ,
93- \ Magento \ AdminNotification \ Model \ InboxFactory $ inboxFactory ,
94- \ Magento \ Framework \ HTTP \ Adapter \ CurlFactory $ curlFactory ,
95- \ Magento \ Framework \ App \ DeploymentConfig $ deploymentConfig ,
96- \ Magento \ Framework \ App \ ProductMetadataInterface $ productMetadata ,
97- \ Magento \ Framework \ UrlInterface $ urlBuilder ,
98- \ Magento \ Framework \ Model \ ResourceModel \ AbstractResource $ resource = null ,
99- \ Magento \ Framework \ Data \ Collection \ AbstractDb $ resourceCollection = null ,
101+ Context $ context ,
102+ Registry $ registry ,
103+ ConfigInterface $ backendConfig ,
104+ InboxFactory $ inboxFactory ,
105+ CurlFactory $ curlFactory ,
106+ DeploymentConfig $ deploymentConfig ,
107+ ProductMetadataInterface $ productMetadata ,
108+ UrlInterface $ urlBuilder ,
109+ AbstractResource $ resource = null ,
110+ AbstractDb $ resourceCollection = null ,
100111 array $ data = [],
101112 Escaper $ escaper = null
102113 ) {
@@ -210,10 +221,11 @@ public function setLastUpdate()
210221 /**
211222 * Retrieve feed data as XML element
212223 *
213- * @return \ SimpleXMLElement
224+ * @return SimpleXMLElement
214225 */
215226 public function getFeedData ()
216227 {
228+ /** @var Curl $curl */
217229 $ curl = $ this ->curlFactory ->create ();
218230 $ curl ->setConfig (
219231 [
@@ -227,11 +239,11 @@ public function getFeedData()
227239 $ curl ->write (\Zend_Http_Client::GET , $ this ->getFeedUrl (), '1.0 ' );
228240 $ data = $ curl ->read ();
229241 $ data = preg_split ('/^\r?$/m ' , $ data , 2 );
230- $ data = trim ($ data [1 ]);
242+ $ data = trim ($ data [1 ] ?? '' );
231243 $ curl ->close ();
232244
233245 try {
234- $ xml = new \ SimpleXMLElement ($ data );
246+ $ xml = new SimpleXMLElement ($ data );
235247 } catch (\Exception $ e ) {
236248 return false ;
237249 }
@@ -242,15 +254,15 @@ public function getFeedData()
242254 /**
243255 * Retrieve feed as XML element
244256 *
245- * @return \ SimpleXMLElement
257+ * @return SimpleXMLElement
246258 */
247259 public function getFeedXml ()
248260 {
249261 try {
250262 $ data = $ this ->getFeedData ();
251- $ xml = new \ SimpleXMLElement ($ data );
263+ $ xml = new SimpleXMLElement ($ data );
252264 } catch (\Exception $ e ) {
253- $ xml = new \ SimpleXMLElement ('<?xml version="1.0" encoding="utf-8" ?> ' );
265+ $ xml = new SimpleXMLElement ('<?xml version="1.0" encoding="utf-8" ?> ' );
254266 }
255267
256268 return $ xml ;
@@ -259,10 +271,10 @@ public function getFeedXml()
259271 /**
260272 * Converts incoming data to string format and escapes special characters.
261273 *
262- * @param \ SimpleXMLElement $data
274+ * @param SimpleXMLElement $data
263275 * @return string
264276 */
265- private function escapeString (\ SimpleXMLElement $ data )
277+ private function escapeString (SimpleXMLElement $ data )
266278 {
267279 return $ this ->escaper ->escapeHtml ((string )$ data );
268280 }
0 commit comments