1313use Joomla \CMS \HTML \HTMLHelper ;
1414use Joomla \CMS \Language \Text ;
1515use Joomla \CMS \MVC \Model \ListModel ;
16+ use Joomla \Database \DatabaseQuery ;
1617use PatchTester \GitHub \Exception \UnexpectedResponse ;
1718use PatchTester \Helper ;
19+ use RuntimeException ;
1820
1921// phpcs:disable PSR1.Files.SideEffects
2022\defined ('_JEXEC ' ) or die;
@@ -40,7 +42,7 @@ class PullsModel extends ListModel
4042 * @var array
4143 * @since 2.0
4244 */
43- protected $ sortFields = array ( 'pulls.pull_id ' , 'pulls.title ' ) ;
45+ protected $ sortFields = [ 'pulls.pull_id ' , 'pulls.title ' ] ;
4446 /**
4547 * Constructor.
4648 *
@@ -86,7 +88,7 @@ public function getItems()
8688 $ this ->getStart (),
8789 $ this ->getState ()->get ('list.limit ' )
8890 );
89- $ db = $ this ->getDbo ();
91+ $ db = $ this ->getDatabase ();
9092 $ query = $ db ->getQuery (true )
9193 ->select ($ db ->quoteName (['name ' , 'color ' ]))
9294 ->from ($ db ->quoteName ('#__patchtester_pulls_labels ' ));
@@ -127,18 +129,18 @@ protected function getStoreId($id = '')
127129 /**
128130 * Gets an array of objects from the results of database query.
129131 *
130- * @param \JDatabaseQuery |string $query The query.
131- * @param integer $limitstart Offset.
132- * @param integer $limit The number of records.
132+ * @param DatabaseQuery |string $query The query.
133+ * @param integer $limitstart Offset.
134+ * @param integer $limit The number of records.
133135 *
134136 * @return array An array of results.
135137 *
136138 * @since 2.0
137139 * @throws RuntimeException
138140 */
139- protected function getList ($ query , $ limitstart = 0 , $ limit = 0 )
141+ protected function getList ($ query , int $ limitstart = 0 , int $ limit = 0 ): array
140142 {
141- return $ this ->getDbo ()->setQuery ($ query , $ limitstart , $ limit )
143+ return $ this ->getDatabase ()->setQuery ($ query , $ limitstart , $ limit )
142144 ->loadObjectList ();
143145 }
144146
@@ -147,11 +149,11 @@ protected function getList($query, $limitstart = 0, $limit = 0)
147149 *
148150 * This method ensures that the query is constructed only once for a given state of the model.
149151 *
150- * @return \JDatabaseQuery A JDatabaseQuery object
152+ * @return DatabaseQuery A DatabaseQuery object
151153 *
152154 * @since 2.0
153155 */
154- protected function getListQueryCache ()
156+ protected function getListQueryCache (): DatabaseQuery
155157 {
156158 // Capture the last store id used.
157159 static $ lastStoreId ;
@@ -167,15 +169,15 @@ protected function getListQueryCache()
167169 }
168170
169171 /**
170- * Method to get a JDatabaseQuery object for retrieving the data set from a database.
172+ * Method to get a DatabaseQuery object for retrieving the data set from a database.
171173 *
172- * @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
174+ * @return DatabaseQuery A DatabaseQuery object to retrieve the data set.
173175 *
174176 * @since 2.0
175177 */
176178 protected function getListQuery ()
177179 {
178- $ db = $ this ->getDbo ();
180+ $ db = $ this ->getDatabase ();
179181 $ query = $ db ->getQuery (true );
180182 $ labelQuery = $ db ->getQuery (true );
181183 $ query ->select ('pulls.* ' )
@@ -270,35 +272,36 @@ protected function getListQuery()
270272 *
271273 * @since 2.0
272274 */
273- public function getSortFields ()
275+ public function getSortFields (): array
274276 {
275277 return $ this ->sortFields ;
276278 }
277279
278280 /**
279281 * Method to request new data from GitHub
280282 *
281- * @param integer $page The page of the request
283+ * @param int $page The page of the request
282284 *
283285 * @return array
284286 *
287+ * @throws RuntimeException
285288 * @since 2.0
286- * @throws \RuntimeException
287289 */
288- public function requestFromGithub ($ page )
290+ public function requestFromGithub (int $ page ): array
289291 {
290292 if ($ page === 1 ) {
291- $ this ->getDbo ()->truncateTable ('#__patchtester_pulls ' );
292- $ this ->getDbo ()->truncateTable ('#__patchtester_pulls_labels ' );
293+ $ this ->getDatabase ()->truncateTable ('#__patchtester_pulls ' );
294+ $ this ->getDatabase ()->truncateTable ('#__patchtester_pulls_labels ' );
293295 }
294296
295297 try {
296- // TODO - Option to configure the batch size
298+ // TODO - Option to configure the batch size
297299 $ batchSize = 100 ;
298300 $ pullsResponse = Helper::initializeGithub ()->getOpenPulls ($ this ->getState ()->get ('github_user ' ), $ this ->getState ()->get ('github_repo ' ), $ page , $ batchSize );
299301 $ pulls = json_decode ($ pullsResponse ->body );
300302 } catch (UnexpectedResponse $ exception ) {
301- throw new \RuntimeException (Text::sprintf ('COM_PATCHTESTER_ERROR_GITHUB_FETCH ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
303+ throw new RuntimeException (
304+ Text::sprintf ('COM_PATCHTESTER_ERROR_GITHUB_FETCH ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
302305 }
303306
304307 // If this is page 1, let's check to see if we need to paginate
@@ -354,20 +357,20 @@ public function requestFromGithub($page)
354357
355358 $ labels [] = implode (', ' , [
356359 (int ) $ pull ->number ,
357- $ this ->getDbo ()->quote ($ label ->name ),
358- $ this ->getDbo ()->quote ($ label ->color ),
360+ $ this ->getDatabase ()->quote ($ label ->name ),
361+ $ this ->getDatabase ()->quote ($ label ->color ),
359362 ]);
360363 }
361364
362365 // Build the data object to store in the database
363366 $ pullData = [
364367 (int ) $ pull ->number ,
365- $ this ->getDbo ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->title ?? '' ), 150 )),
366- $ this ->getDbo ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->body ?? '' ), 100 )),
367- $ this ->getDbo ()->quote ($ pull ->html_url ),
368+ $ this ->getDatabase ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->title ?? '' ), 150 )),
369+ $ this ->getDatabase ()->quote (HTMLHelper::_ ('string.truncate ' , ($ pull ->body ?? '' ), 100 )),
370+ $ this ->getDatabase ()->quote ($ pull ->html_url ),
368371 (int ) $ isRTC ,
369372 (int ) $ isNPM ,
370- $ this ->getDbo ()->quote ($ branch ),
373+ $ this ->getDatabase ()->quote ($ branch ),
371374 ($ pull ->draft ? 1 : 0 )
372375 ];
373376 $ data [] = implode (', ' , $ pullData );
@@ -379,25 +382,26 @@ public function requestFromGithub($page)
379382 }
380383
381384 try {
382- $ this ->getDbo ()->setQuery ($ this ->getDbo ()->getQuery (true )
385+ $ this ->getDatabase ()->setQuery ($ this ->getDatabase ()->getQuery (true )
383386 ->insert ('#__patchtester_pulls ' )
384387 ->columns (['pull_id ' , 'title ' , 'description ' , 'pull_url ' ,
385388 'is_rtc ' , 'is_npm ' , 'branch ' , 'is_draft ' ])
386389 ->values ($ data ));
387- $ this ->getDbo ()->execute ();
388- } catch (\RuntimeException $ exception ) {
389- throw new \RuntimeException (Text::sprintf ('COM_PATCHTESTER_ERROR_INSERT_DATABASE ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
390+ $ this ->getDatabase ()->execute ();
391+ } catch (RuntimeException $ exception ) {
392+ throw new RuntimeException (
393+ Text::sprintf ('COM_PATCHTESTER_ERROR_INSERT_DATABASE ' , $ exception ->getMessage ()), $ exception ->getCode (), $ exception );
390394 }
391395
392396 if ($ labels ) {
393397 try {
394- $ this ->getDbo ()->setQuery ($ this ->getDbo ()->getQuery (true )
398+ $ this ->getDatabase ()->setQuery ($ this ->getDatabase ()->getQuery (true )
395399 ->insert ('#__patchtester_pulls_labels ' )
396400 ->columns (['pull_id ' , 'name ' , 'color ' ])
397401 ->values ($ labels ));
398- $ this ->getDbo ()->execute ();
399- } catch (\ RuntimeException $ exception ) {
400- throw new \ RuntimeException (
402+ $ this ->getDatabase ()->execute ();
403+ } catch (RuntimeException $ exception ) {
404+ throw new RuntimeException (
401405 Text::sprintf (
402406 'COM_PATCHTESTER_ERROR_INSERT_DATABASE ' ,
403407 $ exception ->getMessage ()
@@ -424,6 +428,6 @@ public function requestFromGithub($page)
424428 */
425429 public function truncateTable ()
426430 {
427- $ this ->getDbo ()->truncateTable ('#__patchtester_pulls ' );
431+ $ this ->getDatabase ()->truncateTable ('#__patchtester_pulls ' );
428432 }
429433}
0 commit comments