TwigProfiler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 27
c 2
b 0
f 0
dl 0
loc 87
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createSettingsModel() 0 3 1
A init() 0 31 3
1
<?php
2
/**
3
 * Twig Profiler plugin for Craft CMS
4
 *
5
 * Twig Profiler allows you to profile sections of your Twig templates, and see
6
 * the resulting timings in the Yii2 Debug Toolbar
7
 *
8
 * @link      https://nystudio107.com/
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
9
 * @copyright Copyright (c) nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
10
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
11
12
namespace nystudio107\twigprofiler;
13
14
use Craft;
15
use craft\base\Plugin;
16
use craft\events\TemplateEvent;
17
use craft\web\View;
18
use nystudio107\twigprofiler\models\Settings;
19
use nystudio107\twigprofiler\services\ServicesTrait;
20
use nystudio107\twigprofiler\twigextensions\ProfilerTwigExtension;
21
use yii\base\Event;
22
23
/**
24
 * Class TwigProfiler
25
 *
26
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
27
 * @package   TwigProfiler
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
28
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
29
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
30
class TwigProfiler extends Plugin
31
{
32
    // Traits
33
    // =========================================================================
34
35
    use ServicesTrait;
36
37
    // Public Static Properties
38
    // =========================================================================
39
40
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
     * @var ?TwigProfiler
42
     */
43
    public static ?TwigProfiler $plugin = null;
44
45
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
46
     * @var string The name of the rendering template
47
     */
48
    public static string $renderingTemplate = '';
49
50
    // Public Properties
51
    // =========================================================================
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
     * @var string
55
     */
56
    public string $schemaVersion = '1.0.0';
57
58
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
59
     * @var bool
60
     */
61
    public bool $hasCpSection = false;
62
63
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
64
     * @var bool
65
     */
66
    public bool $hasCpSettings = false;
67
68
    // Public Methods
69
    // =========================================================================
70
71
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
72
     * @inheritdoc
73
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
74
    public function init(): void
75
    {
76
        parent::init();
77
        self::$plugin = $this;
78
79
        /** @var Settings $settings */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
80
        $settings = $this->getSettings();
81
        Craft::$app->view->registerTwigExtension(new ProfilerTwigExtension());
82
83
        if ($settings !== null && $settings->appendTemplateName) {
84
            // Handler: View::EVENT_BEFORE_RENDER_TEMPLATE
85
            Event::on(
86
                View::class,
87
                View::EVENT_BEFORE_RENDER_TEMPLATE,
88
                static function(TemplateEvent $event): void {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
89
                    Craft::debug(
90
                        'View::EVENT_BEFORE_RENDER_TEMPLATE',
91
                        __METHOD__
92
                    );
93
                    self::$renderingTemplate = ' - ' . $event->template;
94
                }
95
            );
96
        }
97
98
        Craft::info(
99
            Craft::t(
100
                'twig-profiler',
101
                '{name} plugin loaded',
102
                ['name' => $this->name]
103
            ),
104
            __METHOD__
105
        );
106
    }
107
108
    // Protected Methods
109
    // =========================================================================
110
111
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
112
     * @inheritdoc
113
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
114
    protected function createSettingsModel(): Settings
115
    {
116
        return new Settings();
117
    }
118
}
119