@@ -14,28 +14,31 @@ class AdminController extends AdminBaseController
1414 protected $ active ;
1515 protected $ plugin ;
1616 protected $ task_prefix = 'task ' ;
17+
18+ /** @var GitSync */
1719 public $ git ;
1820
1921 /**
20- * @param Plugin $plugin
22+ * @param Plugin $plugin
2123 */
2224 public function __construct (Plugin $ plugin )
2325 {
24- $ post = !empty ($ _POST ) ? $ _POST : [];
2526 $ this ->grav = Grav::instance ();
2627 $ this ->active = false ;
2728 $ uri = $ this ->grav ['uri ' ];
28- $ this ->post = $ this ->getPost ($ post );
2929 $ this ->plugin = $ plugin ;
3030
31+ $ post = !empty ($ _POST ) ? $ _POST : [];
32+ $ this ->post = $ this ->getPost ($ post );
33+
3134 // Ensure the controller should be running
3235 if (Utils::isAdminPlugin ()) {
3336 $ routeDetails = $ this ->grav ['admin ' ]->getRouteDetails ();
3437 $ target = array_pop ($ routeDetails );
35- $ this ->git = new GitSync ($ plugin );
38+ $ this ->git = new GitSync ();
3639
3740 // return null if this is not running
38- if ($ target != $ plugin ->name ) {
41+ if ($ target !== $ plugin ->name ) {
3942 return ;
4043 }
4144
@@ -45,7 +48,7 @@ public function __construct(Plugin $plugin)
4548 $ this ->admin = Grav::instance ()['admin ' ];
4649
4750 $ task = !empty ($ post ['task ' ]) ? $ post ['task ' ] : $ uri ->param ('task ' );
48- if ($ task && ($ this ->target == $ plugin ->name || $ uri ->route () == '/lessons ' )) {
51+ if ($ task && ($ this ->target === $ plugin ->name || $ uri ->route () = == '/lessons ' )) {
4952 $ this ->task = $ task ;
5053 $ this ->active = true ;
5154 }
@@ -54,19 +57,20 @@ public function __construct(Plugin $plugin)
5457
5558 public function taskTestConnection ()
5659 {
57- $ post = $ this ->post ;
58- $ data = json_decode (base64_decode ($ post ['test ' ]));
60+ $ post = $ this ->post ;
61+ $ test = base64_decode ($ post ['test ' ]) ?: null ;
62+ $ data = $ test ? json_decode ($ test , false ) : new \stdClass ();
5963
6064 try {
6165 Helper::testRepository ($ data ->user , $ data ->password , $ data ->repository );
6266 echo json_encode ([
63- 'status ' => " success " ,
67+ 'status ' => ' success ' ,
6468 'message ' => 'The connection to the repository has been successful. '
6569 ]);
6670 } catch (\Exception $ e ) {
6771 $ invalid = str_replace ($ data ->password , '{password} ' , $ e ->getMessage ());
6872 echo json_encode ([
69- 'status ' => " error " ,
73+ 'status ' => ' error ' ,
7074 'message ' => $ invalid
7175 ]);
7276 }
@@ -79,13 +83,13 @@ public function taskSynchronize()
7983 try {
8084 $ this ->plugin ->synchronize ();
8185 echo json_encode ([
82- 'status ' => " success " ,
86+ 'status ' => ' success ' ,
8387 'message ' => 'GitSync has successfully synchronized with the repository. '
8488 ]);
8589 } catch (\Exception $ e ) {
8690 $ invalid = str_replace ($ this ->git ->getConfig ('password ' , null ), '{password} ' , $ e ->getMessage ());
8791 echo json_encode ([
88- 'status ' => " error " ,
92+ 'status ' => ' error ' ,
8993 'message ' => $ invalid
9094 ]);
9195 }
@@ -98,13 +102,13 @@ public function taskResetLocal()
98102 try {
99103 $ this ->plugin ->reset ();
100104 echo json_encode ([
101- 'status ' => " success " ,
105+ 'status ' => ' success ' ,
102106 'message ' => 'GitSync has successfully reset your local changes and synchronized with the repository. '
103107 ]);
104108 } catch (\Exception $ e ) {
105109 $ invalid = str_replace ($ this ->git ->getConfig ('password ' , null ), '{password} ' , $ e ->getMessage ());
106110 echo json_encode ([
107- 'status ' => " error " ,
111+ 'status ' => ' error ' ,
108112 'message ' => $ invalid
109113 ]);
110114 }
@@ -115,11 +119,10 @@ public function taskResetLocal()
115119 /**
116120 * Performs a task or action on a post or target.
117121 *
118- * @return bool|mixed
122+ * @return bool
119123 */
120124 public function execute ()
121125 {
122- $ success = false ;
123126 $ params = [];
124127
125128 // Handle Task & Action
@@ -142,10 +145,10 @@ public function execute()
142145 return false ;
143146 }
144147
145- $ success = call_user_func_array ([ $ this , $ method], $ params );
148+ $ success = $ this ->{ $ method}(... $ params );
146149
147150 // Grab redirect parameter.
148- $ redirect = isset ( $ this ->post ['_redirect ' ]) ? $ this -> post [ ' _redirect ' ] : null ;
151+ $ redirect = $ this ->post ['_redirect ' ] ?? null ;
149152 unset($ this ->post ['_redirect ' ]);
150153
151154 // Redirect if requested.
@@ -156,6 +159,9 @@ public function execute()
156159 return $ success ;
157160 }
158161
162+ /**
163+ * @return bool
164+ */
159165 public function isActive ()
160166 {
161167 return (bool ) $ this ->active ;
0 commit comments