| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 85.71% covered (warning) | 85.71% | 6 / 7 | CRAP | 92.86% covered (success) | 92.86% | 13 / 14
AModule | 0.00% covered (danger) | 0.00% | 0 / 1 | 90.00% covered (success) | 90.00% | 9 / 10 | 14.07 | 92.86% covered (success) | 92.86% | 13 / 14
install | 100.00% covered (success) | 100.00% | 1 / 1 | 1 |  |  |
uninstall | 0.00% covered (danger) | 0.00% | 0 / 1 | 2 | 0.00% covered (danger) | 0.00% | 0 / 1
doAction | 100.00% covered (success) | 100.00% | 1 / 1 | 1 |  |  |
doShortCode | 100.00% covered (success) | 100.00% | 1 / 1 | 1 |  |  |
setContext | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 3 / 3
setEntity | 100.00% covered (success) | 100.00% | 1 / 1 | 2 | 100.00% covered (success) | 100.00% | 3 / 3
registerHook | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 2 / 2
getName | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 1 / 1
getDescription | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 1 / 1
__get | 100.00% covered (success) | 100.00% | 1 / 1 | 3 | 100.00% covered (success) | 100.00% | 3 / 3

1 | <?php
2 |
3 | namespace Tools;
4 |
5 | /**
6 | * Module superclass
7 | * Contains all informations about the module
8 | **/
9 | abstract class AModule
10 | {
11 | /**
12 | * @var \Tools\Context $context
13 | * /core/tools/Context.php
14 | * Website context
15 | * Can be accessed read-only
16 | **/
17 | private $context;
18 |
19 | /**
20 | * @var Module database object
21 | **/
22 | private $entity;
23 |
24 | /**
25 | * Called on module install
26 | * Should register shortcodes and Hooks
27 | **/
28 | public abstract function install();
29 |
30 | /**
31 | * Called on module unsinstall
32 | **/
33 | public function uninstall()
34 | { }
35 |
36 | /**
37 | * @param \Tools\HookEvent $event called hook
38 | * /core/tools/HookEvent.php
39 | * Called on hook reception
40 | **/
41 | public abstract function doAction($event);
42 |
43 | /**
44 | * @param string $shortCode
45 | * @param array ( key => value ) shortcode's parameters
46 | * Called on shortcode reception
47 | **/
48 | public abstract function doShortCode($shortCode, $params);
49 |
50 | /**
51 | * @param \Tools\Context $context
52 | * /core/tools/Context.php
53 | * set the application context
54 | * Will work only one time
55 | **/
56 | public function setContext($context)
57 | {
58 | if ($this->context === null)
59 | $this->context = $context;
60 | }
61 |
62 | /**
63 | * @param \Entity\Module $module
64 | * /core/models/Module.php
65 | * set the module database object
66 | * Will work only one time
67 | **/
68 | public function setEntity($entity)
69 | {
70 | if ($this->entity === null)
71 | $this->entity = $entity;
72 | }
73 |
74 | /**
75 | * Register hook to be triggered
76 | * Can only be triggered while module setup
77 | **/
78 | public function registerHook($hookName)
79 | {
80 | $this->context->hookManager->register($this, $hookName);
81 | }
82 |
83 | /**
84 | * @return string module name
85 | **/
86 | public function getName()
87 | {
88 | return $this->entity->name;
89 | }
90 |
91 | /**
92 | * @return string module's description
93 | **/
94 | public function getDescription()
95 | { return ""; }
96 |
97 | /**
98 | * Getter
99 | **/
100 | public function __get($key)
101 | {
102 | switch ($key)
103 | {
104 | case "context": return $this->context; break;
105 | case "entity": return $this->entity; break;
106 | }
107 | throw new \Exception("Cannot access attribute {$key}");
108 | }
109 | }
110 |