Skip to content

Commit d86335e

Browse files
committed
Update class definitions to use the namespaced versions
Signed-off-by: Roland Dalmulder <[email protected]>
1 parent b74c149 commit d86335e

File tree

3 files changed

+53
-46
lines changed

3 files changed

+53
-46
lines changed

administrator/components/com_patchtester/PatchTester/Model/AbstractModel.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PatchTester\Model;
1111

1212
use Joomla\CMS\Factory;
13+
use Joomla\Database\DatabaseDriver;
1314
use Joomla\Registry\Registry;
1415

1516
/**
@@ -22,7 +23,7 @@ abstract class AbstractModel
2223
/**
2324
* The database driver.
2425
*
25-
* @var \JDatabaseDriver
26+
* @var DatabaseDriver
2627
* @since 4.0.0
2728
*/
2829
protected $db;
@@ -33,15 +34,16 @@ abstract class AbstractModel
3334
* @since 4.0.0
3435
*/
3536
protected $state;
36-
/**
37+
38+
/**
3739
* Instantiate the model.
3840
*
39-
* @param Registry $state The model state.
40-
* @param \JDatabaseDriver $db The database adpater.
41+
* @param Registry|null $state The model state.
42+
* @param DatabaseDriver|null $db The database adapter.
4143
*
4244
* @since 4.0.0
4345
*/
44-
public function __construct(Registry $state = null, \JDatabaseDriver $db = null)
46+
public function __construct(Registry $state = null, DatabaseDriver $db = null)
4547
{
4648
$this->state = $state ?: new Registry();
4749
$this->db = $db ?: Factory::getDbo();
@@ -50,7 +52,7 @@ public function __construct(Registry $state = null, \JDatabaseDriver $db = null)
5052
/**
5153
* Get the database driver.
5254
*
53-
* @return \JDatabaseDriver
55+
* @return DatabaseDriver
5456
*
5557
* @since 4.0.0
5658
*/
@@ -74,13 +76,13 @@ public function getState()
7476
/**
7577
* Set the database driver.
7678
*
77-
* @param \JDatabaseDriver $db The database driver.
79+
* @param DatabaseDriver $db The database driver.
7880
*
7981
* @return void
8082
*
8183
* @since 4.0.0
8284
*/
83-
public function setDb(\JDatabaseDriver $db)
85+
public function setDb(DatabaseDriver $db)
8486
{
8587
$this->db = $db;
8688
}

administrator/components/com_patchtester/PatchTester/Model/PullModel.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Joomla\CMS\Http\HttpFactory;
1717
use Joomla\CMS\Language\Text;
1818
use Joomla\CMS\Version;
19+
use Joomla\Database\DatabaseDriver;
1920
use Joomla\Filesystem\File;
2021
use Joomla\Filesystem\Folder;
2122
use Joomla\Registry\Registry;
@@ -88,11 +89,11 @@ class PullModel extends AbstractModel
8889
* Instantiate the model.
8990
*
9091
* @param Registry $state The model state.
91-
* @param \JDatabaseDriver $db The database adpater.
92+
* @param DatabaseDriver $db The database adpater.
9293
*
9394
* @since 4.0.0
9495
*/
95-
public function __construct(Registry $state = null, \JDatabaseDriver $db = null)
96+
public function __construct(Registry $state = null, DatabaseDriver $db = null)
9697
{
9798
parent::__construct($state, $db);
9899
$this->namespaceMapper = new \JNamespacePsr4Map();
@@ -113,7 +114,7 @@ public function __construct(Registry $state = null, \JDatabaseDriver $db = null)
113114
public function apply(int $id): bool
114115
{
115116
$params = ComponentHelper::getParams('com_patchtester');
116-
// Decide based on repository settings whether patch will be applied through Github or CIServer
117+
// Decide based on repository settings whether patch will be applied through Github or CIServer
117118
if ((bool) $params->get('ci_switch', 0)) {
118119
return $this->applyWithCIServer($id);
119120
}

administrator/components/com_patchtester/PatchTester/Model/PullsModel.php

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
use Joomla\CMS\HTML\HTMLHelper;
1414
use Joomla\CMS\Language\Text;
1515
use Joomla\CMS\MVC\Model\ListModel;
16+
use Joomla\Database\DatabaseQuery;
1617
use PatchTester\GitHub\Exception\UnexpectedResponse;
1718
use 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

Comments
 (0)