@@ -14,18 +14,18 @@ class Access {
1414 *
1515 * @param \Elgg\Event $event 'access:collections:write', 'all'
1616 *
17- * @return array
17+ * @return null| array
1818 */
19- public static function setWriteAccess (\Elgg \Event $ event ) {
19+ public static function setWriteAccess (\Elgg \Event $ event ): ? array {
2020
2121 $ input_params = $ event ->getParam ('input_params ' , []);
2222 if (elgg_extract ('entity_type ' , $ input_params ) !== 'object ' || elgg_extract ('entity_subtype ' , $ input_params ) !== 'widget ' ) {
23- return ;
23+ return null ;
2424 }
2525
2626 $ container = get_entity (elgg_extract ('container_guid ' , $ input_params ));
2727 if (!$ container instanceof \ElggEntity) {
28- return ;
28+ return null ;
2929 }
3030
3131 if ($ container instanceof \ElggGroup) {
@@ -42,7 +42,7 @@ public static function setWriteAccess(\Elgg\Event $event) {
4242
4343 $ widget = elgg_extract ('entity ' , $ input_params );
4444 if (!$ widget instanceof \ElggWidget) {
45- return ;
45+ return null ;
4646 }
4747
4848 if (elgg_can_edit_widget_layout ($ widget ->context )) {
@@ -54,59 +54,54 @@ public static function setWriteAccess(\Elgg\Event $event) {
5454 ];
5555 }
5656 }
57+
58+ return null ;
5759 }
5860
5961 /**
6062 * Allow write access for index managers
6163 *
6264 * @param \Elgg\Event $event 'permissions_check', 'site'
6365 *
64- * @return array
66+ * @return null|bool
6567 */
66- public static function writeAccessForIndexManagers (\Elgg \Event $ event ) {
68+ public static function writeAccessForIndexManagers (\Elgg \Event $ event ): ? bool {
6769 $ result = $ event ->getValue ();
68-
6970 if ($ result ) {
70- return ;
71+ return $ result ;
7172 }
7273
7374 $ entity = $ event ->getEntityParam ();
7475 if (!$ entity instanceof \ElggSite) {
75- return ;
76+ return null ;
7677 }
7778
7879 $ user = $ event ->getUserParam ();
7980 if (!$ user instanceof \ElggUser) {
80- return ;
81+ return null ;
8182 }
8283
8384 $ index_managers = explode (', ' , elgg_get_plugin_setting ('index_managers ' , 'widget_manager ' , '' ));
84- if (in_array ($ user ->guid , $ index_managers )) {
85- return true ;
86- }
85+ return in_array ($ user ->guid , $ index_managers ) ?: null ;
8786 }
8887
8988 /**
9089 * Creates the ability to see content only for logged_out users
9190 *
9291 * @param \Elgg\Event $event 'access:collections:read', 'user'
9392 *
94- * @return array
93+ * @return null| array
9594 */
96- public static function addLoggedOutReadAccess (\Elgg \Event $ event ) {
95+ public static function addLoggedOutReadAccess (\Elgg \Event $ event ): ? array {
9796
9897 if (elgg_is_logged_in () && !elgg_is_admin_logged_in ()) {
99- return ;
98+ return null ;
10099 }
101100
102- $ return_value = $ event ->getValue ();
101+ $ return_value = $ event ->getValue () ?: [] ;
103102
104- if (empty ($ return_value )) {
105- $ return_value = [];
106- } else {
107- if (!is_array ($ return_value )) {
108- $ return_value = [$ return_value ];
109- }
103+ if (!is_array ($ return_value )) {
104+ $ return_value = [$ return_value ];
110105 }
111106
112107 $ return_value [] = ACCESS_LOGGED_OUT ;
@@ -119,25 +114,23 @@ public static function addLoggedOutReadAccess(\Elgg\Event $event) {
119114 *
120115 * @param \Elgg\Event $event 'permissions_check', 'object'
121116 *
122- * @return boolean
117+ * @return null|bool
123118 */
124- public static function canEditWidgetOnManagedLayout (\Elgg \Event $ event ) {
119+ public static function canEditWidgetOnManagedLayout (\Elgg \Event $ event ): ? bool {
125120 $ user = $ event ->getUserParam ();
126121 $ entity = $ event ->getEntityParam ();
127122
128123 if ($ event ->getValue () || !$ user instanceof \ElggUser || !$ entity instanceof \ElggWidget) {
129- return ;
124+ return null ;
130125 }
131126
132127 if (!$ entity ->getOwnerEntity () instanceof \ElggSite) {
133128 // special permission is only for widget owned by site
134- return ;
129+ return null ;
135130 }
136131
137132 $ context = $ entity ->context ;
138- if ($ context ) {
139- return elgg_can_edit_widget_layout ($ context , $ user ->guid );
140- }
133+ return $ context ? elgg_can_edit_widget_layout ($ context , $ user ->guid ) : null ;
141134 }
142135
143136 /**
@@ -147,7 +140,7 @@ public static function canEditWidgetOnManagedLayout(\Elgg\Event $event) {
147140 *
148141 * @return void
149142 */
150- public static function moreRightsForWidgetManager (\Elgg \Event $ event ) {
143+ public static function moreRightsForWidgetManager (\Elgg \Event $ event ): void {
151144 if ($ event ->getType () === 'widgets/add ' ) {
152145 elgg_register_event_handler ('permissions_check ' , 'site ' , '\ColdTrick\WidgetManager\Access::writeAccessForIndexManagers ' );
153146 return ;
@@ -171,7 +164,7 @@ public static function moreRightsForWidgetManager(\Elgg\Event $event) {
171164 elgg_register_event_handler ('get_sql ' , 'access ' , function (\Elgg \Event $ event ) use ($ widget_guid ) {
172165 if ($ event ->getParam ('ignore_access ' )) {
173166 // no need to give extra access
174- return ;
167+ return null ;
175168 }
176169
177170 /**
0 commit comments