diff --git a/phpstan-baseline.neon.dist b/phpstan-baseline.neon.dist index f018a20ca851..17f71d164f29 100644 --- a/phpstan-baseline.neon.dist +++ b/phpstan-baseline.neon.dist @@ -455,11 +455,6 @@ parameters: count: 1 path: system/Debug/Exceptions.php - - - message: "#^Property CodeIgniter\\\\Debug\\\\Exceptions\\:\\:\\$formatter \\(CodeIgniter\\\\Format\\\\FormatterInterface\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: system/Debug/Exceptions.php - - message: "#^Property Config\\\\Exceptions\\:\\:\\$sensitiveDataInTrace \\(array\\) in isset\\(\\) is not nullable\\.$#" count: 1 @@ -660,11 +655,6 @@ parameters: count: 1 path: system/Log/Logger.php - - - message: "#^Property CodeIgniter\\\\RESTful\\\\ResourceController\\:\\:\\$formatter \\(CodeIgniter\\\\Format\\\\FormatterInterface\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: system/RESTful/ResourceController.php - - message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getDefaultNamespace\\(\\)\\.$#" count: 3 @@ -835,11 +825,6 @@ parameters: count: 1 path: system/Test/Mock/MockConnection.php - - - message: "#^Property CodeIgniter\\\\Test\\\\Mock\\\\MockResourcePresenter\\:\\:\\$formatter \\(CodeIgniter\\\\Format\\\\FormatterInterface\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: system/Test/Mock/MockResourcePresenter.php - - message: "#^Property CodeIgniter\\\\Throttle\\\\Throttler\\:\\:\\$testTime \\(int\\) on left side of \\?\\? is not nullable\\.$#" count: 1 diff --git a/system/API/ResponseTrait.php b/system/API/ResponseTrait.php index 9ee722b45235..f20affaffaf5 100644 --- a/system/API/ResponseTrait.php +++ b/system/API/ResponseTrait.php @@ -75,7 +75,7 @@ trait ResponseTrait /** * Current Formatter instance. This is usually set by ResponseTrait::format * - * @var FormatterInterface + * @var FormatterInterface|null */ protected $formatter; diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 0b4ab7531176..6b0068f04670 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -76,11 +76,6 @@ require_once SYSTEMPATH . 'Config/Services.php'; require_once APPPATH . 'Config/Services.php'; -// Use Config\Services as CodeIgniter\Services -if (! class_exists('CodeIgniter\Services', false)) { - class_alias(Services::class, 'CodeIgniter\Services'); -} - // Initialize and register the loader with the SPL autoloader stack. Services::autoloader()->initialize(new Autoload(), new Modules())->register(); diff --git a/system/bootstrap.php b/system/bootstrap.php index 863bb327a93a..421b6ca6b7d6 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -101,11 +101,6 @@ require_once SYSTEMPATH . 'Config/Services.php'; require_once APPPATH . 'Config/Services.php'; -// Use Config\Services as CodeIgniter\Services -if (! class_exists('CodeIgniter\Services', false)) { - class_alias(Services::class, 'CodeIgniter\Services'); -} - // Initialize and register the loader with the SPL autoloader stack. Services::autoloader()->initialize(new Autoload(), new Modules())->register(); diff --git a/tests/_support/Services.php b/tests/_support/Services.php deleted file mode 100644 index e6a8e53e6858..000000000000 --- a/tests/_support/Services.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please view - * the LICENSE file that was distributed with this source code. - */ - -namespace CodeIgniter; - -use CIUnitTestCase; -use Config\Services as ConfigServices; - -/** - * Services class for testing. - */ -class Services -{ - /** - * Mock objects for testing which are returned if exist. - * - * @var array - */ - protected static $mocks = []; - - /** - * Reset shared instances and mocks for testing. - */ - public static function reset() - { - static::$mocks = []; - - CIUnitTestCase::setPrivateProperty(ConfigServices::class, 'instances', []); - } - - /** - * Inject mock object for testing. - * - * @param $mock - */ - public static function injectMock(string $name, $mock) - { - $name = strtolower($name); - static::$mocks[$name] = $mock; - } - - /** - * Returns a service - */ - public static function __callStatic(string $name, array $arguments) - { - $name = strtolower($name); - - // Returns mock if exists - if (isset(static::$mocks[$name])) { - return static::$mocks[$name]; - } - - if (method_exists(ConfigServices::class, $name)) { - return ConfigServices::$name(...$arguments); - } - } -} diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 2069762bba57..9410b13322c1 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -12,7 +12,6 @@ namespace CodeIgniter; use CodeIgniter\Config\BaseService; -use CodeIgniter\Config\Services; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\Response; use CodeIgniter\HTTP\URI; @@ -29,6 +28,7 @@ use Config\App; use Config\Logger; use Config\Modules; +use Config\Services; use Kint; use stdClass; use Tests\Support\Models\JobModel; @@ -118,8 +118,8 @@ public function testRedirectReturnsRedirectResponse() Services::locator(), new Modules() ); - \CodeIgniter\Services::injectMock('response', $response); - \CodeIgniter\Services::injectMock('routes', $routes); + Services::injectMock('response', $response); + Services::injectMock('routes', $routes); $routes->add('home/base', 'Controller::index', ['as' => 'base']); $response->method('redirect')->willReturnArgument(0); diff --git a/tests/system/ControllerTest.php b/tests/system/ControllerTest.php index 9330b9e15d16..6a16ea7bb17f 100644 --- a/tests/system/ControllerTest.php +++ b/tests/system/ControllerTest.php @@ -19,6 +19,7 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Validation\Exceptions\ValidationException; use Config\App; +use Config\Services; use Psr\Log\LoggerInterface; /** @@ -56,7 +57,7 @@ protected function setUp(): void $this->config = new App(); $this->request = new IncomingRequest($this->config, new URI('https://somwhere.com'), null, new UserAgent()); $this->response = new Response($this->config); - $this->logger = \Config\Services::logger(); + $this->logger = Services::logger(); } public function testConstructor() diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 85a3e8dc0182..3fdcc582d0fc 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -12,10 +12,10 @@ namespace CodeIgniter\Helpers; use CodeIgniter\HTTP\URI; -use CodeIgniter\Services; use CodeIgniter\Test\CIUnitTestCase; use Config\App; use Config\Filters; +use Config\Services; /** * @internal diff --git a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php index 1060f90da512..f6f49e1ef53c 100644 --- a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php +++ b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php @@ -11,11 +11,11 @@ namespace CodeIgniter\Log\Handlers; -use CodeIgniter\Services; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockLogger as LoggerConfig; use CodeIgniter\Test\Mock\MockResponse; use Config\App; +use Config\Services; use stdClass; /**