Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 26, 2024
1 parent 3cf86f9 commit cbee86a
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 63 deletions.
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Bug Report
description: Create a bug report for this plugin.
labels:
- bug
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to submit a bug report! To ensure this hasn’t already been reported, please first search existing issues.
To rule out that this isn’t a setup or configuration issue, please read the docs.
If you still believe you’ve found a bug, please provide a clear and concise description, including:
- What is happening and what you expected to happen.
- Steps to reproduce the issue.
- Screenshots, if applicable.
- type: textarea
id: body
attributes:
label: Bug Report
description: Please provide a clear and concise description of the bug.
validations:
required: true
- type: input
id: pluginVersion
attributes:
label: Plugin Version
description: Provide the plugin version that this relates to, ideally the latest version.
validations:
required: true
- type: input
id: craftVersion
attributes:
label: Craft CMS Version
description: Provide the version of Craft that is installed.
validations:
required: true
- type: input
id: phpVersion
attributes:
label: PHP Version
description: Provide the PHP version, if applicable.
14 changes: 0 additions & 14 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/feature-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Feature Request
description: Suggest a new feature for this plugin.
labels:
- enhancement
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to submit a feature request! To ensure this isn’t already on our radar, please first search existing issues.
If you still believe you have a new suggestion, please provide a clear and concise description, including:
- What problem you believe your feature request can solve.
- Any alternative solutions or features you have already considered.
- type: textarea
id: body
attributes:
label: Feature Request
description: Please provide a clear and concise suggestion for a feature.
validations:
required: true
- type: input
id: pluginVersion
attributes:
label: Plugin Version
description: Provide the plugin version that this relates to, ideally the latest version.
12 changes: 0 additions & 12 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

10 changes: 0 additions & 10 deletions .github/ISSUE_TEMPLATE/support-request.md

This file was deleted.

23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/support-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Support Request
description: Ask a question about this plugin.
labels:
- question
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to submit a support request! To ensure your question hasn’t already been asked and answered, please first search existing issues.
If your question is still unanswered, please provide a clear and concise description. Note that we are diligent about documentation, so please check whether your question is answered by the plugin docs before submitting.
- type: textarea
id: body
attributes:
label: Support Request
description: Please provide a clear and concise question.
validations:
required: true
- type: input
id: pluginVersion
attributes:
label: Plugin Version
description: Provide the plugin version that this relates to, ideally the latest version.
3 changes: 1 addition & 2 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->parallel();
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);

$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
16 changes: 8 additions & 8 deletions src/BlitzHints.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ public function init(): void
{
parent::init();

$this->_registerComponents();
$this->_registerEvents();
$this->_registerTemplateRoots();
$this->_registerUtilities();
$this->registerComponents();
$this->registerEvents();
$this->registerTemplateRoots();
$this->registerUtilities();
}

/**
* Registers components
*/
private function _registerComponents(): void
private function registerComponents(): void
{
$this->setComponents([
'hints' => HintsService::class,
Expand All @@ -81,7 +81,7 @@ private function _registerComponents(): void
/**
* Registers events
*/
private function _registerEvents(): void
private function registerEvents(): void
{
// Ignore CP requests
if (Craft::$app->getRequest()->getIsCpRequest()) {
Expand Down Expand Up @@ -112,7 +112,7 @@ function() {
/**
* Registers template roots.
*/
private function _registerTemplateRoots(): void
private function registerTemplateRoots(): void
{
Event::on(
View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS,
Expand All @@ -125,7 +125,7 @@ function(RegisterTemplateRootsEvent $event) {
/**
* Registers utilities
*/
private function _registerUtilities(): void
private function registerUtilities(): void
{
Event::on(Utilities::class, Utilities::EVENT_REGISTER_UTILITIES,
function(RegisterComponentTypesEvent $event) {
Expand Down
34 changes: 17 additions & 17 deletions src/services/HintsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class HintsService extends Component
/**
* @var HintModel[] The hints to be saved for the current request.
*/
private array $_hints = [];
private array $hints = [];

/**
* @var string|null
*/
private ?string $_templateClassFilename = null;
private ?string $templateClassFilename = null;

/**
* Returns the total hints.
Expand Down Expand Up @@ -133,7 +133,7 @@ public function checkElementQuery(ElementQuery $elementQuery): void
return;
}

$this->_addFieldHint($fieldId);
$this->addFieldHint($fieldId);
}
}

Expand All @@ -144,7 +144,7 @@ public function save(): void
{
$db = Craft::$app->getDb();

foreach ($this->_hints as $hint) {
foreach ($this->hints as $hint) {
$db->createCommand()
->upsert(
HintRecord::tableName(),
Expand All @@ -164,7 +164,7 @@ public function save(): void
/**
* Adds a field hint.
*/
private function _addFieldHint(int $fieldId): void
private function addFieldHint(int $fieldId): void
{
$field = Craft::$app->getFields()->getFieldById($fieldId);

Expand All @@ -188,11 +188,11 @@ private function _addFieldHint(int $fieldId): void
$key = implode('-', [$fieldId, $hint->template, $hint->routeVariable]);

// Don’t continue if a hint with the key already exists.
if (!empty($this->_hints[$key])) {
if (!empty($this->hints[$key])) {
return;
}

$this->_hints[$key] = $hint;
$this->hints[$key] = $hint;
}

/**
Expand All @@ -205,12 +205,12 @@ protected function createHintWithTemplateLine(FieldInterface $field): ?HintModel
$traces = debug_backtrace();

foreach ($traces as $key => $trace) {
$template = $this->_getTraceTemplate($trace);
$template = $this->getTraceTemplate($trace);
if ($template) {
$path = $template->getSourceContext()->getPath();
$templatePath = str_replace(Craft::getAlias('@templates/'), '', $path);
$templateCodeLine = $traces[$key - 1]['line'] ?? null;
$line = $this->_findTemplateLine($template, $templateCodeLine);
$line = $this->findTemplateLine($template, $templateCodeLine);

if ($templatePath && $line) {
$hint = new HintModel([
Expand Down Expand Up @@ -241,25 +241,25 @@ protected function createHintWithTemplateLine(FieldInterface $field): ?HintModel
/**
* Returns the template class filename.
*/
private function _getTemplateClassFilename(): string
private function getTemplateClassFilename(): string
{
if ($this->_templateClassFilename !== null) {
return $this->_templateClassFilename;
if ($this->templateClassFilename !== null) {
return $this->templateClassFilename;
}

$reflector = new ReflectionClassAlias(Template::class);
$this->_templateClassFilename = $reflector->getFileName();
$this->templateClassFilename = $reflector->getFileName();

return $this->_templateClassFilename;
return $this->templateClassFilename;
}

/**
* Returns a template from the trace.
*/
private function _getTraceTemplate(array $trace): ?Template
private function getTraceTemplate(array $trace): ?Template
{
// Ensure this is a template class file.
if (empty($trace['file']) || $trace['file'] != $this->_getTemplateClassFilename()) {
if (empty($trace['file']) || $trace['file'] != $this->getTemplateClassFilename()) {
return null;
}

Expand All @@ -282,7 +282,7 @@ private function _getTraceTemplate(array $trace): ?Template
*
* @see Deprecator::_findTemplateLine()
*/
private function _findTemplateLine(Template $template, int $actualCodeLine = null): ?int
private function findTemplateLine(Template $template, int $actualCodeLine = null): ?int
{
if ($actualCodeLine === null) {
return null;
Expand Down

0 comments on commit cbee86a

Please sign in to comment.