Completed
Push — feature/code-analysis ( 1158f1...5e4834 )
by Jonathan
03:51
created
src/Webtrees/Hook/HookProvider.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -70,34 +70,34 @@  discard block
 block discarded – undo
70 70
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getPossibleHooks()
71 71
 	 */
72 72
 	public function getPossibleHooks() {
73
-		static $hooks=null;
73
+		static $hooks = null;
74 74
 		if ($hooks === null) {
75 75
 		    $hooks = array();
76
-		    foreach (glob(WT_ROOT . WT_MODULES_DIR . '*/module.php') as $file) {
76
+		    foreach (glob(WT_ROOT.WT_MODULES_DIR.'*/module.php') as $file) {
77 77
 		        try {
78 78
 		            $module = include $file;
79
-		            if($module instanceof HookSubscriberInterface){
79
+		            if ($module instanceof HookSubscriberInterface) {
80 80
 						$subscribedhooks = $module->getSubscribedHooks();
81
-						if(is_array($subscribedhooks)){
82
-							foreach($subscribedhooks as $key => $value){
83
-								if(is_int($key)) {
81
+						if (is_array($subscribedhooks)) {
82
+							foreach ($subscribedhooks as $key => $value) {
83
+								if (is_int($key)) {
84 84
 									$hook_item = $value;
85 85
 									$priority = self::DEFAULT_PRIORITY;
86 86
 								}
87
-								else{
87
+								else {
88 88
 									$hook_item = explode('#', $key, 2);
89 89
 									$priority = $value;
90 90
 								}
91
-								if($hook_item && count($hook_item) == 2){
91
+								if ($hook_item && count($hook_item) == 2) {
92 92
 									$hook_func = $hook_item[0];
93 93
 									$hook_cont = $hook_item[1];
94 94
 								}
95
-								else{
95
+								else {
96 96
 									$hook_func = $hook_item[0];
97 97
 									$hook_cont = 'all';
98 98
 								}
99
-								if(method_exists($module, $hook_func)){
100
-									$hooks[$module->getName().'#'.$hook_func.'#'.$hook_cont]=$priority;
99
+								if (method_exists($module, $hook_func)) {
100
+									$hooks[$module->getName().'#'.$hook_func.'#'.$hook_cont] = $priority;
101 101
 								}
102 102
 							}
103 103
 						}
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * {@inheritDoc}
115 115
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getRawInstalledHooks()
116 116
 	 */
117
-	public function getRawInstalledHooks(){
118
-		if(self::isModuleOperational()){
117
+	public function getRawInstalledHooks() {
118
+		if (self::isModuleOperational()) {
119 119
 			return fw\Database::prepare(
120 120
 					"SELECT majh_id AS id, majh_module_name AS module, majh_hook_function AS hook, majh_hook_context as context, majh_module_priority AS priority,  majh_status AS status".
121 121
 					" FROM `##maj_hooks`".
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
 	 * {@inheritDoc}
130 130
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getInstalledHooks()
131 131
 	 */
132
-	public function getInstalledHooks(){
133
-		static $installedhooks =null;
134
-		if($installedhooks===null){
135
-			$dbhooks=self::getRawInstalledHooks();
136
-			foreach($dbhooks as $dbhook){
132
+	public function getInstalledHooks() {
133
+		static $installedhooks = null;
134
+		if ($installedhooks === null) {
135
+			$dbhooks = self::getRawInstalledHooks();
136
+			foreach ($dbhooks as $dbhook) {
137 137
 				$installedhooks[($dbhook->module).'#'.($dbhook->hook).'#'.($dbhook->context)] = array('id' => $dbhook->id, 'status' => $dbhook->status, 'priority' => $dbhook->priority);
138 138
 			}
139 139
 		}
@@ -146,15 +146,15 @@  discard block
 block discarded – undo
146 146
 	 */
147 147
 	public function updateHooks() {
148 148
 	    
149
-	    if(Auth::isAdmin()){
149
+	    if (Auth::isAdmin()) {
150 150
 	        $ihooks = self::getInstalledHooks();
151 151
 	        $phooks = self::getPossibleHooks();
152 152
 	        	
153 153
 	        // Insert hooks not existing yet in the DB
154
-	        if($phooks !== null){
155
-	            foreach($phooks as $phook => $priority){
154
+	        if ($phooks !== null) {
155
+	            foreach ($phooks as $phook => $priority) {
156 156
 	                $array_hook = explode('#', $phook);
157
-	                if($ihooks === null || !array_key_exists($phook, $ihooks)){
157
+	                if ($ihooks === null || !array_key_exists($phook, $ihooks)) {
158 158
 	                    $chook = new Hook($array_hook[1], $array_hook[2]);
159 159
 	                    $chook->subscribe($array_hook[0]);
160 160
 	                    $chook->setPriority($array_hook[0], $priority);
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 	        }
164 164
 	        	
165 165
 	        //Remove hooks not existing any more in the file system
166
-	        if($ihooks !== null){
167
-	            foreach($ihooks as $ihook => $status){
166
+	        if ($ihooks !== null) {
167
+	            foreach ($ihooks as $ihook => $status) {
168 168
 	                $array_hook = explode('#', $ihook);
169
-	                if($phooks === null || !array_key_exists($ihook, $phooks)){
169
+	                if ($phooks === null || !array_key_exists($ihook, $phooks)) {
170 170
 	                    $chook = new Hook($array_hook[1], $array_hook[2]);
171 171
 	                    $chook->remove($array_hook[0]);
172 172
 	                }
Please login to merge, or discard this patch.
src/Webtrees/Hook/Hook.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * @param string $hook_function_in Hook function to be subscribed or executed
31 31
 	 * @param string $hook_context_in Hook context to be subscribed or executed
32 32
 	 */
33
-	public function __construct($hook_function_in, $hook_context_in = 'all'){
33
+	public function __construct($hook_function_in, $hook_context_in = 'all') {
34 34
 		$this->hook_function = $hook_function_in;
35 35
 		$this->hook_context = $hook_context_in;
36 36
 	}
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @param string $hsubscriber Name of the subscriber module
48 48
 	 */
49
-	public function subscribe($hsubscriber){
50
-		if(HookProvider::getInstance()->isModuleOperational()){
49
+	public function subscribe($hsubscriber) {
50
+		if (HookProvider::getInstance()->isModuleOperational()) {
51 51
 			$statement = fw\Database::prepare(
52 52
 					"INSERT IGNORE INTO `##maj_hooks` (majh_hook_function, majh_hook_context, majh_module_name)".
53 53
 					" VALUES (?, ?, ?)"
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @param string $hsubscriber Name of the subscriber module
62 62
 	 * @param int $priority Priority of execution
63 63
 	 */
64
-	public function setPriority($hsubscriber, $priority){
65
-		if(HookProvider::getInstance()->isModuleOperational()){
64
+	public function setPriority($hsubscriber, $priority) {
65
+		if (HookProvider::getInstance()->isModuleOperational()) {
66 66
 			fw\Database::prepare(
67 67
 			"UPDATE `##maj_hooks`".
68 68
 			" SET majh_module_priority=?".
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param string $hsubscriber Name of the subscriber module
80 80
 	 */
81
-	public function enable($hsubscriber){
82
-		if(HookProvider::getInstance()->isModuleOperational()){
81
+	public function enable($hsubscriber) {
82
+		if (HookProvider::getInstance()->isModuleOperational()) {
83 83
 		fw\Database::prepare(
84 84
 			"UPDATE `##maj_hooks`".
85 85
 			" SET majh_status='enabled'".
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	 *
96 96
 	 * @param string $hsubscriber Name of the subscriber module
97 97
 	 */
98
-	public function disable($hsubscriber){
99
-		if(HookProvider::getInstance()->isModuleOperational()){
98
+	public function disable($hsubscriber) {
99
+		if (HookProvider::getInstance()->isModuleOperational()) {
100 100
 		fw\Database::prepare(
101 101
 			"UPDATE `##maj_hooks`".
102 102
 			" SET majh_status='disabled'".
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @param string $hsubscriber Name of the subscriber module
114 114
 	 */
115
-	public function remove($hsubscriber){
116
-		if(HookProvider::getInstance()->isModuleOperational()){
115
+	public function remove($hsubscriber) {
116
+		if (HookProvider::getInstance()->isModuleOperational()) {
117 117
 		fw\Database::prepare(
118 118
 			"DELETE FROM `##maj_hooks`".
119 119
 			" WHERE majh_hook_function=?".
@@ -135,24 +135,24 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @return array Results of the hook executions
137 137
 	 */
138
-	public function execute(){
138
+	public function execute() {
139 139
 		$result = array();
140
-		if(HookProvider::getInstance()->isModuleOperational()){
140
+		if (HookProvider::getInstance()->isModuleOperational()) {
141 141
 			$params = func_get_args();
142 142
 			$sqlquery = '';
143 143
 			$sqlparams = array($this->hook_function);
144
-			if($this->hook_context != 'all') {
144
+			if ($this->hook_context != 'all') {
145 145
 				$sqlparams = array($this->hook_function, $this->hook_context);
146 146
 				$sqlquery = " OR majh_hook_context=?";
147 147
 			}
148
-			$module_names=fw\Database::prepare(
148
+			$module_names = fw\Database::prepare(
149 149
 					"SELECT majh_module_name AS module, majh_module_priority AS priority FROM `##maj_hooks`".
150 150
 					" WHERE majh_hook_function = ? AND (majh_hook_context='all'".$sqlquery.") AND majh_status='enabled'".
151 151
 					" ORDER BY majh_module_priority ASC, module ASC"
152 152
 			)->execute($sqlparams)->fetchAssoc();
153 153
 			asort($module_names);
154 154
 			foreach ($module_names as $module_name => $module_priority) {
155
-				$module = include WT_ROOT . WT_MODULES_DIR . $module_name . '/module.php';
155
+				$module = include WT_ROOT.WT_MODULES_DIR.$module_name.'/module.php';
156 156
 				$result[] = call_user_func_array(array($module, $this->hook_function), $params);
157 157
 			}
158 158
 		}
@@ -164,15 +164,15 @@  discard block
 block discarded – undo
164 164
 	 *
165 165
 	 * @return int Number of active modules
166 166
 	 */
167
-	public function getNumberActiveModules(){
168
-		if(HookProvider::getInstance()->isModuleOperational()){
167
+	public function getNumberActiveModules() {
168
+		if (HookProvider::getInstance()->isModuleOperational()) {
169 169
 			$sqlquery = '';
170 170
 			$sqlparams = array($this->hook_function);
171
-			if($this->hook_context != 'all') {
171
+			if ($this->hook_context != 'all') {
172 172
 				$sqlparams = array($this->hook_function, $this->hook_context);
173 173
 				$sqlquery = " OR majh_hook_context=?";
174 174
 			}
175
-			$module_names=fw\Database::prepare(
175
+			$module_names = fw\Database::prepare(
176 176
 					"SELECT majh_module_name AS modules FROM `##maj_hooks`".
177 177
 					" WHERE majh_hook_function = ? AND (majh_hook_context='all'".$sqlquery.") AND majh_status='enabled'"
178 178
 			)->execute($sqlparams)->fetchOneColumn();
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 	 *
187 187
 	 * @return bool True is active modules exist, false otherwise
188 188
 	 */
189
-	public function hasAnyActiveModule(){
190
-		return ($this->getNumberActiveModules()>0);
189
+	public function hasAnyActiveModule() {
190
+		return ($this->getNumberActiveModules() > 0);
191 191
 	}
192 192
 
193 193
 }
Please login to merge, or discard this patch.
src/Webtrees/Controller/IndividualController.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \Fisharebest\Webtrees\Controller\IndividualController $ctrl_individual_in The Individual Controller to extend
34 34
 	 */
35
-	public function __construct(fw\Controller\IndividualController $ctrl_individual_in){
35
+	public function __construct(fw\Controller\IndividualController $ctrl_individual_in) {
36 36
 		$this->ctrl_individual = $ctrl_individual_in;
37 37
 		$this->dindi = new mw\Individual($this->ctrl_individual->getSignificantIndividual());
38 38
 	}
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * 
44 44
 	 * @uses \MyArtJaub\Webtrees\Hook\Hook
45 45
 	 */
46
-	public function printHeaderExtensions(){
46
+	public function printHeaderExtensions() {
47 47
 		$hook_extend_indi_header_left = new mw\Hook\Hook('hExtendIndiHeaderLeft');
48 48
 		$hook_extend_indi_header_right = new mw\Hook\Hook('hExtendIndiHeaderRight');
49 49
 		$hook_extend_indi_header_left = $hook_extend_indi_header_left->execute($this->ctrl_individual);
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		echo '<div id="indi_perso_header">',
53 53
 			'<div id="indi_perso_header_left">';
54 54
 		foreach ($hook_extend_indi_header_left as $div) {
55
-			if(count($div)==2){
55
+			if (count($div) == 2) {
56 56
 				echo '<div id="', $div[0], '" class="indi_perso_header_left_div">',
57 57
 					$div[1], '</div>';
58 58
 			}
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 		echo '</div>',
61 61
 			'<div id="indi_perso_header_right">';
62 62
 		foreach ($hook_extend_indi_header_right as $div) {
63
-			if(count($div)==2){
63
+			if (count($div) == 2) {
64 64
 				echo '<div id="', $div[0], '" class="indi_perso_header_right_div">',
65 65
 					$div[1], '</div>';
66 66
 			}
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @uses \MyArtJaub\Webtrees\Hook\Hook
77 77
 	 */
78
-	public function printHeaderExtraIcons(){
78
+	public function printHeaderExtraIcons() {
79 79
 		$hook_extend_indi_header_icons = new Hook('hExtendIndiHeaderIcons');
80 80
 		$hook_extend_indi_header_icons = $hook_extend_indi_header_icons->execute($this->ctrl_individual);
81 81
 		
Please login to merge, or discard this patch.