{"id":10021202,"date":"2026-01-20T15:28:00","date_gmt":"2026-01-20T07:28:00","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021202"},"modified":"2026-01-20T15:28:00","modified_gmt":"2026-01-20T07:28:00","slug":"rector-rules-%e6%8f%90%e4%be%9b%e6%a0%87%e5%87%86%e5%8c%96%e7%9a%84%e5%b8%b8%e9%87%8f%e3%80%81%e5%8f%98%e9%87%8f%e3%80%81%e5%87%bd%e6%95%b0%e3%80%81%e7%b1%bb%e3%80%81%e5%b1%9e%e6%80%a7%e5%92%8c-3","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021202","title":{"rendered":"rector-rules &#8211; \u63d0\u4f9b\u6807\u51c6\u5316\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u3001\u5c5e\u6027\u548c\u65b9\u6cd5\u547d\u540d\u4ee5\u53ca\u5176\u4ed6 Rector \u89c4\u5219"},"content":{"rendered":"<h2>rector-rules &#8211; \u63d0\u4f9b\u6807\u51c6\u5316\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u3001\u5c5e\u6027\u548c\u65b9\u6cd5\u547d\u540d\u4ee5\u53ca\u5176\u4ed6 Rector \u89c4\u5219<\/h2>\n<blockquote>\n<p>\u4e4b\u524d\u5199\u8fc7\u7528 Rector <a href=\"https:\/\/link.segmentfault.com\/?enc=%2Fl0EF2Gu%2BWLTw1A0M3AFrQ%3D%3D.6Ud%2B3u9JF4ki6N%2FPznaWyeG62cRfPD0oxP%2F8x1ovlKLUx824VEpaDgb8iAq%2BBYDu\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u300a\u7edf\u4e00\u89c4\u8303\u5316\u4ee3\u7801\u7684\u547d\u540d\u98ce\u683c\u300b<\/a>\uff0c\u73b0\u5728\u5df2\u7ecf\u6574\u7406\u53d1\u5e03\u4e3a Composer \u5305\u4e86\u3002<\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=tM8D5asiuyTVaFqJxs8fDg%3D%3D.A%2B%2F1CcplRGmwWf%2B0paRFf7B3Os3Psmy7UkdYeXas1OtgaSnHh%2F16St11HEt6V%2Bhf\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">rector-rules<\/a> &#8211; \u63d0\u4f9b\u6807\u51c6\u5316\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u3001\u5c5e\u6027\u548c\u65b9\u6cd5\u547d\u540d\u4ee5\u53ca\u5176\u4ed6 Rector \u89c4\u5219\u3002<\/p>\n<\/blockquote>\n<h3><a href=\"https:\/\/link.segmentfault.com\/?enc=jAU9OCzetHsoy9HHLvh1gg%3D%3D.uO7EZfv4LXd4uGOrnu4yAYvNAl%2FNTkNid0U5CeX5zHAepSYtVLrgtBITnBDeXb3a4kzpkDVeLM7yroitj%2F0dNFATq%2BTo2GcTZzyqu9Ed0BM%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Rector \u89c4\u5219\u603b\u89c8<\/a><\/h3>\n<h3><a href=\"https:\/\/link.segmentfault.com\/?enc=cRew%2B%2FUUWZxp71srQ4U02A%3D%3D.isi2yXm2b%2Bxp1AIhlhXxOJQgH8%2Fgz5EPa2Pr6n1ITpU4MZEYTMwCJCadCgFWZmke%2BhlW1o9AQv7KF6p5Cz0S2A%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Rector \u89c4\u5219\u96c6\u603b\u89c8<\/a><\/h3>\n<ul>\n<li><code>Guanguans\/RectorRules\/Set\/SetList::ALL<\/code><\/li>\n<li><code>Guanguans\/RectorRules\/Set\/SetList::COMMON<\/code><\/li>\n<li><code>Guanguans\/RectorRules\/Set\/SetList::PHPBENCH<\/code><\/li>\n<li><code>Guanguans\/RectorRules\/Set\/SetList::PHPSTAN<\/code><\/li>\n<li><code>Guanguans\/RectorRules\/Set\/SetList::RECTOR<\/code><\/li>\n<\/ul>\n<h3>\u914d\u7f6e\u4f7f\u7528\u89c4\u5219\u96c6\u548c\u89c4\u5219<\/h3>\n<pre><code class=\"php\">use Guanguans\/RectorRules\/Rector\/File\/SortFileFunctionStmtRector;\nuse Guanguans\/RectorRules\/Rector\/Name\/RenameToPsrNameRector;\nuse PhpParser\/NodeVisitor\/ParentConnectingVisitor;\nuse Rector\/Config\/RectorConfig;\n\nreturn RectorConfig::configure()\n    -&gt;withSets([\n        Guanguans\/RectorRules\/Set\/SetList::ALL,\n        \/\/ ...\n    ])\n    \/\/ ...\n    -&gt;registerDecoratingNodeVisitor(ParentConnectingVisitor::class)\n    -&gt;withConfiguredRule(RenameToPsrNameRector::class, [\n        'assertMatches*Snapshot', \/\/ \u6392\u9664 spatie\/pest-plugin-snapshots \u5305\u7684\u51fd\u6570\u540d\u79f0\n        'beforeEach', \/\/ \u6392\u9664 pestphp\/pest \u5305\u7684\u51fd\u6570\u540d\u79f0\n        'PDO', \/\/ \u6392\u9664 PDO \u7c7b\u540d\u79f0\n    ])\n    \/\/ ...\n    -&gt;withRules([\n        SortFileFunctionStmtRector::class,\n        \/\/ ...\n    ]);<\/code><\/pre>\n<h3>\u53e6\u5916\u63a8\u8350\u4e0b\u5176\u4ed6\u76f8\u5173\u7c7b\u4f3c\u7684\u5305<\/h3>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=crBs06IPS4paAPOnrXqIlg%3D%3D.h%2FuJxwnO%2FRCMX%2FToAsT3XPiCrxmWP9j6p5pqkoxYTg25W2azCuC0zDCkbAgjsXKlAmNRmJtXbKpP5X9eZL%2FeeA%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">php-cs-fixer-custom-fixers<\/a> &#8211; \u7528 php-cs-fixer \u7edf\u4e00\u4fee\u590d\u9879\u76ee\u4e2d\u7684\u975e php \u683c\u5f0f\u6587\u4ef6<\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=lkUlvEFVcX3aJB7Tp6WoMw%3D%3D.Ds6NfEtsg4kj9vX%2BxZq%2Fv9Eu47RxA8iNbFTKA4rjPmrgrvxN29ppvSdUaYmp7%2F6tAO3OSqJVIx6f6%2FMJI4kZng%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">monorepo-builder-worker<\/a> &#8211; \u7528 monorepo-builder \u81ea\u52a8\u5316\u751f\u6210 <a href=\"https:\/\/link.segmentfault.com\/?enc=daC7pmY%2FJN7iaThePB7ebg%3D%3D.m%2F0biRa6Yf1y4Qx6cSe2X7hUsclw91adXsRUWjnJOvViu0ntWDeYhdn9eScQTj5J4mlW8LlE0GpjGOkekMD6aQCLiReTBJZTTYylx2hl9z4%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">changelog<\/a> \/ \u81ea\u52a8\u5316\u9879\u76ee<a href=\"https:\/\/link.segmentfault.com\/?enc=XTTd8ChSBXmbW7Jhzde7wg%3D%3D.aAIYxUo6w1AVPLTm%2Fex2z5lOresc7zUYU2zFmMdpn2unUcPVLFaXNEO8tasOdoLMFda8sJP%2FSXKAPYvj8aP9hg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u53d1\u5e03\u6d41\u7a0b<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=sbi%2Biq3siqYHbTBJNGogLA%3D%3D.ND8fdhFi1HaTWHobTRQGS6x3SafP0JXMXiyQ%2Fw8RBKH0GyqVWgQaMvTlFb3yG2Ws\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">phpstan-rules<\/a> &#8211; \u4e00\u4e9b\u9644\u52a0\u7684 phpstan \u89c4\u5219<\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047553402\">https:\/\/segmentfault.com\/a\/1190000047553402<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rector-rules &#8211; \u63d0\u4f9b\u6807\u51c6\u5316\u7684\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u3001\u5c5e\u6027\u548c\u65b9\u6cd5\u547d\u540d\u4ee5\u53ca\u5176\u4ed6 Recto [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021202","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021202"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021202\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}