-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: CodeIgniter has context #5650
Conversation
ef473c6
to
8d76a03
Compare
@samsonasik Is this a bug of rector? 1 file with changes
===================
1) system/CodeIgniter.php:369
---------- begin diff ----------
@@ @@
}
/**
- * Invoked via php-cli command?
- */
- private function isPhpCli(): bool
- {
- return $this->context === 'php-cli';
- }
-
- /**
* Web access?
*/
private function isWeb(): bool
----------- end diff -----------
Applied rules:
* RemoveUnusedPrivateMethodRector https://github.com/codeigniter4/CodeIgniter4/runs/5049699602?check_suite_focus=true |
Possibly, could you create failing test case? You can start with getrector.org/demo and click "Create a Test" after submit reproduced bug |
No, I tried on getrector.org/demo, but |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this much better than your first attempt. Some comments. Also, I think we should set a default context on MockCodeIgniter
(probably "web"?) so people's tests don't start failing unexpectedly.
Added. |
The simple property check inline is too complex to me, as @samsonasik pointed out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, still a few conversations going.
system/Test/Mock/MockCodeIgniter.php
Outdated
/** | ||
* Context | ||
* web: Invoked by HTTP request | ||
* php-cli: Invoked by CLI via `php public/index.php` | ||
* spark: Invoked by CLI via the `spark` command | ||
* | ||
* @phpstan-var 'php-cli'|'spark'|'web' | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDEs will use the parent docblock so it's fine to drop this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped.
@@ -65,6 +65,7 @@ protected function setUp(): void | |||
|
|||
$config = new App(); | |||
$this->codeigniter = new MockCodeIgniter($config); | |||
$this->codeigniter->setContext('web'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are no longer needed with the default property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
@@ -59,6 +59,7 @@ protected function setUp(): void | |||
|
|||
$config = new App(); | |||
$this->codeigniter = new MockCodeIgniter($config); | |||
$this->codeigniter->setContext('web'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these are no longer needed with the default property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
I'm fine with the private methods. It still isn't my preference but I don't think either is "wrong" and I trust you as the author, unless there are other stronger opinions. |
3cf1c50
to
822adfd
Compare
Make the constant SPARKED deprecated. Remove is_cli() in CodeIgniter.
It is MockCodeIgniter's default.
729ba95
to
a10bde7
Compare
@MGatner Can you review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Should spark and public/index.php be included in the "All Changes" section?
Strictly speaking no, I think. Because:
|
@kenjis just tried a development build in a ci4 project: php builds development
composer update
php spark serve
CodeIgniter v4.1.8 Command Line Tool - Server Time: 2022-02-18 17:42:23 UTC-06:00
An uncaught Exception was encountered
Type: Error
Message: Typed property CodeIgniter\CodeIgniter::$context must not be accessed before initialization
Filename: /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CodeIgniter.php
Line Number: 308
Backtrace:
-48 - /Users/samsonasik/www/ci4-prj/vendor/codeigniter4/codeigniter4/system/CLI/Console.php::run
-57 - /Users/samsonasik/www/ci4-prj/spark::run It seems the warning is not shown early for :
as it not initialized. |
@samsonasik
|
@samsonasik I got it! |
Description
Supersede: #5649
CodeIgniter::$context
:web
,php-cli
,spark
SPARKED
deprecatedis_cli()
inCodeIgniter
Checklist: