Completed
Push — master ( f813e0...5f1c56 )
by Thierry
03:59 queued 02:07
created

Plugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerPlugin() 0 4 1
A registerRequestPlugins() 0 7 1
A registerResponsePlugins() 0 5 1
1
<?php
2
3
/**
4
 * Sentry.php - Upload Trait
5
 *
6
 * The Jaxon class uses a modular plug-in system to facilitate the processing
7
 * of special Ajax requests made by a PHP page.
8
 * It generates Javascript that the page must include in order to make requests.
9
 * It handles the output of response commands (see <Jaxon\Response\Response>).
10
 * Many flags and settings can be adjusted to effect the behavior of the Jaxon class
11
 * as well as the client-side javascript.
12
 *
13
 * @package jaxon-core
14
 * @author Thierry Feuzeu <[email protected]>
15
 * @copyright 2017 Thierry Feuzeu <[email protected]>
16
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
17
 * @link https://github.com/jaxon-php/jaxon-core
18
 */
19
20
namespace Jaxon\Traits;
21
22
use Jaxon\Utils\Container;
23
24
trait Plugin
25
{
26
    /**
27
     * Register a plugin
28
     *
29
     * Below is a table for priorities and their description:
30
     * - 0 thru 999: Plugins that are part of or extensions to the jaxon core
31
     * - 1000 thru 8999: User created plugins, typically, these plugins don't care about order
32
     * - 9000 thru 9999: Plugins that generally need to be last or near the end of the plugin list
33
     *
34
     * @param Plugin         $xPlugin               An instance of a plugin
0 ignored issues
show
introduced by
The type Plugin for parameter $xPlugin is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
35
     * @param integer        $nPriority             The plugin priority, used to order the plugins
36
     *
37
     * @return void
38
     */
39
    public function registerPlugin(\Jaxon\Plugin\Plugin $xPlugin, $nPriority = 1000)
40
    {
41
        $this->getPluginManager()->registerPlugin($xPlugin, $nPriority);
0 ignored issues
show
Bug introduced by
It seems like getPluginManager() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
42
    }
43
44
    /**
45
     * Register the Jaxon request plugins
46
     *
47
     * @return void
48
     */
49
    public function registerRequestPlugins()
50
    {
51
        $this->registerPlugin(new \Jaxon\Request\Plugin\CallableObject(), 101);
52
        $this->registerPlugin(new \Jaxon\Request\Plugin\UserFunction(), 102);
53
        $this->registerPlugin(new \Jaxon\Request\Plugin\BrowserEvent(), 103);
54
        $this->registerPlugin(new \Jaxon\Request\Plugin\FileUpload(), 104);
55
    }
56
57
    /**
58
     * Register the Jaxon response plugins
59
     *
60
     * @return void
61
     */
62
    public function registerResponsePlugins()
63
    {
64
        // Register an instance of the JQuery plugin
65
        $this->registerPlugin(new \Jaxon\JQuery\Plugin(), 700);
66
    }
67
}
68