Skip to content

Commit af805d0

Browse files
authored
General code cleanup (#564)
* General code cleanup * Remove un-used import
1 parent a3abb63 commit af805d0

File tree

11 files changed

+164
-137
lines changed

11 files changed

+164
-137
lines changed

src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function validateSection($section, $item = null)
105105
*/
106106
public function getContexts(): array
107107
{
108-
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
108+
Factory::getApplication()->getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
109109
$contexts = [
110110
'com_weblinks.weblink' => Text::_('COM_WEBLINKS'),
111111
];

src/administrator/components/com_weblinks/src/Field/Modal/WeblinkField.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,21 @@ class WeblinkField extends FormField
4343
*/
4444
protected function getInput()
4545
{
46+
$app = Factory::getApplication();
47+
4648
$allowNew = ((string) $this->element['new'] == 'true');
4749
$allowEdit = ((string) $this->element['edit'] == 'true');
4850
$allowClear = ((string) $this->element['clear'] != 'false');
4951
$allowSelect = ((string) $this->element['select'] != 'false');
52+
5053
// Load language
51-
Factory::getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
54+
$app->getLanguage()->load('com_weblinks', JPATH_ADMINISTRATOR);
5255
// The active weblink id field.
5356
$value = (int) $this->value > 0 ? (int) $this->value : '';
5457
// Create the modal id.
5558
$modalId = 'Weblink_' . $this->id;
5659
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
57-
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
60+
$wa = $app->getDocument()->getWebAssetManager();
5861
// Add the modal field script to the document head.
5962
$wa->useScript('field.modal-fields');
6063
// Script to proxy the select modal function to the modal-fields.js file.
@@ -92,7 +95,7 @@ protected function getInput()
9295
$urlEdit = $linkWeblink . '&task=weblink.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \'';
9396
$urlNew = $linkWeblink . '&task=weblink.add';
9497
if ($value) {
95-
$db = Factory::getDbo();
98+
$db = $this->getDatabase();
9699
$query = $db->getQuery(true)
97100
->select($db->quoteName('title'))
98101
->from($db->quoteName('#__weblinks'))
@@ -102,7 +105,7 @@ protected function getInput()
102105
try {
103106
$title = $db->loadResult();
104107
} catch (\RuntimeException $e) {
105-
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
108+
$app->enqueueMessage($e->getMessage(), 'error');
106109
}
107110
}
108111

src/administrator/components/com_weblinks/src/Model/WeblinkModel.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ public function getForm($data = [], $loadData = true)
110110
// Get the form.
111111
$form = $this->loadForm('com_weblinks.weblink', 'weblink', ['control' => 'jform', 'load_data' => $loadData]);
112112

113-
if (empty($form)) {
114-
return false;
115-
}
116-
117113
// Determine correct permissions to check.
118114
if ($this->getState('weblink.id')) {
119115
// Existing record. Can only edit in selected categories.
@@ -294,8 +290,6 @@ protected function getReorderConditions($table)
294290
*/
295291
public function save($data)
296292
{
297-
$app = Factory::getApplication();
298-
299293
// Cast catid to integer for comparison
300294
$catid = (int) $data['catid'];
301295

@@ -318,7 +312,7 @@ public function save($data)
318312
}
319313

320314
// Alter the title for save as copy
321-
if ($app->input->get('task') == 'save2copy') {
315+
if ($this->getState('task') === 'save2copy') {
322316
[$name, $alias] = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
323317
$data['title'] = $name;
324318
$data['alias'] = $alias;

src/administrator/components/com_weblinks/src/Table/WeblinkTable.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,29 @@ class WeblinkTable extends Table implements VersionableTableInterface, TaggableT
3535
use TaggableTableTrait;
3636

3737
/**
38-
* Indicates that columns fully support the NULL value in the database
39-
*
40-
* @var boolean
41-
* @since __DEPLOY_VERSION__
42-
*/
43-
38+
* Indicates that columns fully support the NULL value in the database
39+
*
40+
* @var boolean
41+
* @since __DEPLOY_VERSION__
42+
*/
4443

4544
protected $_supportNullValue = true;
4645
/**
47-
* Ensure the params and metadata in json encoded in the bind method
48-
*
49-
* @var array
50-
* @since 3.4
51-
*/
46+
* Ensure the params and metadata in json encoded in the bind method
47+
*
48+
* @var array
49+
* @since 3.4
50+
*/
51+
5252
protected $_jsonEncode = ['params', 'metadata', 'images'];
53+
5354
/**
54-
* Constructor
55-
*
56-
* @param \JDatabaseDriver &$db A database connector object
57-
*
58-
* @since 1.5
59-
*/
55+
* Constructor
56+
*
57+
* @param \JDatabaseDriver &$db A database connector object
58+
*
59+
* @since 1.5
60+
*/
6061
public function __construct($db)
6162
{
6263
$this->typeAlias = 'com_weblinks.weblink';
@@ -79,6 +80,7 @@ public function store($updateNulls = true)
7980
$date = Factory::getDate()->toSql();
8081
$user = Factory::getApplication()->getIdentity();
8182
$this->modified = $date;
83+
8284
if ($this->id) {
8385
// Existing item
8486
$this->modified_by = $user->id;
@@ -148,7 +150,7 @@ public function check()
148150
}
149151

150152
// Check for valid name
151-
if (trim($this->title) == '') {
153+
if (trim($this->title) === '') {
152154
$this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
153155
return false;
154156
}

src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
2222
use Joomla\CMS\Toolbar\Toolbar;
2323
use Joomla\CMS\Toolbar\ToolbarHelper;
24+
use Joomla\Component\Weblinks\Administrator\Model\WeblinksModel;
2425

2526
/**
2627
* View class for a list of weblinks.
@@ -81,11 +82,14 @@ class HtmlView extends BaseHtmlView
8182
*/
8283
public function display($tpl = null)
8384
{
84-
$this->state = $this->get('State');
85-
$this->items = $this->get('Items');
86-
$this->pagination = $this->get('Pagination');
87-
$this->filterForm = $this->get('FilterForm');
88-
$this->activeFilters = $this->get('ActiveFilters');
85+
/** @var WeblinksModel $model */
86+
$model = $this->getModel();
87+
88+
$this->state = $model->getState();
89+
$this->items = $model->getItems();
90+
$this->pagination = $model->getPagination();
91+
$this->filterForm = $model->getFilterForm();
92+
$this->activeFilters = $model->getActiveFilters();
8993

9094
// Check for errors.
9195
if (\count($errors = $this->get('Errors'))) {

src/components/com_weblinks/src/Controller/DisplayController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function display($cacheable = false, $urlparams = false)
3939
// Huh? Why not just put that in the constructor?
4040
$cacheable = true;
4141
/**
42-
* Set the default view name and format from the Request.
43-
* Note we are using w_id to avoid collisions with the router and the return page.
44-
* Frontend is a bit messier than the backend.
45-
*/
42+
* Set the default view name and format from the Request.
43+
* Note we are using w_id to avoid collisions with the router and the return page.
44+
* Frontend is a bit messier than the backend.
45+
*/
4646
$id = $this->input->getInt('w_id');
4747
$vName = $this->input->get('view', 'categories');
4848
$this->input->set('view', $vName);

src/components/com_weblinks/src/Controller/WeblinkController.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,30 @@ class WeblinkController extends FormController
3232
* @since 1.6
3333
*/
3434
protected $view_item = 'form';
35+
3536
/**
36-
* The URL view list variable.
37-
*
38-
* @var string
39-
* @since 1.6
40-
*/
37+
* The URL view list variable.
38+
*
39+
* @var string
40+
* @since 1.6
41+
*/
4142
protected $view_list = 'categories';
43+
4244
/**
43-
* The URL edit variable.
44-
*
45-
* @var string
46-
* @since 3.2
47-
*/
45+
* The URL edit variable.
46+
*
47+
* @var string
48+
* @since 3.2
49+
*/
4850
protected $urlVar = 'a.id';
51+
4952
/**
50-
* Method to add a new record.
51-
*
52-
* @return boolean True if the article can be added, false if not.
53-
*
54-
* @since 1.6
55-
*/
53+
* Method to add a new record.
54+
*
55+
* @return boolean True if the article can be added, false if not.
56+
*
57+
* @since 1.6
58+
*/
5659
public function add()
5760
{
5861
if (!parent::add()) {

src/components/com_weblinks/src/Model/CategoriesModel.php

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// phpcs:disable PSR1.Files.SideEffects
2020
\defined('_JEXEC') or die;
2121
// phpcs:enable PSR1.Files.SideEffects
22+
2223
/**
2324
* This models supports retrieving lists of article categories.
2425
*
@@ -33,36 +34,40 @@ class CategoriesModel extends ListModel
3334
* @var string
3435
*/
3536
protected $context = 'com_weblinks.categories';
37+
3638
/**
37-
* The category context (allows other extensions to derived from this model).
38-
*
39-
* @var string
40-
*/
39+
* The category context (allows other extensions to derived from this model).
40+
*
41+
* @var string
42+
*/
4143
protected $_extension = 'com_weblinks';
44+
4245
/**
43-
* Parent category
44-
*
45-
* @var CategoryNode|null
46-
*/
46+
* Parent category
47+
*
48+
* @var CategoryNode|null
49+
*/
4750
private $_parent = null;
51+
4852
/**
49-
* Categories data
50-
*
51-
* @var false|array
52-
*/
53+
* Categories data
54+
*
55+
* @var false|array
56+
*/
5357
private $_items = null;
58+
5459
/**
55-
* Method to auto-populate the model state.
56-
*
57-
* Note. Calling getState in this method will result in recursion.
58-
*
59-
* @param string $ordering An optional ordering field.
60-
* @param string $direction An optional direction (asc|desc).
61-
*
62-
* @return void
63-
*
64-
* @since 1.6
65-
*/
60+
* Method to auto-populate the model state.
61+
*
62+
* Note. Calling getState in this method will result in recursion.
63+
*
64+
* @param string $ordering An optional ordering field.
65+
* @param string $direction An optional direction (asc|desc).
66+
*
67+
* @return void
68+
*
69+
* @since 1.6
70+
*/
6671
protected function populateState($ordering = null, $direction = null)
6772
{
6873
$app = Factory::getApplication();
@@ -94,6 +99,7 @@ protected function getStoreId($id = '')
9499
$id .= ':' . $this->getState('filter.published');
95100
$id .= ':' . $this->getState('filter.access');
96101
$id .= ':' . $this->getState('filter.parentId');
102+
97103
return parent::getStoreId($id);
98104
}
99105

src/components/com_weblinks/src/Model/CategoryModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Joomla\CMS\Helper\TagsHelper;
2121
use Joomla\CMS\Language\Multilanguage;
2222
use Joomla\CMS\MVC\Model\ListModel;
23-
use Joomla\CMS\Table\Table;
23+
use Joomla\CMS\Table\Category;
2424
use Joomla\Database\ParameterType;
2525
use Joomla\Registry\Registry;
2626

@@ -401,7 +401,7 @@ public function hit($pk = 0)
401401

402402
if ($hitcount) {
403403
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
404-
$table = Table::getInstance('Category', 'Joomla\\CMS\\Table\\');
404+
$table = new Category($this->getDatabase());
405405
$table->load($pk);
406406
$table->hit($pk);
407407
}

0 commit comments

Comments
 (0)