Issues (29)

plugins/mycompany/demoPlugin/Classes/Plugin.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Plugin class
4
 */
5
6
/*
7
 * The namespace structure is Phile\Plugin\<vendor>\<plugin-name>
8
 *
9
 * - the namespace always starts with Phile\Plugin
10
 * - the vendor name in lowercase is the folder name under plugins directory
11
 * - the sub-folder in lowerCamelCase is the plugin name
12
 *
13
 * So if your folder is: plugins/mycompany/myPluginName/
14
 * then your namespace should be: Phile\Plugin\Mycompany\MyPluginName
15
 */
16
namespace Phile\Plugin\Mycompany\DemoPlugin;
17
18
// import useful Phile classes for easy access
19
use Phile\Core\Response;
20
use Phile\Core\Session;
21
use Phile\Core\Utility;
22
23
/**
24
 * Class Plugin - the class name is always "Plugin"
25
 *
26
 * @author  PhileCMS
27
 * @license http://opensource.org/licenses/MIT
28
 */
29
class Plugin extends \Phile\Plugin\AbstractPlugin
30
{
31
    /**
32
     * subscribe to Phile events with methods of this class
33
     *
34
     * In this example we subscribe to "before_parse_content" and
35
     * "outputPluginSettings" will be called.
36
     */
37
    protected $events = [
38
        'before_parse_content' => 'outputPluginSettings'
39
    ];
40
41
    /**
42
     * the method we assigned to the 'before_parse_content' event
43
     *
44
     * in this example we output this plugins' settings on the top of every
45
     * page
46
     *
47
     * @param null|array $data depends on the particular event (see Phile's
48
     *     event docs)
49
     */
50
    public function outputPluginSettings($data = null)
51
    {
52
        // you can access this plugins' config in $this->settings
53
        $settings = $this->settings;
54
55
        $content = $data['content'];
56
        $content = $this->printPhpAsMarkdown($settings) . $content;
57
58
        $page = $data['page'];
59
        $page->setContent($content);
60
    }
61
62
    /**
63
     * plugin helper method for printing PHP as markdown code
64
     */
65
    protected function printPhpAsMarkdown($input)
66
    {
67
        return "\n```php\n" . trim(print_r($input, true), "\n") . "\n```\n";
0 ignored issues
show
It seems like print_r($input, true) can also be of type true; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        return "\n```php\n" . trim(/** @scrutinizer ignore-type */ print_r($input, true), "\n") . "\n```\n";
Loading history...
68
    }
69
}
70