Skip to content

Commit 0549469

Browse files
committed
address review suggestions
1 parent 9783bc2 commit 0549469

31 files changed

Lines changed: 67 additions & 46 deletions

system/CLI/CLI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ public static function strlen(?string $string): int
656656
*/
657657
public static function streamSupports(string $function, $resource): bool
658658
{
659-
if (service('environmentdetector')->isTesting()) {
659+
if (service('envdetector')->isTesting()) {
660660
// In the current setup of the tests we cannot fully check
661661
// if the stream supports the function since we are using
662662
// filtered streams.

system/CLI/InputOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct()
4242
public function input(?string $prefix = null): string
4343
{
4444
// readline() can't be tested.
45-
if ($this->readlineSupport && ! service('environmentdetector')->isTesting()) {
45+
if ($this->readlineSupport && ! service('envdetector')->isTesting()) {
4646
return readline($prefix); // @codeCoverageIgnore
4747
}
4848

system/Commands/Database/CreateDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function run(array $params)
8787
$config = config(Database::class);
8888

8989
// Set to an empty database to prevent connection errors.
90-
$group = service('environmentdetector')->isTesting() ? 'tests' : $config->defaultGroup;
90+
$group = service('envdetector')->isTesting() ? 'tests' : $config->defaultGroup;
9191

9292
$config->{$group}['database'] = '';
9393

system/Commands/Database/MigrateRefresh.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function run(array $params)
7474
{
7575
$params['b'] = 0;
7676

77-
if (service('environmentdetector')->isProduction()) {
77+
if (service('envdetector')->isProduction()) {
7878
// @codeCoverageIgnoreStart
7979
$force = array_key_exists('f', $params) || CLI::getOption('f');
8080

system/Commands/Database/MigrateRollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MigrateRollback extends BaseCommand
7272
*/
7373
public function run(array $params)
7474
{
75-
if (service('environmentdetector')->isProduction()) {
75+
if (service('envdetector')->isProduction()) {
7676
// @codeCoverageIgnoreStart
7777
$force = array_key_exists('f', $params) || CLI::getOption('f');
7878

system/Commands/Database/MigrateStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function run(array $params)
9292
$status = [];
9393

9494
foreach (array_keys($namespaces) as $namespace) {
95-
if (! service('environmentdetector')->isTesting()) {
95+
if (! service('envdetector')->isTesting()) {
9696
// Make Tests\\Support discoverable for testing
9797
$this->ignoredNamespaces[] = 'Tests\Support'; // @codeCoverageIgnore
9898
}

system/Commands/Translation/LocalizationFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function run(array $params)
6161
$currentDir = APPPATH;
6262
$this->languagePath = $currentDir . 'Language';
6363

64-
if (service('environmentdetector')->isTesting()) {
64+
if (service('envdetector')->isTesting()) {
6565
$currentDir = SUPPORTPATH . 'Services' . DIRECTORY_SEPARATOR;
6666
$this->languagePath = SUPPORTPATH . 'Language';
6767
}

system/Commands/Translation/LocalizationSync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function run(array $params)
8585
return EXIT_USER_INPUT;
8686
}
8787

88-
if (service('environmentdetector')->isTesting()) {
88+
if (service('envdetector')->isTesting()) {
8989
$this->languagePath = SUPPORTPATH . 'Language';
9090
}
9191

system/Config/BaseService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use CodeIgniter\Debug\Toolbar;
3030
use CodeIgniter\Email\Email;
3131
use CodeIgniter\Encryption\EncrypterInterface;
32+
use CodeIgniter\EnvironmentDetector;
3233
use CodeIgniter\Exceptions\InvalidArgumentException;
3334
use CodeIgniter\Filters\Filters;
3435
use CodeIgniter\Format\Format;
@@ -111,6 +112,7 @@
111112
* @method static CURLRequest curlrequest($options = [], ResponseInterface $response = null, App $config = null, $getShared = true)
112113
* @method static Email email($config = null, $getShared = true)
113114
* @method static EncrypterInterface encrypter(Encryption $config = null, $getShared = false)
115+
* @method static EnvironmentDetector envdetector(?string $environment = null, bool $getShared = true)
114116
* @method static Exceptions exceptions(ConfigExceptions $config = null, $getShared = true)
115117
* @method static Filters filters(ConfigFilters $config = null, $getShared = true)
116118
* @method static Format format(ConfigFormat $config = null, $getShared = true)

system/Config/Services.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ public static function encrypter(?EncryptionConfig $config = null, $getShared =
264264
* Provides a simple way to determine the current environment
265265
* of the application.
266266
*
267-
* @return EnvironmentDetector
267+
* Primarily intended for testing environment-specific branches by
268+
* mocking this service. Mocking it does not modify the `ENVIRONMENT`
269+
* constant. It only affects code paths that resolve and use this service.
268270
*/
269-
public static function environmentdetector(?string $environment = null, bool $getShared = true)
271+
public static function envdetector(?string $environment = null, bool $getShared = true): EnvironmentDetector
270272
{
271273
if ($getShared) {
272-
return static::getSharedInstance('environmentdetector', $environment);
274+
return static::getSharedInstance('envdetector', $environment);
273275
}
274276

275277
return new EnvironmentDetector($environment);

0 commit comments

Comments
 (0)