Skip to content
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: add declare(strict_types=1) #8072

Merged
merged 11 commits into from
Dec 4, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Oct 22, 2023

Needs #8078, #8080, #8090, #8091, #8124, #8138, #8175, #8242, #8270

Description

  • add declare(strict_types=1)

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added refactor Pull requests that refactor code 4.5 labels Oct 22, 2023
@kenjis kenjis marked this pull request as draft October 22, 2023 06:26
@kenjis
Copy link
Member Author

kenjis commented Oct 22, 2023

@samsonasik
The following config does not work.
DeclareStrictTypesRector does not skip files in app/ or other folders.
Is there something wrong?

--- a/rector.php
+++ b/rector.php
@@ -44,6 +44,7 @@ use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
 use Rector\Set\ValueObject\LevelSetList;
 use Rector\Set\ValueObject\SetList;
 use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
+use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
 use Utils\Rector\PassStrictParameterToFunctionParameterRector;
 use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
 use Utils\Rector\RemoveVarTagFromClassConstantRector;
@@ -107,6 +108,15 @@ return static function (RectorConfig $rectorConfig): void {
             __DIR__ . '/system/Session/Handlers',
         ],
 
+        DeclareStrictTypesRector::class => [
+            __DIR__ . '/app',
+            __DIR__ . '/system/Commands/Generators/Views',
+            __DIR__ . '/system/Pager/Views',
+            __DIR__ . '/system/Validation/Views',
+            __DIR__ . '/system/View/Parser.php',
+            __DIR__ . '/tests/system/View/Views',
+        ],
+
         // use mt_rand instead of random_int on purpose on non-cryptographically random
         RandomFunctionRector::class,
 
@@ -117,6 +127,7 @@ return static function (RectorConfig $rectorConfig): void {
     $rectorConfig->importNames();
     $rectorConfig->removeUnusedImports();
 
+    $rectorConfig->rule(DeclareStrictTypesRector::class);
     $rectorConfig->rule(UnderscoreToCamelCaseVariableNameRector::class);
     $rectorConfig->rule(SimplifyUselessVariableRector::class);
     $rectorConfig->rule(RemoveAlwaysElseRector::class);

@samsonasik
Copy link
Member

I am on mobile, but that seems a bug due to DeclareStrictTypesRector run on beforeTraverse() while skipping check happen on enterNode() so that overlapped.

@samsonasik
Copy link
Member

Reproduced at Rector side:

@MGatner
Copy link
Member

MGatner commented Oct 22, 2023

What a long-standing conversation! I think this is the right time to do this. @lonnieezell What was our strict_types friend? John something... Should mention him here.

@MGatner
Copy link
Member

MGatner commented Oct 22, 2023

@John-Betong

@neznaika0
Copy link
Contributor

I like type control.

@github-actions github-actions bot added the stale Pull requests with conflicts label Oct 24, 2023
@github-actions
Copy link

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis removed the stale Pull requests with conflicts label Oct 25, 2023
@github-actions
Copy link

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@github-actions github-actions bot added the stale Pull requests with conflicts label Oct 27, 2023
@kenjis kenjis removed the stale Pull requests with conflicts label Oct 27, 2023
@kenjis kenjis force-pushed the declare_strict_types branch 4 times, most recently from 60d3980 to 3b31066 Compare October 30, 2023 04:02
@github-actions github-actions bot added the stale Pull requests with conflicts label Nov 3, 2023
Copy link

github-actions bot commented Nov 3, 2023

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis removed the stale Pull requests with conflicts label Nov 3, 2023
@kenjis kenjis mentioned this pull request Nov 3, 2023
5 tasks
Copy link

github-actions bot commented Nov 6, 2023

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis removed the stale Pull requests with conflicts label Nov 8, 2023
@kenjis kenjis mentioned this pull request Nov 8, 2023
2 tasks
@kenjis kenjis force-pushed the declare_strict_types branch 3 times, most recently from 9a4da43 to 71e8443 Compare November 29, 2023 03:06
@kenjis
Copy link
Member Author

kenjis commented Nov 30, 2023

All checks have passed! 🎉

@kenjis kenjis marked this pull request as ready for review November 30, 2023 08:04
@kenjis kenjis merged commit d61e33e into codeigniter4:4.5 Dec 4, 2023
45 checks passed
@kenjis kenjis deleted the declare_strict_types branch December 4, 2023 21:36
@kenjis
Copy link
Member Author

kenjis commented Dec 4, 2023

Now in 4.5 branch, most files have declare(strict_types=1)! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.5 refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants