Base::getClasses()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Foundation\Plugin;
13
14
/**
15
 * Plugin Base class.
16
 */
17
abstract class Base extends \Jitamin\Foundation\Base
18
{
19
    /**
20
     * Method called for each request.
21
     *
22
     * @abstract
23
     */
24
    abstract public function initialize();
25
26
    /**
27
     * Override default CSP rules.
28
     *
29
     * @param array $rules
30
     */
31
    public function setContentSecurityPolicy(array $rules)
32
    {
33
        $this->container['cspRules'] = $rules;
34
    }
35
36
    /**
37
     * Returns all classes that needs to be stored in the DI container.
38
     *
39
     * @return array
40
     */
41
    public function getClasses()
42
    {
43
        return [];
44
    }
45
46
    /**
47
     * Returns all helper classes that needs to be stored in the DI container.
48
     *
49
     * @return array
50
     */
51
    public function getHelpers()
52
    {
53
        return [];
54
    }
55
56
    /**
57
     * Listen on internal events.
58
     *
59
     * @param string   $event
60
     * @param callable $callback
61
     */
62
    public function on($event, $callback)
63
    {
64
        $container = $this->container;
65
66
        $this->dispatcher->addListener($event, function () use ($container, $callback) {
0 ignored issues
show
Documentation introduced by
The property dispatcher does not exist on object<Jitamin\Foundation\Plugin\Base>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
67
            call_user_func($callback, $container);
68
        });
69
    }
70
71
    /**
72
     * Get plugin name.
73
     *
74
     * This method should be overridden by your Plugin class
75
     *
76
     * @return string
77
     */
78
    public function getPluginName()
79
    {
80
        return ucfirst(substr(get_called_class(), 15, -7));
81
    }
82
83
    /**
84
     * Get plugin description.
85
     *
86
     * This method should be overridden by your Plugin class
87
     *
88
     * @return string
89
     */
90
    public function getPluginDescription()
91
    {
92
        return '';
93
    }
94
95
    /**
96
     * Get plugin author.
97
     *
98
     * This method should be overridden by your Plugin class
99
     *
100
     * @return string
101
     */
102
    public function getPluginAuthor()
103
    {
104
        return '?';
105
    }
106
107
    /**
108
     * Get plugin version.
109
     *
110
     * This method should be overridden by your Plugin class
111
     *
112
     * @return string
113
     */
114
    public function getPluginVersion()
115
    {
116
        return '?';
117
    }
118
119
    /**
120
     * Get plugin homepage.
121
     *
122
     * This method should be overridden by your Plugin class
123
     *
124
     * @return string
125
     */
126
    public function getPluginHomepage()
127
    {
128
        return '';
129
    }
130
}
131