From cb3225e8154bc92af68985f0c7b0dee16d1a10b0 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 3 Aug 2025 02:31:48 +0800 Subject: [PATCH] refactor: remove redundant property declarations in `BaseController` --- app/Controllers/BaseController.php | 35 ++++++++++-------------------- system/Controller.php | 2 -- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 689405bdf314..ab45a7710be9 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -3,44 +3,28 @@ namespace App\Controllers; use CodeIgniter\Controller; -use CodeIgniter\HTTP\CLIRequest; -use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; /** - * Class BaseController - * * BaseController provides a convenient place for loading components * and performing functions that are needed by all your controllers. + * * Extend this class in any new controllers: + * ``` * class Home extends BaseController + * ``` * - * For security be sure to declare any new methods as protected or private. + * For security, be sure to declare any new methods as protected or private. */ abstract class BaseController extends Controller { - /** - * Instance of the main Request object. - * - * @var CLIRequest|IncomingRequest - */ - protected $request; - - /** - * An array of helpers to be loaded automatically upon - * class instantiation. These helpers will be available - * to all other controllers that extend BaseController. - * - * @var list - */ - protected $helpers = []; - /** * Be sure to declare properties for any property fetch you initialized. * The creation of dynamic property is deprecated in PHP 8.2. */ + // protected $session; /** @@ -48,11 +32,14 @@ abstract class BaseController extends Controller */ public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { - // Do Not Edit This Line + // Load here all helpers you want to be available in your controllers that extend BaseController. + // Caution: Do not put the this below the parent::initController() call below. + // $this->helpers = ['form', 'url']; + + // Caution: Do not edit this line. parent::initController($request, $response, $logger); // Preload any models, libraries, etc, here. - - // E.g.: $this->session = service('session'); + // $this->session = service('session'); } } diff --git a/system/Controller.php b/system/Controller.php index 9c6e7ee36a63..af74f3a3af10 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -25,8 +25,6 @@ use Psr\Log\LoggerInterface; /** - * Class Controller - * * @see \CodeIgniter\ControllerTest */ class Controller