diff --git a/phpstan-baseline.neon.dist b/phpstan-baseline.neon.dist index 698fe2f56c42..0a68ece79609 100644 --- a/phpstan-baseline.neon.dist +++ b/phpstan-baseline.neon.dist @@ -70,36 +70,11 @@ parameters: count: 1 path: system/Cache/Handlers/RedisHandler.php - - - message: "#^Call to an undefined method CodeIgniter\\\\HTTP\\\\Request\\:\\:getPost\\(\\)\\.$#" - count: 1 - path: system/CodeIgniter.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\HTTP\\\\Request\\:\\:setLocale\\(\\)\\.$#" - count: 1 - path: system/CodeIgniter.php - - message: "#^Property CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:\\$db \\(CodeIgniter\\\\Database\\\\BaseConnection\\) in empty\\(\\) is not falsy\\.$#" count: 1 path: system/Database/BaseBuilder.php - - - message: "#^Call to an undefined method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:_disableForeignKeyChecks\\(\\)\\.$#" - count: 1 - path: system/Database/BaseConnection.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Database\\\\BaseConnection\\:\\:_enableForeignKeyChecks\\(\\)\\.$#" - count: 1 - path: system/Database/BaseConnection.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Database\\\\QueryInterface\\:\\:getOriginalQuery\\(\\)\\.$#" - count: 1 - path: system/Database/BaseConnection.php - - message: "#^Negated boolean expression is always false\\.$#" count: 3 @@ -115,16 +90,6 @@ parameters: count: 2 path: system/Database/BaseResult.php - - - message: "#^Access to an undefined property CodeIgniter\\\\Database\\\\ConnectionInterface\\:\\:\\$DBDriver\\.$#" - count: 2 - path: system/Database/Database.php - - - - message: "#^Access to an undefined property CodeIgniter\\\\Database\\\\ConnectionInterface\\:\\:\\$connID\\.$#" - count: 2 - path: system/Database/Database.php - - message: "#^Property CodeIgniter\\\\Database\\\\Migration\\:\\:\\$DBGroup \\(string\\) on left side of \\?\\? is not nullable\\.$#" count: 1 @@ -400,26 +365,11 @@ parameters: count: 1 path: system/Debug/Exceptions.php - - - message: "#^Call to an undefined method CodeIgniter\\\\View\\\\RendererInterface\\:\\:getPerformanceData\\(\\)\\.$#" - count: 1 - path: system/Debug/Toolbar/Collectors/Events.php - - message: "#^Property CodeIgniter\\\\Log\\\\Logger\\:\\:\\$logCache \\(array\\) on left side of \\?\\? is not nullable\\.$#" count: 1 path: system/Debug/Toolbar/Collectors/Logs.php - - - message: "#^Call to an undefined method CodeIgniter\\\\View\\\\RendererInterface\\:\\:getData\\(\\)\\.$#" - count: 1 - path: system/Debug/Toolbar/Collectors/Views.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\View\\\\RendererInterface\\:\\:getPerformanceData\\(\\)\\.$#" - count: 2 - path: system/Debug/Toolbar/Collectors/Views.php - - message: "#^Static property CodeIgniter\\\\Email\\\\Email\\:\\:\\$func_overload \\(bool\\) in isset\\(\\) is not nullable\\.$#" count: 1 @@ -565,51 +515,6 @@ parameters: count: 1 path: system/Images/Handlers/ImageMagickHandler.php - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getDefaultNamespace\\(\\)\\.$#" - count: 3 - path: system/Router/Router.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getFilterForRoute\\(\\)\\.$#" - count: 1 - path: system/Router/Router.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getFiltersForRoute\\(\\)\\.$#" - count: 1 - path: system/Router/Router.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRoutesOptions\\(\\)\\.$#" - count: 1 - path: system/Router/Router.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:isFiltered\\(\\)\\.$#" - count: 1 - path: system/Router/Router.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:setHTTPVerb\\(\\)\\.$#" - count: 1 - path: system/Router/Router.php - - - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRegisteredControllers\\(.*\\)\\.$#" - count: 2 - path: system/Router/Router.php - - - - message: "#^Expression on left side of \\?\\? is not nullable\\.$#" - count: 1 - path: system/Router/Router.php - - - - message: "#^Method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRoutes\\(\\) invoked with 1 parameter, 0 required\\.$#" - count: 1 - path: system/Router/Router.php - - message: "#^Strict comparison using \\=\\=\\= between string and true will always evaluate to false\\.$#" count: 1 @@ -675,11 +580,6 @@ parameters: count: 1 path: system/Validation/Validation.php - - - message: "#^Property CodeIgniter\\\\View\\\\Cell\\:\\:\\$cache \\(CodeIgniter\\\\Cache\\\\CacheInterface\\) in empty\\(\\) is not falsy\\.$#" - count: 2 - path: system/View/Cell.php - - message: "#^Property Config\\\\View\\:\\:\\$plugins \\(array\\) on left side of \\?\\? is not nullable\\.$#" count: 1 diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 1585a135c205..ebf12893e063 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -82,7 +82,7 @@ class CodeIgniter /** * Current request. * - * @var CLIRequest|IncomingRequest|Request|null + * @var CLIRequest|IncomingRequest|null */ protected $request; @@ -432,7 +432,10 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache return $returnResponse ? $possibleResponse : $possibleResponse->pretend($this->useSafeOutput)->send(); } - if ($possibleResponse instanceof Request) { + if ( + $possibleResponse instanceof IncomingRequest + || $possibleResponse instanceof CLIRequest + ) { $this->request = $possibleResponse; } @@ -549,9 +552,11 @@ protected function startBenchmark() * Sets a Request object to be used for this request. * Used when running certain tests. * + * @param CLIRequest|IncomingRequest $request + * * @return $this */ - public function setRequest(Request $request) + public function setRequest($request) { $this->request = $request; diff --git a/system/Config/Services.php b/system/Config/Services.php index 169795c77a44..10f073c3e5ff 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -44,7 +44,6 @@ use CodeIgniter\Log\Logger; use CodeIgniter\Pager\Pager; use CodeIgniter\Router\RouteCollection; -use CodeIgniter\Router\RouteCollectionInterface; use CodeIgniter\Router\Router; use CodeIgniter\Security\Security; use CodeIgniter\Session\Handlers\Database\MySQLiHandler; @@ -597,7 +596,7 @@ public static function routes(bool $getShared = true) * * @return Router */ - public static function router(?RouteCollectionInterface $routes = null, ?Request $request = null, bool $getShared = true) + public static function router(?RouteCollection $routes = null, ?Request $request = null, bool $getShared = true) { if ($getShared) { return static::getSharedInstance('router', $routes, $request); diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 4e6bcd6dfc1e..4b926b590155 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -914,7 +914,7 @@ public function prepare(Closure $func, array $options = []) $this->pretend(false); - if ($sql instanceof QueryInterface) { + if ($sql instanceof Query) { $sql = $sql->getOriginalQuery(); } @@ -1509,6 +1509,13 @@ public function disableForeignKeyChecks() return $this->query($sql); } + /** + * Returns platform-specific SQL to disable foreign key checks. + * + * @return string + */ + abstract protected function _disableForeignKeyChecks(); + /** * Enables foreign key checks temporarily. */ @@ -1519,6 +1526,13 @@ public function enableForeignKeyChecks() return $this->query($sql); } + /** + * Returns platform-specific SQL to enable foreign key checks. + * + * @return string + */ + abstract protected function _enableForeignKeyChecks(); + /** * Allows the engine to be set into a mode where queries are not * actually executed, but they are still generated, timed, etc. diff --git a/system/Database/Database.php b/system/Database/Database.php index 0d3c26c2e84b..4c0b068e5c41 100644 --- a/system/Database/Database.php +++ b/system/Database/Database.php @@ -61,7 +61,7 @@ public function load(array $params = [], string $alias = '') /** * Creates a Forge instance for the current database type. */ - public function loadForge(ConnectionInterface $db): object + public function loadForge(BaseConnection $db): object { if (! $db->connID) { $db->initialize(); @@ -73,7 +73,7 @@ public function loadForge(ConnectionInterface $db): object /** * Creates a Utils instance for the current database type. */ - public function loadUtils(ConnectionInterface $db): object + public function loadUtils(BaseConnection $db): object { if (! $db->connID) { $db->initialize(); diff --git a/system/Debug/Toolbar/Collectors/Events.php b/system/Debug/Toolbar/Collectors/Events.php index a8a7e7aa4c35..510821e5e1da 100644 --- a/system/Debug/Toolbar/Collectors/Events.php +++ b/system/Debug/Toolbar/Collectors/Events.php @@ -11,7 +11,7 @@ namespace CodeIgniter\Debug\Toolbar\Collectors; -use CodeIgniter\View\RendererInterface; +use CodeIgniter\View\View; use Config\Services; /** @@ -54,7 +54,7 @@ class Events extends BaseCollector /** * Instance of the Renderer service * - * @var RendererInterface + * @var View */ protected $viewer; diff --git a/system/Debug/Toolbar/Collectors/Views.php b/system/Debug/Toolbar/Collectors/Views.php index fae3385fffbc..3144e87a6d53 100644 --- a/system/Debug/Toolbar/Collectors/Views.php +++ b/system/Debug/Toolbar/Collectors/Views.php @@ -11,7 +11,7 @@ namespace CodeIgniter\Debug\Toolbar\Collectors; -use CodeIgniter\View\RendererInterface; +use CodeIgniter\View\View; use Config\Services; /** @@ -62,7 +62,7 @@ class Views extends BaseCollector /** * Instance of the Renderer service * - * @var RendererInterface + * @var View */ protected $viewer; diff --git a/system/HTTP/Request.php b/system/HTTP/Request.php index 6294295db4df..00df6abe9966 100644 --- a/system/HTTP/Request.php +++ b/system/HTTP/Request.php @@ -98,7 +98,7 @@ public function getMethod(bool $upper = false): string /** * Sets the request method. Used when spoofing the request. * - * @return Request + * @return $this * * @deprecated Use withMethod() instead for immutability * diff --git a/system/Model.php b/system/Model.php index 59fbef240668..6a3076421dfd 100644 --- a/system/Model.php +++ b/system/Model.php @@ -156,8 +156,8 @@ public function setTable(string $table) /** * Fetches the row of database from $this->table with a primary key - * matching $id. This methods works only with dbCalls - * This methods works only with dbCalls + * matching $id. + * This method works only with dbCalls * * @param bool $singleton Single or multiple results * @param array|int|string|null $id One primary key or an array of primary keys @@ -189,7 +189,7 @@ protected function doFind(bool $singleton, $id = null) /** * Fetches the column of database from $this->table - * This methods works only with dbCalls + * This method works only with dbCalls * * @param string $columnName Column Name * @@ -197,13 +197,15 @@ protected function doFind(bool $singleton, $id = null) */ protected function doFindColumn(string $columnName) { - return $this->select($columnName)->asArray()->find(); + $this->select($columnName); + + return $this->asArray()->find(); } /** * Works with the current Query Builder instance to return * all results, while optionally limiting them. - * This methods works only with dbCalls + * This method works only with dbCalls * * @param int $limit Limit * @param int $offset Offset @@ -226,7 +228,7 @@ protected function doFindAll(int $limit = 0, int $offset = 0) /** * Returns the first row of the result set. Will take any previous * Query Builder calls into account when determining the result set. - * This methods works only with dbCalls + * This method works only with dbCalls * * @return array|object|null */ @@ -251,7 +253,7 @@ protected function doFirst() /** * Inserts data into the current table. - * This methods works only with dbCalls + * This method works only with dbCalls * * @param array $data Data * @@ -314,7 +316,7 @@ protected function doInsert(array $data) /** * Compiles batch insert strings and runs the queries, validating each row prior. - * This methods works only with dbCalls + * This method works only with dbCalls * * @param array|null $set An associative array of insert values * @param bool|null $escape Whether to escape values @@ -340,7 +342,7 @@ protected function doInsertBatch(?array $set = null, ?bool $escape = null, int $ /** * Updates a single record in $this->table. - * This methods works only with dbCalls + * This method works only with dbCalls * * @param array|int|string|null $id * @param array|null $data @@ -366,7 +368,7 @@ protected function doUpdate($id = null, $data = null): bool /** * Compiles an update string and runs the query - * This methods works only with dbCalls + * This method works only with dbCalls * * @param array|null $set An associative array of update values * @param string|null $index The where key @@ -385,7 +387,7 @@ protected function doUpdateBatch(?array $set = null, ?string $index = null, int /** * Deletes a single record from $this->table where $id matches * the table's primaryKey - * This methods works only with dbCalls + * This method works only with dbCalls * * @param array|int|string|null $id The rows primary key(s) * @param bool $purge Allows overriding the soft deletes setting. @@ -430,7 +432,7 @@ protected function doDelete($id = null, bool $purge = false) /** * Permanently deletes all rows that have been marked as deleted * through soft deletes (deleted = 1) - * This methods works only with dbCalls + * This method works only with dbCalls * * @return bool|mixed */ @@ -444,7 +446,7 @@ protected function doPurgeDeleted() /** * Works with the find* methods to return only the rows that * have been deleted. - * This methods works only with dbCalls + * This method works only with dbCalls */ protected function doOnlyDeleted() { @@ -453,7 +455,7 @@ protected function doOnlyDeleted() /** * Compiles a replace into string and runs the query - * This methods works only with dbCalls + * This method works only with dbCalls * * @param array|null $data Data * @param bool $returnSQL Set to true to return Query String @@ -469,7 +471,7 @@ protected function doReplace(?array $data = null, bool $returnSQL = false) * Grabs the last error(s) that occurred from the Database connection. * The return array should be in the following format: * ['source' => 'message'] - * This methods works only with dbCalls + * This method works only with dbCalls * * @return array */ @@ -523,7 +525,7 @@ public function getIdValue($data) * Loops over records in batches, allowing you to operate on them. * Works with $this->builder to get the Compiled select to * determine the rows to operate on. - * This methods works only with dbCalls + * This method works only with dbCalls * * @throws DataException */ diff --git a/system/Router/Router.php b/system/Router/Router.php index c653608d08c3..aec3ec68d82f 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -20,12 +20,12 @@ /** * Request router. */ -class Router implements RouterInterface +class Router { /** * A RouteCollection instance. * - * @var RouteCollectionInterface + * @var RouteCollection */ protected $collection; @@ -118,7 +118,7 @@ class Router implements RouterInterface /** * Stores a reference to the RouteCollection object. */ - public function __construct(RouteCollectionInterface $routes, ?Request $request = null) + public function __construct(RouteCollection $routes, ?Request $request = null) { $this->collection = $routes; @@ -126,7 +126,7 @@ public function __construct(RouteCollectionInterface $routes, ?Request $request $this->controller = $this->collection->getDefaultController(); $this->method = $this->collection->getDefaultMethod(); - $this->collection->setHTTPVerb(strtolower($request->getMethod() ?? $_SERVER['REQUEST_METHOD'])); + $this->collection->setHTTPVerb(strtolower($request->getMethod())); $this->translateURIDashes = $this->collection->shouldTranslateURIDashes(); diff --git a/system/Test/FeatureTestCase.php b/system/Test/FeatureTestCase.php index dc0c65b4a8b7..fce81efffd36 100644 --- a/system/Test/FeatureTestCase.php +++ b/system/Test/FeatureTestCase.php @@ -342,9 +342,9 @@ protected function setupHeaders(IncomingRequest $request) * * @throws ReflectionException * - * @return Request + * @return IncomingRequest */ - protected function populateGlobals(string $method, Request $request, ?array $params = null) + protected function populateGlobals(string $method, IncomingRequest $request, ?array $params = null) { // $params should set the query vars if present, // otherwise set it from the URL. @@ -371,8 +371,10 @@ protected function populateGlobals(string $method, Request $request, ?array $par * * @param array|null $params The parameters to be formatted and put in the body. If this is empty, it will get the * what has been loaded into the request global of the request class. + * + * @return IncomingRequest */ - protected function setRequestBody(Request $request, ?array $params = null): Request + protected function setRequestBody(IncomingRequest $request, ?array $params = null): Request { if (isset($this->requestBody) && $this->requestBody !== '') { $request->setBody($this->requestBody); diff --git a/system/Test/Mock/MockConnection.php b/system/Test/Mock/MockConnection.php index 2d95b496aab8..ed8e09a5d103 100644 --- a/system/Test/Mock/MockConnection.php +++ b/system/Test/Mock/MockConnection.php @@ -238,4 +238,14 @@ protected function _transRollback(): bool { return true; } + + protected function _disableForeignKeyChecks() + { + return ''; + } + + protected function _enableForeignKeyChecks() + { + return ''; + } } diff --git a/system/View/Cell.php b/system/View/Cell.php index c4fa23a6fbba..81e111e719be 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -75,7 +75,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c ? $cacheName : str_replace(['\\', '/'], '', $class) . $method . md5(serialize($params)); - if (! empty($this->cache) && $output = $this->cache->get($cacheName)) { + if ($output = $this->cache->get($cacheName)) { return $output; } @@ -129,7 +129,7 @@ public function render(string $library, $params = null, int $ttl = 0, ?string $c $output = $instance->{$method}(...array_values($fireArgs)); } // Can we cache it? - if (! empty($this->cache) && $ttl !== 0) { + if ($ttl !== 0) { $this->cache->save($cacheName, $output, $ttl); }