[{"data":1,"prerenderedAt":3616},["ShallowReactive",2],{"series-\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fpint-larastan-rector-and-pest-essential-for-success":3,"series-context-\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api":3407},{"id":4,"title":5,"body":6,"contentId":3394,"date":3395,"description":3396,"extension":3397,"github":3398,"meetTheInstructor":3398,"meta":3399,"navigation":922,"part":71,"path":3400,"rawbody":3401,"robots":3398,"schemaOrg":3398,"seo":3402,"seriesSlug":3403,"sitemap":3404,"stem":3405,"subtitle":3398,"topics":3398,"__hash__":3406},"series\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fpint-larastan-rector-and-pest-essential-for-success.md","Pint, Rector, Larastan, and Pest: Essentials for Success",{"type":7,"value":8,"toc":3387},"minimark",[9,13,16,32,35,40,43,51,629,632,811,819,830,864,886,889,1297,1308,1315,1359,1362,1366,1369,1429,1432,1468,1475,1478,1497,1503,1620,1623,1716,1721,1754,1772,2143,2148,2151,2157,2201,2205,2208,2225,2230,2329,2332,2376,2380,2413,2416,2434,2591,2598,2640,2645,2697,2701,2704,2709,2715,2896,2899,3127,3130,3147,3186,3189,3214,3219,3311,3314,3343,3349,3365,3373,3377,3380,3383],[10,11,12],"p",{},"Now that the Laravel project is in place and its structure is familiar, it is time to make the codebase easier to maintain.",[10,14,15],{},"As the project grows, consistent formatting, automated refactoring, static analysis, and tests will help us move quickly without losing confidence. In this article, we will configure four tools that support that workflow: Pint, Rector, Larastan, and Pest.",[17,18,19,23,26,29],"ol",{},[20,21,22],"li",{},"Pint formats PHP code according to a consistent style. In the JavaScript ecosystem, it is closest to Prettier or ESLint's formatting rules.",[20,24,25],{},"Rector refactors PHP code automatically. It can modernize syntax, remove deprecated patterns, and apply project-wide improvements.",[20,27,28],{},"Larastan performs static analysis tailored to Laravel. It catches many potential problems before the code runs.",[20,30,31],{},"Pest is a testing framework focused on simple, expressive tests. It is the closest PHP equivalent to tools such as Jest in the JavaScript ecosystem.",[10,33,34],{},"Using these tools from the start keeps the codebase easier to maintain and gives future contributors a clear, consistent foundation. It also saves time as the project grows.",[36,37,39],"h2",{"id":38},"pint","Pint",[10,41,42],{},"Pint comes pre-installed with Laravel, so there is nothing to install. We only need to configure it and add a Composer script for formatting the code.",[10,44,45,46,50],{},"Create a ",[47,48,49],"code",{},"pint.json"," file in the project root. This file lets us choose the rules that should be applied across the codebase.",[52,53,58],"pre",{"className":54,"code":55,"filename":49,"language":56,"meta":57,"style":57},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"preset\": \"laravel\",\n  \"rules\": {\n    \"array_push\": true,\n    \"backtick_to_shell_exec\": true,\n    \"date_time_immutable\": true,\n    \"declare_strict_types\": true,\n    \"lowercase_keywords\": true,\n    \"lowercase_static_reference\": true,\n    \"final_class\": true,\n    \"final_internal_class\": true,\n    \"final_public_method_for_abstract_class\": true,\n    \"fully_qualified_strict_types\": true,\n    \"global_namespace_import\": {\n      \"import_classes\": true,\n      \"import_constants\": true,\n      \"import_functions\": true\n    },\n    \"mb_str_functions\": true,\n    \"modernize_types_casting\": true,\n    \"new_with_parentheses\": false,\n    \"no_superfluous_elseif\": true,\n    \"no_useless_else\": true,\n    \"no_multiple_statements_per_line\": true,\n    \"ordered_class_elements\": {\n      \"order\": [\n        \"use_trait\",\n        \"case\",\n        \"constant\",\n        \"constant_public\",\n        \"constant_protected\",\n        \"constant_private\",\n        \"property_public\",\n        \"property_protected\",\n        \"property_private\",\n        \"construct\",\n        \"destruct\",\n        \"magic\",\n        \"phpunit\",\n        \"method_abstract\",\n        \"method_public_static\",\n        \"method_public\",\n        \"method_protected_static\",\n        \"method_protected\",\n        \"method_private_static\",\n        \"method_private\"\n      ],\n      \"sort_algorithm\": \"none\"\n    },\n    \"ordered_interfaces\": true,\n    \"ordered_traits\": true,\n    \"protected_to_private\": true,\n    \"self_accessor\": true,\n    \"self_static_accessor\": true,\n    \"strict_comparison\": true,\n    \"visibility_required\": true\n  }\n}\n","json","",[47,59,60,69,86,95,108,120,132,144,156,168,180,192,204,216,224,236,248,259,265,277,289,302,314,326,338,346,355,363,371,379,387,395,403,411,419,427,435,443,451,459,467,475,483,491,499,507,513,519,530,535,547,559,571,583,595,607,617,623],{"__ignoreMap":57},[61,62,65],"span",{"class":63,"line":64},"line",1,[61,66,68],{"class":67},"sxrX7","{\n",[61,70,72,76,79,83],{"class":63,"line":71},2,[61,73,75],{"class":74},"sBjJW","  \"preset\"",[61,77,78],{"class":67},": ",[61,80,82],{"class":81},"sIIMD","\"laravel\"",[61,84,85],{"class":67},",\n",[61,87,89,92],{"class":63,"line":88},3,[61,90,91],{"class":74},"  \"rules\"",[61,93,94],{"class":67},": {\n",[61,96,98,101,103,106],{"class":63,"line":97},4,[61,99,100],{"class":74},"    \"array_push\"",[61,102,78],{"class":67},[61,104,105],{"class":74},"true",[61,107,85],{"class":67},[61,109,111,114,116,118],{"class":63,"line":110},5,[61,112,113],{"class":74},"    \"backtick_to_shell_exec\"",[61,115,78],{"class":67},[61,117,105],{"class":74},[61,119,85],{"class":67},[61,121,123,126,128,130],{"class":63,"line":122},6,[61,124,125],{"class":74},"    \"date_time_immutable\"",[61,127,78],{"class":67},[61,129,105],{"class":74},[61,131,85],{"class":67},[61,133,135,138,140,142],{"class":63,"line":134},7,[61,136,137],{"class":74},"    \"declare_strict_types\"",[61,139,78],{"class":67},[61,141,105],{"class":74},[61,143,85],{"class":67},[61,145,147,150,152,154],{"class":63,"line":146},8,[61,148,149],{"class":74},"    \"lowercase_keywords\"",[61,151,78],{"class":67},[61,153,105],{"class":74},[61,155,85],{"class":67},[61,157,159,162,164,166],{"class":63,"line":158},9,[61,160,161],{"class":74},"    \"lowercase_static_reference\"",[61,163,78],{"class":67},[61,165,105],{"class":74},[61,167,85],{"class":67},[61,169,171,174,176,178],{"class":63,"line":170},10,[61,172,173],{"class":74},"    \"final_class\"",[61,175,78],{"class":67},[61,177,105],{"class":74},[61,179,85],{"class":67},[61,181,183,186,188,190],{"class":63,"line":182},11,[61,184,185],{"class":74},"    \"final_internal_class\"",[61,187,78],{"class":67},[61,189,105],{"class":74},[61,191,85],{"class":67},[61,193,195,198,200,202],{"class":63,"line":194},12,[61,196,197],{"class":74},"    \"final_public_method_for_abstract_class\"",[61,199,78],{"class":67},[61,201,105],{"class":74},[61,203,85],{"class":67},[61,205,207,210,212,214],{"class":63,"line":206},13,[61,208,209],{"class":74},"    \"fully_qualified_strict_types\"",[61,211,78],{"class":67},[61,213,105],{"class":74},[61,215,85],{"class":67},[61,217,219,222],{"class":63,"line":218},14,[61,220,221],{"class":74},"    \"global_namespace_import\"",[61,223,94],{"class":67},[61,225,227,230,232,234],{"class":63,"line":226},15,[61,228,229],{"class":74},"      \"import_classes\"",[61,231,78],{"class":67},[61,233,105],{"class":74},[61,235,85],{"class":67},[61,237,239,242,244,246],{"class":63,"line":238},16,[61,240,241],{"class":74},"      \"import_constants\"",[61,243,78],{"class":67},[61,245,105],{"class":74},[61,247,85],{"class":67},[61,249,251,254,256],{"class":63,"line":250},17,[61,252,253],{"class":74},"      \"import_functions\"",[61,255,78],{"class":67},[61,257,258],{"class":74},"true\n",[61,260,262],{"class":63,"line":261},18,[61,263,264],{"class":67},"    },\n",[61,266,268,271,273,275],{"class":63,"line":267},19,[61,269,270],{"class":74},"    \"mb_str_functions\"",[61,272,78],{"class":67},[61,274,105],{"class":74},[61,276,85],{"class":67},[61,278,280,283,285,287],{"class":63,"line":279},20,[61,281,282],{"class":74},"    \"modernize_types_casting\"",[61,284,78],{"class":67},[61,286,105],{"class":74},[61,288,85],{"class":67},[61,290,292,295,297,300],{"class":63,"line":291},21,[61,293,294],{"class":74},"    \"new_with_parentheses\"",[61,296,78],{"class":67},[61,298,299],{"class":74},"false",[61,301,85],{"class":67},[61,303,305,308,310,312],{"class":63,"line":304},22,[61,306,307],{"class":74},"    \"no_superfluous_elseif\"",[61,309,78],{"class":67},[61,311,105],{"class":74},[61,313,85],{"class":67},[61,315,317,320,322,324],{"class":63,"line":316},23,[61,318,319],{"class":74},"    \"no_useless_else\"",[61,321,78],{"class":67},[61,323,105],{"class":74},[61,325,85],{"class":67},[61,327,329,332,334,336],{"class":63,"line":328},24,[61,330,331],{"class":74},"    \"no_multiple_statements_per_line\"",[61,333,78],{"class":67},[61,335,105],{"class":74},[61,337,85],{"class":67},[61,339,341,344],{"class":63,"line":340},25,[61,342,343],{"class":74},"    \"ordered_class_elements\"",[61,345,94],{"class":67},[61,347,349,352],{"class":63,"line":348},26,[61,350,351],{"class":74},"      \"order\"",[61,353,354],{"class":67},": [\n",[61,356,358,361],{"class":63,"line":357},27,[61,359,360],{"class":81},"        \"use_trait\"",[61,362,85],{"class":67},[61,364,366,369],{"class":63,"line":365},28,[61,367,368],{"class":81},"        \"case\"",[61,370,85],{"class":67},[61,372,374,377],{"class":63,"line":373},29,[61,375,376],{"class":81},"        \"constant\"",[61,378,85],{"class":67},[61,380,382,385],{"class":63,"line":381},30,[61,383,384],{"class":81},"        \"constant_public\"",[61,386,85],{"class":67},[61,388,390,393],{"class":63,"line":389},31,[61,391,392],{"class":81},"        \"constant_protected\"",[61,394,85],{"class":67},[61,396,398,401],{"class":63,"line":397},32,[61,399,400],{"class":81},"        \"constant_private\"",[61,402,85],{"class":67},[61,404,406,409],{"class":63,"line":405},33,[61,407,408],{"class":81},"        \"property_public\"",[61,410,85],{"class":67},[61,412,414,417],{"class":63,"line":413},34,[61,415,416],{"class":81},"        \"property_protected\"",[61,418,85],{"class":67},[61,420,422,425],{"class":63,"line":421},35,[61,423,424],{"class":81},"        \"property_private\"",[61,426,85],{"class":67},[61,428,430,433],{"class":63,"line":429},36,[61,431,432],{"class":81},"        \"construct\"",[61,434,85],{"class":67},[61,436,438,441],{"class":63,"line":437},37,[61,439,440],{"class":81},"        \"destruct\"",[61,442,85],{"class":67},[61,444,446,449],{"class":63,"line":445},38,[61,447,448],{"class":81},"        \"magic\"",[61,450,85],{"class":67},[61,452,454,457],{"class":63,"line":453},39,[61,455,456],{"class":81},"        \"phpunit\"",[61,458,85],{"class":67},[61,460,462,465],{"class":63,"line":461},40,[61,463,464],{"class":81},"        \"method_abstract\"",[61,466,85],{"class":67},[61,468,470,473],{"class":63,"line":469},41,[61,471,472],{"class":81},"        \"method_public_static\"",[61,474,85],{"class":67},[61,476,478,481],{"class":63,"line":477},42,[61,479,480],{"class":81},"        \"method_public\"",[61,482,85],{"class":67},[61,484,486,489],{"class":63,"line":485},43,[61,487,488],{"class":81},"        \"method_protected_static\"",[61,490,85],{"class":67},[61,492,494,497],{"class":63,"line":493},44,[61,495,496],{"class":81},"        \"method_protected\"",[61,498,85],{"class":67},[61,500,502,505],{"class":63,"line":501},45,[61,503,504],{"class":81},"        \"method_private_static\"",[61,506,85],{"class":67},[61,508,510],{"class":63,"line":509},46,[61,511,512],{"class":81},"        \"method_private\"\n",[61,514,516],{"class":63,"line":515},47,[61,517,518],{"class":67},"      ],\n",[61,520,522,525,527],{"class":63,"line":521},48,[61,523,524],{"class":74},"      \"sort_algorithm\"",[61,526,78],{"class":67},[61,528,529],{"class":81},"\"none\"\n",[61,531,533],{"class":63,"line":532},49,[61,534,264],{"class":67},[61,536,538,541,543,545],{"class":63,"line":537},50,[61,539,540],{"class":74},"    \"ordered_interfaces\"",[61,542,78],{"class":67},[61,544,105],{"class":74},[61,546,85],{"class":67},[61,548,550,553,555,557],{"class":63,"line":549},51,[61,551,552],{"class":74},"    \"ordered_traits\"",[61,554,78],{"class":67},[61,556,105],{"class":74},[61,558,85],{"class":67},[61,560,562,565,567,569],{"class":63,"line":561},52,[61,563,564],{"class":74},"    \"protected_to_private\"",[61,566,78],{"class":67},[61,568,105],{"class":74},[61,570,85],{"class":67},[61,572,574,577,579,581],{"class":63,"line":573},53,[61,575,576],{"class":74},"    \"self_accessor\"",[61,578,78],{"class":67},[61,580,105],{"class":74},[61,582,85],{"class":67},[61,584,586,589,591,593],{"class":63,"line":585},54,[61,587,588],{"class":74},"    \"self_static_accessor\"",[61,590,78],{"class":67},[61,592,105],{"class":74},[61,594,85],{"class":67},[61,596,598,601,603,605],{"class":63,"line":597},55,[61,599,600],{"class":74},"    \"strict_comparison\"",[61,602,78],{"class":67},[61,604,105],{"class":74},[61,606,85],{"class":67},[61,608,610,613,615],{"class":63,"line":609},56,[61,611,612],{"class":74},"    \"visibility_required\"",[61,614,78],{"class":67},[61,616,258],{"class":74},[61,618,620],{"class":63,"line":619},57,[61,621,622],{"class":67},"  }\n",[61,624,626],{"class":63,"line":625},58,[61,627,628],{"class":67},"}\n",[10,630,631],{},"Let's break down the configuration:",[633,634,635,645,657,663,673,679,685,691,697,703,709,715,721,727,733,739,745,751,757,763,769,775,781,787,793,799,805],"ul",{},[20,636,637,640,641,644],{},[47,638,639],{},"preset",": This option allows you to choose a preset configuration for Pint. In this case, we are using the ",[47,642,643],{},"laravel"," preset, which comes with a set of recommended rules for Laravel projects.",[20,646,647,650,651,653,654,656],{},[47,648,649],{},"rules",": This section contains the specific rules we want to apply to our codebase. Each rule can be set to ",[47,652,105],{}," or ",[47,655,299],{},", depending on whether we want to enable or disable it.",[20,658,659,662],{},[47,660,661],{},"array_push",": Enforces the use of array push syntax instead of array merging.",[20,664,665,668,669,672],{},[47,666,667],{},"backtick_to_shell_exec",": Converts backticks to the ",[47,670,671],{},"shell_exec"," function.",[20,674,675,678],{},[47,676,677],{},"date_time_immutable",": Enforces the use of immutable date and time objects.",[20,680,681,684],{},[47,682,683],{},"declare_strict_types",": Enforces the use of strict types in PHP files.",[20,686,687,690],{},[47,688,689],{},"lowercase_keywords",": Enforces the use of lowercase keywords in PHP.",[20,692,693,696],{},[47,694,695],{},"lowercase_static_reference",": Enforces the use of lowercase static references in PHP.",[20,698,699,702],{},[47,700,701],{},"final_class",": Enforces the use of final classes.",[20,704,705,708],{},[47,706,707],{},"final_internal_class",": Enforces the use of final classes for internal classes.",[20,710,711,714],{},[47,712,713],{},"final_public_method_for_abstract_class",": Enforces the use of final public methods for abstract classes.",[20,716,717,720],{},[47,718,719],{},"fully_qualified_strict_types",": Enforces the use of fully qualified strict types in PHP files.",[20,722,723,726],{},[47,724,725],{},"global_namespace_import",": Enforces the use of global namespace imports for classes, constants, and functions.",[20,728,729,732],{},[47,730,731],{},"mb_str_functions",": Enforces the use of multibyte string functions.",[20,734,735,738],{},[47,736,737],{},"modernize_types_casting",": Enforces the use of modern type casting in PHP.",[20,740,741,744],{},[47,742,743],{},"new_with_parentheses",": Enforces the use of parentheses when creating new objects.",[20,746,747,750],{},[47,748,749],{},"no_superfluous_elseif",": Enforces the removal of superfluous elseif statements.",[20,752,753,756],{},[47,754,755],{},"no_useless_else",": Enforces the removal of useless else statements.",[20,758,759,762],{},[47,760,761],{},"no_multiple_statements_per_line",": Enforces the use of a single statement per line.",[20,764,765,768],{},[47,766,767],{},"ordered_class_elements",": Enforces the ordering of class elements, such as traits, constants, properties, and methods.",[20,770,771,774],{},[47,772,773],{},"ordered_interfaces",": Enforces the ordering of interfaces.",[20,776,777,780],{},[47,778,779],{},"ordered_traits",": Enforces the ordering of traits.",[20,782,783,786],{},[47,784,785],{},"protected_to_private",": Enforces the use of private visibility for properties and methods.",[20,788,789,792],{},[47,790,791],{},"self_accessor",": Enforces the use of self accessors for properties and methods.",[20,794,795,798],{},[47,796,797],{},"self_static_accessor",": Enforces the use of self static accessors for properties and methods.",[20,800,801,804],{},[47,802,803],{},"strict_comparison",": Enforces the use of strict comparison operators.",[20,806,807,810],{},[47,808,809],{},"visibility_required",": Enforces the use of visibility keywords for properties and methods.",[812,813,816],"callout",{"color":814,"icon":815},"info","i-ph-info-duotone",[10,817,818],{},"If you have questions about any of these rules, feel free to ask in the comments.",[10,820,821,822,825,826,829],{},"Now, let's add a custom command to lint our code. We will add a ",[47,823,824],{},"lint"," command to our ",[47,827,828],{},"composer.json"," file:",[52,831,833],{"className":54,"code":832,"filename":828,"language":56,"meta":57,"style":57},"{\n  \"scripts\": {\n    \"lint\": \"pint\"\n  }\n}\n",[47,834,835,839,846,856,860],{"__ignoreMap":57},[61,836,837],{"class":63,"line":64},[61,838,68],{"class":67},[61,840,841,844],{"class":63,"line":71},[61,842,843],{"class":74},"  \"scripts\"",[61,845,94],{"class":67},[61,847,848,851,853],{"class":63,"line":88},[61,849,850],{"class":74},"    \"lint\"",[61,852,78],{"class":67},[61,854,855],{"class":81},"\"pint\"\n",[61,857,858],{"class":63,"line":97},[61,859,622],{"class":67},[61,861,862],{"class":63,"line":110},[61,863,628],{"class":67},[10,865,866,867,870,871,874,875,874,878,881,882,885],{},"From now on, we can run ",[47,868,869],{},"composer lint"," to format the code. Pint will process the files in the ",[47,872,873],{},"app",", ",[47,876,877],{},"config",[47,879,880],{},"database",", and ",[47,883,884],{},"routes"," folders and keep their style consistent.",[10,887,888],{},"You should see something like this:",[52,890,895],{"className":891,"code":892,"filename":893,"language":894,"meta":57,"style":57},"language-bash shiki shiki-themes github-light github-light github-dark","➜ composer lint\n> pint\n\n  ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓\n\n  ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Laravel\n    FIXED   ......................................................................................................................... 26 files, 26 style issues fixed\n  ✓ app\u002FHttp\u002FControllers\u002FController.php                                                                            declare_strict_types, blank_line_after_opening_tag\n  ✓ app\u002FModels\u002FUser.php                                                                               final_class, declare_strict_types, blank_line_after_opening_tag\n  ✓ app\u002FProviders\u002FAppServiceProvider.php                                                              final_class, declare_strict_types, blank_line_after_opening_tag\n  ✓ bootstrap\u002Fapp.php                                                                                              declare_strict_types, blank_line_after_opening_tag\n  ✓ bootstrap\u002Fproviders.php                                                                                        declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fapp.php                                                                                                 declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fauth.php                                                                                                declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fcache.php                                                                                               declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fdatabase.php                                                                                            declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Ffilesystems.php                                                                                         declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Flogging.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fmail.php                                                                                                declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fqueue.php                                                                                               declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fservices.php                                                                                            declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fsession.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ database\u002Ffactories\u002FUserFactory.php                                          final_class, self_static_accessor, declare_strict_types, blank_line_after_opening_tag\n  ✓ database\u002Fmigrations\u002F0001_01_01_000000_create_users_table.php                class_definition, declare_strict_types, blank_line_after_opening_tag, braces_position\n  ✓ database\u002Fmigrations\u002F0001_01_01_000001_create_cache_table.php                class_definition, declare_strict_types, blank_line_after_opening_tag, braces_position\n  ✓ database\u002Fmigrations\u002F0001_01_01_000002_create_jobs_table.php                 class_definition, declare_strict_types, blank_line_after_opening_tag, braces_position\n  ✓ database\u002Fseeders\u002FDatabaseSeeder.php                                                               final_class, declare_strict_types, blank_line_after_opening_tag\n  ✓ public\u002Findex.php                                                                                               declare_strict_types, blank_line_after_opening_tag\n  ✓ routes\u002Fconsole.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ routes\u002Fweb.php                                                                                                 declare_strict_types, blank_line_after_opening_tag\n  ✓ tests\u002FFeature\u002FExampleTest.php                                                                                  declare_strict_types, blank_line_after_opening_tag\n  ✓ tests\u002FTestCase.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ tests\u002FUnit\u002FExampleTest.php                                                                                     declare_strict_types, blank_line_after_opening_tag\n","terminal","bash",[47,896,897,909,918,924,929,933,941,966,980,995,1009,1021,1033,1045,1057,1069,1081,1093,1105,1116,1127,1138,1149,1166,1184,1199,1215,1229,1240,1251,1262,1274,1285],{"__ignoreMap":57},[61,898,899,903,906],{"class":63,"line":64},[61,900,902],{"class":901},"snPdu","➜",[61,904,905],{"class":81}," composer",[61,907,908],{"class":81}," lint\n",[61,910,911,915],{"class":63,"line":71},[61,912,914],{"class":913},"s8jYJ",">",[61,916,917],{"class":67}," pint\n",[61,919,920],{"class":63,"line":88},[61,921,923],{"emptyLinePlaceholder":922},true,"\n",[61,925,926],{"class":63,"line":97},[61,927,928],{"class":901},"  ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓\n",[61,930,931],{"class":63,"line":110},[61,932,923],{"emptyLinePlaceholder":922},[61,934,935,938],{"class":63,"line":122},[61,936,937],{"class":901},"  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────",[61,939,940],{"class":81}," Laravel\n",[61,942,943,946,949,952,955,957,960,963],{"class":63,"line":134},[61,944,945],{"class":901},"    FIXED",[61,947,948],{"class":81},"   .........................................................................................................................",[61,950,951],{"class":74}," 26",[61,953,954],{"class":81}," files,",[61,956,951],{"class":74},[61,958,959],{"class":81}," style",[61,961,962],{"class":81}," issues",[61,964,965],{"class":81}," fixed\n",[61,967,968,971,974,977],{"class":63,"line":146},[61,969,970],{"class":901},"  ✓",[61,972,973],{"class":81}," app\u002FHttp\u002FControllers\u002FController.php",[61,975,976],{"class":81},"                                                                            declare_strict_types,",[61,978,979],{"class":81}," blank_line_after_opening_tag\n",[61,981,982,984,987,990,993],{"class":63,"line":158},[61,983,970],{"class":901},[61,985,986],{"class":81}," app\u002FModels\u002FUser.php",[61,988,989],{"class":81},"                                                                               final_class,",[61,991,992],{"class":81}," declare_strict_types,",[61,994,979],{"class":81},[61,996,997,999,1002,1005,1007],{"class":63,"line":170},[61,998,970],{"class":901},[61,1000,1001],{"class":81}," app\u002FProviders\u002FAppServiceProvider.php",[61,1003,1004],{"class":81},"                                                              final_class,",[61,1006,992],{"class":81},[61,1008,979],{"class":81},[61,1010,1011,1013,1016,1019],{"class":63,"line":182},[61,1012,970],{"class":901},[61,1014,1015],{"class":81}," bootstrap\u002Fapp.php",[61,1017,1018],{"class":81},"                                                                                              declare_strict_types,",[61,1020,979],{"class":81},[61,1022,1023,1025,1028,1031],{"class":63,"line":194},[61,1024,970],{"class":901},[61,1026,1027],{"class":81}," bootstrap\u002Fproviders.php",[61,1029,1030],{"class":81},"                                                                                        declare_strict_types,",[61,1032,979],{"class":81},[61,1034,1035,1037,1040,1043],{"class":63,"line":206},[61,1036,970],{"class":901},[61,1038,1039],{"class":81}," config\u002Fapp.php",[61,1041,1042],{"class":81},"                                                                                                 declare_strict_types,",[61,1044,979],{"class":81},[61,1046,1047,1049,1052,1055],{"class":63,"line":218},[61,1048,970],{"class":901},[61,1050,1051],{"class":81}," config\u002Fauth.php",[61,1053,1054],{"class":81},"                                                                                                declare_strict_types,",[61,1056,979],{"class":81},[61,1058,1059,1061,1064,1067],{"class":63,"line":226},[61,1060,970],{"class":901},[61,1062,1063],{"class":81}," config\u002Fcache.php",[61,1065,1066],{"class":81},"                                                                                               declare_strict_types,",[61,1068,979],{"class":81},[61,1070,1071,1073,1076,1079],{"class":63,"line":238},[61,1072,970],{"class":901},[61,1074,1075],{"class":81}," config\u002Fdatabase.php",[61,1077,1078],{"class":81},"                                                                                            declare_strict_types,",[61,1080,979],{"class":81},[61,1082,1083,1085,1088,1091],{"class":63,"line":250},[61,1084,970],{"class":901},[61,1086,1087],{"class":81}," config\u002Ffilesystems.php",[61,1089,1090],{"class":81},"                                                                                         declare_strict_types,",[61,1092,979],{"class":81},[61,1094,1095,1097,1100,1103],{"class":63,"line":261},[61,1096,970],{"class":901},[61,1098,1099],{"class":81}," config\u002Flogging.php",[61,1101,1102],{"class":81},"                                                                                             declare_strict_types,",[61,1104,979],{"class":81},[61,1106,1107,1109,1112,1114],{"class":63,"line":267},[61,1108,970],{"class":901},[61,1110,1111],{"class":81}," config\u002Fmail.php",[61,1113,1054],{"class":81},[61,1115,979],{"class":81},[61,1117,1118,1120,1123,1125],{"class":63,"line":279},[61,1119,970],{"class":901},[61,1121,1122],{"class":81}," config\u002Fqueue.php",[61,1124,1066],{"class":81},[61,1126,979],{"class":81},[61,1128,1129,1131,1134,1136],{"class":63,"line":291},[61,1130,970],{"class":901},[61,1132,1133],{"class":81}," config\u002Fservices.php",[61,1135,1078],{"class":81},[61,1137,979],{"class":81},[61,1139,1140,1142,1145,1147],{"class":63,"line":304},[61,1141,970],{"class":901},[61,1143,1144],{"class":81}," config\u002Fsession.php",[61,1146,1102],{"class":81},[61,1148,979],{"class":81},[61,1150,1151,1153,1156,1159,1162,1164],{"class":63,"line":316},[61,1152,970],{"class":901},[61,1154,1155],{"class":81}," database\u002Ffactories\u002FUserFactory.php",[61,1157,1158],{"class":81},"                                          final_class,",[61,1160,1161],{"class":81}," self_static_accessor,",[61,1163,992],{"class":81},[61,1165,979],{"class":81},[61,1167,1168,1170,1173,1176,1178,1181],{"class":63,"line":328},[61,1169,970],{"class":901},[61,1171,1172],{"class":81}," database\u002Fmigrations\u002F0001_01_01_000000_create_users_table.php",[61,1174,1175],{"class":81},"                class_definition,",[61,1177,992],{"class":81},[61,1179,1180],{"class":81}," blank_line_after_opening_tag,",[61,1182,1183],{"class":81}," braces_position\n",[61,1185,1186,1188,1191,1193,1195,1197],{"class":63,"line":340},[61,1187,970],{"class":901},[61,1189,1190],{"class":81}," database\u002Fmigrations\u002F0001_01_01_000001_create_cache_table.php",[61,1192,1175],{"class":81},[61,1194,992],{"class":81},[61,1196,1180],{"class":81},[61,1198,1183],{"class":81},[61,1200,1201,1203,1206,1209,1211,1213],{"class":63,"line":348},[61,1202,970],{"class":901},[61,1204,1205],{"class":81}," database\u002Fmigrations\u002F0001_01_01_000002_create_jobs_table.php",[61,1207,1208],{"class":81},"                 class_definition,",[61,1210,992],{"class":81},[61,1212,1180],{"class":81},[61,1214,1183],{"class":81},[61,1216,1217,1219,1222,1225,1227],{"class":63,"line":357},[61,1218,970],{"class":901},[61,1220,1221],{"class":81}," database\u002Fseeders\u002FDatabaseSeeder.php",[61,1223,1224],{"class":81},"                                                               final_class,",[61,1226,992],{"class":81},[61,1228,979],{"class":81},[61,1230,1231,1233,1236,1238],{"class":63,"line":365},[61,1232,970],{"class":901},[61,1234,1235],{"class":81}," public\u002Findex.php",[61,1237,1066],{"class":81},[61,1239,979],{"class":81},[61,1241,1242,1244,1247,1249],{"class":63,"line":373},[61,1243,970],{"class":901},[61,1245,1246],{"class":81}," routes\u002Fconsole.php",[61,1248,1102],{"class":81},[61,1250,979],{"class":81},[61,1252,1253,1255,1258,1260],{"class":63,"line":381},[61,1254,970],{"class":901},[61,1256,1257],{"class":81}," routes\u002Fweb.php",[61,1259,1042],{"class":81},[61,1261,979],{"class":81},[61,1263,1264,1266,1269,1272],{"class":63,"line":389},[61,1265,970],{"class":901},[61,1267,1268],{"class":81}," tests\u002FFeature\u002FExampleTest.php",[61,1270,1271],{"class":81},"                                                                                  declare_strict_types,",[61,1273,979],{"class":81},[61,1275,1276,1278,1281,1283],{"class":63,"line":397},[61,1277,970],{"class":901},[61,1279,1280],{"class":81}," tests\u002FTestCase.php",[61,1282,1102],{"class":81},[61,1284,979],{"class":81},[61,1286,1287,1289,1292,1295],{"class":63,"line":405},[61,1288,970],{"class":901},[61,1290,1291],{"class":81}," tests\u002FUnit\u002FExampleTest.php",[61,1293,1294],{"class":81},"                                                                                     declare_strict_types,",[61,1296,979],{"class":81},[10,1298,1299,1300,1303,1304,1307],{},"The output shows each file and the rules that Pint applied. A ",[47,1301,1302],{},"✓"," means that Pint changed the file; a ",[47,1305,1306],{},"."," means that the file was already formatted correctly.",[10,1309,1310,1311,1314],{},"We will also add a ",[47,1312,1313],{},"test:lint"," command for CI. Instead of changing files, it checks the formatting and exits with an error if a file needs changes.",[52,1316,1318],{"className":54,"code":1317,"filename":828,"language":56,"meta":57,"style":57},"{\n  \"scripts\": {\n    \"lint\": \"pint\",\n    \"test:lint\": \"pint --test\"\n  }\n}\n",[47,1319,1320,1324,1330,1341,1351,1355],{"__ignoreMap":57},[61,1321,1322],{"class":63,"line":64},[61,1323,68],{"class":67},[61,1325,1326,1328],{"class":63,"line":71},[61,1327,843],{"class":74},[61,1329,94],{"class":67},[61,1331,1332,1334,1336,1339],{"class":63,"line":88},[61,1333,850],{"class":74},[61,1335,78],{"class":67},[61,1337,1338],{"class":81},"\"pint\"",[61,1340,85],{"class":67},[61,1342,1343,1346,1348],{"class":63,"line":97},[61,1344,1345],{"class":74},"    \"test:lint\"",[61,1347,78],{"class":67},[61,1349,1350],{"class":81},"\"pint --test\"\n",[61,1352,1353],{"class":63,"line":110},[61,1354,622],{"class":67},[61,1356,1357],{"class":63,"line":122},[61,1358,628],{"class":67},[10,1360,1361],{},"Perfect!",[36,1363,1365],{"id":1364},"rector","Rector",[10,1367,1368],{},"The second tool is Rector, which complements Pint. Pint changes formatting, while Rector changes the structure and behavior of the code according to its rules. For example:",[52,1370,1375],{"className":1371,"code":1372,"filename":1373,"language":1374,"meta":57,"style":57},"language-php shiki shiki-themes github-light github-light github-dark","class SomeClass\n{\n    public function getValue(int $number)\n    {\n        if ($number) {\n            return 100;\n        }\n\n        return 500;\n    }\n}\n","Example","php",[47,1376,1377,1382,1386,1391,1396,1401,1406,1411,1415,1420,1425],{"__ignoreMap":57},[61,1378,1379],{"class":63,"line":64},[61,1380,1381],{},"class SomeClass\n",[61,1383,1384],{"class":63,"line":71},[61,1385,68],{},[61,1387,1388],{"class":63,"line":88},[61,1389,1390],{},"    public function getValue(int $number)\n",[61,1392,1393],{"class":63,"line":97},[61,1394,1395],{},"    {\n",[61,1397,1398],{"class":63,"line":110},[61,1399,1400],{},"        if ($number) {\n",[61,1402,1403],{"class":63,"line":122},[61,1404,1405],{},"            return 100;\n",[61,1407,1408],{"class":63,"line":134},[61,1409,1410],{},"        }\n",[61,1412,1413],{"class":63,"line":146},[61,1414,923],{"emptyLinePlaceholder":922},[61,1416,1417],{"class":63,"line":158},[61,1418,1419],{},"        return 500;\n",[61,1421,1422],{"class":63,"line":170},[61,1423,1424],{},"    }\n",[61,1426,1427],{"class":63,"line":182},[61,1428,628],{},[10,1430,1431],{},"Would be refactored to this:",[52,1433,1435],{"className":1371,"code":1434,"filename":1373,"language":1374,"meta":57,"style":57},"final class SomeClass\n{\n    public function getValue(int $number): int\n    {\n        return $number ? 100 : 500;\n    }\n}\n",[47,1436,1437,1442,1446,1451,1455,1460,1464],{"__ignoreMap":57},[61,1438,1439],{"class":63,"line":64},[61,1440,1441],{},"final class SomeClass\n",[61,1443,1444],{"class":63,"line":71},[61,1445,68],{},[61,1447,1448],{"class":63,"line":88},[61,1449,1450],{},"    public function getValue(int $number): int\n",[61,1452,1453],{"class":63,"line":97},[61,1454,1395],{},[61,1456,1457],{"class":63,"line":110},[61,1458,1459],{},"        return $number ? 100 : 500;\n",[61,1461,1462],{"class":63,"line":122},[61,1463,1424],{},[61,1465,1466],{"class":63,"line":134},[61,1467,628],{},[10,1469,1470,1471,1474],{},"By applying the ",[47,1472,1473],{},"ReturnTypeFromStrictTernaryRector"," rule.",[10,1476,1477],{},"Let's install Rector with Composer:",[52,1479,1481],{"className":891,"code":1480,"filename":893,"language":894,"meta":57,"style":57},"composer require rector\u002Frector --dev\n",[47,1482,1483],{"__ignoreMap":57},[61,1484,1485,1488,1491,1494],{"class":63,"line":64},[61,1486,1487],{"class":901},"composer",[61,1489,1490],{"class":81}," require",[61,1492,1493],{"class":81}," rector\u002Frector",[61,1495,1496],{"class":74}," --dev\n",[10,1498,45,1499,1502],{},[47,1500,1501],{},"rector.php"," configuration file:",[52,1504,1506],{"className":1371,"code":1505,"filename":1501,"language":1374,"meta":57,"style":57},"\u003C?php\n\ndeclare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\n\nreturn RectorConfig::configure()\n    ->withPaths([\n        __DIR__.'\u002Fapp',\n        __DIR__.'\u002Fbootstrap\u002Fapp.php',\n        __DIR__.'\u002Fconfig',\n        __DIR__.'\u002Fdatabase',\n        __DIR__.'\u002Fpublic',\n    ])\n    ->withPreparedSets(\n        deadCode: true,\n        codeQuality: true,\n        typeDeclarations: true,\n        privatization: true,\n        earlyReturn: true,\n        strictBooleans: true,\n    )\n    ->withPhpSets();\n",[47,1507,1508,1513,1517,1522,1526,1531,1535,1540,1545,1550,1555,1560,1565,1570,1575,1580,1585,1590,1595,1600,1605,1610,1615],{"__ignoreMap":57},[61,1509,1510],{"class":63,"line":64},[61,1511,1512],{},"\u003C?php\n",[61,1514,1515],{"class":63,"line":71},[61,1516,923],{"emptyLinePlaceholder":922},[61,1518,1519],{"class":63,"line":88},[61,1520,1521],{},"declare(strict_types=1);\n",[61,1523,1524],{"class":63,"line":97},[61,1525,923],{"emptyLinePlaceholder":922},[61,1527,1528],{"class":63,"line":110},[61,1529,1530],{},"use Rector\\Config\\RectorConfig;\n",[61,1532,1533],{"class":63,"line":122},[61,1534,923],{"emptyLinePlaceholder":922},[61,1536,1537],{"class":63,"line":134},[61,1538,1539],{},"return RectorConfig::configure()\n",[61,1541,1542],{"class":63,"line":146},[61,1543,1544],{},"    ->withPaths([\n",[61,1546,1547],{"class":63,"line":158},[61,1548,1549],{},"        __DIR__.'\u002Fapp',\n",[61,1551,1552],{"class":63,"line":170},[61,1553,1554],{},"        __DIR__.'\u002Fbootstrap\u002Fapp.php',\n",[61,1556,1557],{"class":63,"line":182},[61,1558,1559],{},"        __DIR__.'\u002Fconfig',\n",[61,1561,1562],{"class":63,"line":194},[61,1563,1564],{},"        __DIR__.'\u002Fdatabase',\n",[61,1566,1567],{"class":63,"line":206},[61,1568,1569],{},"        __DIR__.'\u002Fpublic',\n",[61,1571,1572],{"class":63,"line":218},[61,1573,1574],{},"    ])\n",[61,1576,1577],{"class":63,"line":226},[61,1578,1579],{},"    ->withPreparedSets(\n",[61,1581,1582],{"class":63,"line":238},[61,1583,1584],{},"        deadCode: true,\n",[61,1586,1587],{"class":63,"line":250},[61,1588,1589],{},"        codeQuality: true,\n",[61,1591,1592],{"class":63,"line":261},[61,1593,1594],{},"        typeDeclarations: true,\n",[61,1596,1597],{"class":63,"line":267},[61,1598,1599],{},"        privatization: true,\n",[61,1601,1602],{"class":63,"line":279},[61,1603,1604],{},"        earlyReturn: true,\n",[61,1606,1607],{"class":63,"line":291},[61,1608,1609],{},"        strictBooleans: true,\n",[61,1611,1612],{"class":63,"line":304},[61,1613,1614],{},"    )\n",[61,1616,1617],{"class":63,"line":316},[61,1618,1619],{},"    ->withPhpSets();\n",[10,1621,1622],{},"This configuration is a little more involved than Pint's. Here is what each part does:",[633,1624,1625,1631,1641,1647,1666,1710],{},[20,1626,1627,1630],{},[47,1628,1629],{},"declare(strict_types=1)",": This line enables strict typing in the file, ensuring that PHP enforces type declarations.",[20,1632,1633,1636,1637,1640],{},[47,1634,1635],{},"use Rector\\Config\\RectorConfig",": This line imports the ",[47,1638,1639],{},"RectorConfig"," class, which is used to configure Rector.",[20,1642,1643,1646],{},[47,1644,1645],{},"return RectorConfig::configure()",": This line starts the configuration process for Rector.",[20,1648,1649,1652,1653,874,1655,874,1658,874,1660,881,1662,1665],{},[47,1650,1651],{},"->withPaths([...])",": This method specifies the paths to the directories and files that Rector should analyze and refactor. In this case, we are including the ",[47,1654,873],{},[47,1656,1657],{},"bootstrap\u002Fapp.php",[47,1659,877],{},[47,1661,880],{},[47,1663,1664],{},"public"," directories.",[20,1667,1668,1671,1672],{},[47,1669,1670],{},"->withPreparedSets(...)",": This method allows you to enable predefined sets of rules for Rector. In this case, we are enabling several sets:\n",[633,1673,1674,1680,1686,1692,1698,1704],{},[20,1675,1676,1679],{},[47,1677,1678],{},"deadCode",": Removes dead code from the project.",[20,1681,1682,1685],{},[47,1683,1684],{},"codeQuality",": Improves code quality by applying various best practices.",[20,1687,1688,1691],{},[47,1689,1690],{},"typeDeclarations",": Adds type declarations to functions and methods.",[20,1693,1694,1697],{},[47,1695,1696],{},"privatization",": Makes properties and methods private when possible.",[20,1699,1700,1703],{},[47,1701,1702],{},"earlyReturn",": Applies early return patterns to improve readability.",[20,1705,1706,1709],{},[47,1707,1708],{},"strictBooleans",": Enforces strict boolean comparisons.",[20,1711,1712,1715],{},[47,1713,1714],{},"->withPhpSets()",": This method enables a set of rules specifically designed for PHP.",[10,1717,1718,1719,829],{},"Now, let's add a custom command to our ",[47,1720,828],{},[52,1722,1724],{"className":54,"code":1723,"filename":828,"language":56,"meta":57,"style":57},"{\n  \"scripts\": {\n    \"refactor\": \"rector\"\n  }\n}\n",[47,1725,1726,1730,1736,1746,1750],{"__ignoreMap":57},[61,1727,1728],{"class":63,"line":64},[61,1729,68],{"class":67},[61,1731,1732,1734],{"class":63,"line":71},[61,1733,843],{"class":74},[61,1735,94],{"class":67},[61,1737,1738,1741,1743],{"class":63,"line":88},[61,1739,1740],{"class":74},"    \"refactor\"",[61,1742,78],{"class":67},[61,1744,1745],{"class":81},"\"rector\"\n",[61,1747,1748],{"class":63,"line":97},[61,1749,622],{"class":67},[61,1751,1752],{"class":63,"line":110},[61,1753,628],{"class":67},[10,1755,1756,1757,1760,1761,874,1763,874,1765,874,1767,881,1769,1771],{},"We can now run ",[47,1758,1759],{},"composer refactor",". Rector will inspect the files in ",[47,1762,873],{},[47,1764,1657],{},[47,1766,877],{},[47,1768,880],{},[47,1770,1664],{}," and apply the configured transformations. You should see output similar to this:",[52,1773,1775],{"className":891,"code":1774,"filename":893,"language":894,"meta":57,"style":57},"➜ composer refactor\n> rector\n 20\u002F20 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n8 files with changes\n====================\n\n1) database\u002Fmigrations\u002F0001_01_01_000001_create_cache_table.php:12\n\n    ---------- begin diff ----------\n@@ @@\n      *\u002F\n     public function up(): void\n     {\n-        Schema::create('cache', function (Blueprint $table) {\n+        Schema::create('cache', function (Blueprint $table): void {\n             $table->string('key')->primary();\n             $table->mediumText('value');\n             $table->integer('expiration');\n         });\n\n-        Schema::create('cache_locks', function (Blueprint $table) {\n+        Schema::create('cache_locks', function (Blueprint $table): void {\n             $table->string('key')->primary();\n             $table->string('owner');\n             $table->integer('expiration');\n    ----------- end diff -----------\n\nApplied rules:\n * AddClosureVoidReturnTypeWhereNoReturnRector\n#  ...\n",[47,1776,1777,1786,1793,1801,1815,1820,1824,1832,1836,1850,1858,1863,1883,1888,1912,1938,1964,1983,2001,2006,2010,2029,2051,2071,2088,2104,2117,2121,2129,2137],{"__ignoreMap":57},[61,1778,1779,1781,1783],{"class":63,"line":64},[61,1780,902],{"class":901},[61,1782,905],{"class":81},[61,1784,1785],{"class":81}," refactor\n",[61,1787,1788,1790],{"class":63,"line":71},[61,1789,914],{"class":913},[61,1791,1792],{"class":67}," rector\n",[61,1794,1795,1798],{"class":63,"line":88},[61,1796,1797],{"class":901}," 20\u002F20",[61,1799,1800],{"class":67}," [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n",[61,1802,1803,1806,1809,1812],{"class":63,"line":97},[61,1804,1805],{"class":901},"8",[61,1807,1808],{"class":81}," files",[61,1810,1811],{"class":81}," with",[61,1813,1814],{"class":81}," changes\n",[61,1816,1817],{"class":63,"line":110},[61,1818,1819],{"class":81},"====================\n",[61,1821,1822],{"class":63,"line":122},[61,1823,923],{"emptyLinePlaceholder":922},[61,1825,1826,1829],{"class":63,"line":134},[61,1827,1828],{"class":901},"1",[61,1830,1831],{"class":67},") database\u002Fmigrations\u002F0001_01_01_000001_create_cache_table.php:12\n",[61,1833,1834],{"class":63,"line":146},[61,1835,923],{"emptyLinePlaceholder":922},[61,1837,1838,1841,1844,1847],{"class":63,"line":158},[61,1839,1840],{"class":901},"    ----------",[61,1842,1843],{"class":81}," begin",[61,1845,1846],{"class":81}," diff",[61,1848,1849],{"class":74}," ----------\n",[61,1851,1852,1855],{"class":63,"line":170},[61,1853,1854],{"class":901},"@@",[61,1856,1857],{"class":81}," @@\n",[61,1859,1860],{"class":63,"line":182},[61,1861,1862],{"class":901},"      *\u002F\n",[61,1864,1865,1868,1871,1874,1877,1880],{"class":63,"line":194},[61,1866,1867],{"class":901},"     public",[61,1869,1870],{"class":81}," function",[61,1872,1873],{"class":81}," up",[61,1875,1876],{"class":67},"()",[61,1878,1879],{"class":81},":",[61,1881,1882],{"class":81}," void\n",[61,1884,1885],{"class":63,"line":206},[61,1886,1887],{"class":67},"     {\n",[61,1889,1890,1893,1896,1899,1902,1905,1907,1910],{"class":63,"line":218},[61,1891,1892],{"class":901},"-",[61,1894,1895],{"class":81},"        Schema::create",[61,1897,1898],{"class":67},"(",[61,1900,1901],{"class":901},"'cache'",[61,1903,1904],{"class":901},",",[61,1906,1870],{"class":81},[61,1908,1909],{"class":67}," (Blueprint $table) ",[61,1911,68],{"class":81},[61,1913,1914,1917,1919,1921,1923,1925,1927,1930,1932,1935],{"class":63,"line":226},[61,1915,1916],{"class":901},"+",[61,1918,1895],{"class":81},[61,1920,1898],{"class":67},[61,1922,1901],{"class":901},[61,1924,1904],{"class":901},[61,1926,1870],{"class":81},[61,1928,1929],{"class":67}," (Blueprint $table)",[61,1931,1879],{"class":81},[61,1933,1934],{"class":81}," void",[61,1936,1937],{"class":81}," {\n",[61,1939,1940,1943,1945,1947,1950,1952,1955,1958,1961],{"class":63,"line":238},[61,1941,1942],{"class":67},"             $table",[61,1944,1892],{"class":81},[61,1946,914],{"class":67},[61,1948,1949],{"class":81},"string",[61,1951,1898],{"class":67},[61,1953,1954],{"class":901},"'key'",[61,1956,1957],{"class":67},")",[61,1959,1960],{"class":901},"->primary",[61,1962,1963],{"class":67},"();\n",[61,1965,1966,1968,1970,1972,1975,1977,1980],{"class":63,"line":250},[61,1967,1942],{"class":67},[61,1969,1892],{"class":81},[61,1971,914],{"class":67},[61,1973,1974],{"class":81},"mediumText",[61,1976,1898],{"class":67},[61,1978,1979],{"class":901},"'value'",[61,1981,1982],{"class":67},");\n",[61,1984,1985,1987,1989,1991,1994,1996,1999],{"class":63,"line":261},[61,1986,1942],{"class":67},[61,1988,1892],{"class":81},[61,1990,914],{"class":67},[61,1992,1993],{"class":81},"integer",[61,1995,1898],{"class":67},[61,1997,1998],{"class":901},"'expiration'",[61,2000,1982],{"class":67},[61,2002,2003],{"class":63,"line":267},[61,2004,2005],{"class":67},"         });\n",[61,2007,2008],{"class":63,"line":279},[61,2009,923],{"emptyLinePlaceholder":922},[61,2011,2012,2014,2016,2018,2021,2023,2025,2027],{"class":63,"line":291},[61,2013,1892],{"class":901},[61,2015,1895],{"class":81},[61,2017,1898],{"class":67},[61,2019,2020],{"class":901},"'cache_locks'",[61,2022,1904],{"class":901},[61,2024,1870],{"class":81},[61,2026,1909],{"class":67},[61,2028,68],{"class":81},[61,2030,2031,2033,2035,2037,2039,2041,2043,2045,2047,2049],{"class":63,"line":304},[61,2032,1916],{"class":901},[61,2034,1895],{"class":81},[61,2036,1898],{"class":67},[61,2038,2020],{"class":901},[61,2040,1904],{"class":901},[61,2042,1870],{"class":81},[61,2044,1929],{"class":67},[61,2046,1879],{"class":81},[61,2048,1934],{"class":81},[61,2050,1937],{"class":81},[61,2052,2053,2055,2057,2059,2061,2063,2065,2067,2069],{"class":63,"line":316},[61,2054,1942],{"class":67},[61,2056,1892],{"class":81},[61,2058,914],{"class":67},[61,2060,1949],{"class":81},[61,2062,1898],{"class":67},[61,2064,1954],{"class":901},[61,2066,1957],{"class":67},[61,2068,1960],{"class":901},[61,2070,1963],{"class":67},[61,2072,2073,2075,2077,2079,2081,2083,2086],{"class":63,"line":328},[61,2074,1942],{"class":67},[61,2076,1892],{"class":81},[61,2078,914],{"class":67},[61,2080,1949],{"class":81},[61,2082,1898],{"class":67},[61,2084,2085],{"class":901},"'owner'",[61,2087,1982],{"class":67},[61,2089,2090,2092,2094,2096,2098,2100,2102],{"class":63,"line":340},[61,2091,1942],{"class":67},[61,2093,1892],{"class":81},[61,2095,914],{"class":67},[61,2097,1993],{"class":81},[61,2099,1898],{"class":67},[61,2101,1998],{"class":901},[61,2103,1982],{"class":67},[61,2105,2106,2109,2112,2114],{"class":63,"line":348},[61,2107,2108],{"class":901},"    -----------",[61,2110,2111],{"class":81}," end",[61,2113,1846],{"class":81},[61,2115,2116],{"class":74}," -----------\n",[61,2118,2119],{"class":63,"line":357},[61,2120,923],{"emptyLinePlaceholder":922},[61,2122,2123,2126],{"class":63,"line":365},[61,2124,2125],{"class":901},"Applied",[61,2127,2128],{"class":81}," rules:\n",[61,2130,2131,2134],{"class":63,"line":373},[61,2132,2133],{"class":901}," *",[61,2135,2136],{"class":81}," AddClosureVoidReturnTypeWhereNoReturnRector\n",[61,2138,2139],{"class":63,"line":381},[61,2140,2142],{"class":2141},"sCsY4","#  ...\n",[812,2144,2145],{"color":814,"icon":815},[10,2146,2147],{},"The output is shortened here. Your terminal should list every file that Rector modified.",[10,2149,2150],{},"The output lists each modified file, shows a diff, and identifies the rules that were applied.",[10,2152,1310,2153,2156],{},[47,2154,2155],{},"test:refactor"," command for CI. It runs Rector in dry-run mode and reports changes without modifying files.",[52,2158,2160],{"className":54,"code":2159,"filename":828,"language":56,"meta":57,"style":57},"{\n  \"scripts\": {\n    \"refactor\": \"rector\",\n    \"test:refactor\": \"rector --dry-run\"\n  }\n}\n",[47,2161,2162,2166,2172,2183,2193,2197],{"__ignoreMap":57},[61,2163,2164],{"class":63,"line":64},[61,2165,68],{"class":67},[61,2167,2168,2170],{"class":63,"line":71},[61,2169,843],{"class":74},[61,2171,94],{"class":67},[61,2173,2174,2176,2178,2181],{"class":63,"line":88},[61,2175,1740],{"class":74},[61,2177,78],{"class":67},[61,2179,2180],{"class":81},"\"rector\"",[61,2182,85],{"class":67},[61,2184,2185,2188,2190],{"class":63,"line":97},[61,2186,2187],{"class":74},"    \"test:refactor\"",[61,2189,78],{"class":67},[61,2191,2192],{"class":81},"\"rector --dry-run\"\n",[61,2194,2195],{"class":63,"line":110},[61,2196,622],{"class":67},[61,2198,2199],{"class":63,"line":122},[61,2200,628],{"class":67},[36,2202,2204],{"id":2203},"larastan","Larastan",[10,2206,2207],{},"Install Larastan with Composer:",[52,2209,2211],{"className":891,"code":2210,"filename":893,"language":894,"meta":57,"style":57},"composer require --dev \"larastan\u002Flarastan:^3.0\"\n",[47,2212,2213],{"__ignoreMap":57},[61,2214,2215,2217,2219,2222],{"class":63,"line":64},[61,2216,1487],{"class":901},[61,2218,1490],{"class":81},[61,2220,2221],{"class":74}," --dev",[61,2223,2224],{"class":81}," \"larastan\u002Flarastan:^3.0\"\n",[10,2226,45,2227,829],{},[47,2228,2229],{},"phpstan.neon",[52,2231,2235],{"className":2232,"code":2233,"filename":2229,"language":2234,"meta":57,"style":57},"language-yml shiki shiki-themes github-light github-light github-dark","includes:\n  - vendor\u002Flarastan\u002Flarastan\u002Fextension.neon\n  - vendor\u002Fphpstan\u002Fphpstan\u002Fconf\u002FbleedingEdge.neon\n\nparameters:\n  level: 6\n\n  paths:\n    - app\n    - config\n    - bootstrap\n    - database\u002Ffactories\n    - routes\n","yml",[47,2236,2237,2246,2254,2261,2265,2272,2282,2286,2293,2301,2308,2315,2322],{"__ignoreMap":57},[61,2238,2239,2243],{"class":63,"line":64},[61,2240,2242],{"class":2241},"sovSZ","includes",[61,2244,2245],{"class":67},":\n",[61,2247,2248,2251],{"class":63,"line":71},[61,2249,2250],{"class":67},"  - ",[61,2252,2253],{"class":81},"vendor\u002Flarastan\u002Flarastan\u002Fextension.neon\n",[61,2255,2256,2258],{"class":63,"line":88},[61,2257,2250],{"class":67},[61,2259,2260],{"class":81},"vendor\u002Fphpstan\u002Fphpstan\u002Fconf\u002FbleedingEdge.neon\n",[61,2262,2263],{"class":63,"line":97},[61,2264,923],{"emptyLinePlaceholder":922},[61,2266,2267,2270],{"class":63,"line":110},[61,2268,2269],{"class":2241},"parameters",[61,2271,2245],{"class":67},[61,2273,2274,2277,2279],{"class":63,"line":122},[61,2275,2276],{"class":2241},"  level",[61,2278,78],{"class":67},[61,2280,2281],{"class":74},"6\n",[61,2283,2284],{"class":63,"line":134},[61,2285,923],{"emptyLinePlaceholder":922},[61,2287,2288,2291],{"class":63,"line":146},[61,2289,2290],{"class":2241},"  paths",[61,2292,2245],{"class":67},[61,2294,2295,2298],{"class":63,"line":158},[61,2296,2297],{"class":67},"    - ",[61,2299,2300],{"class":81},"app\n",[61,2302,2303,2305],{"class":63,"line":170},[61,2304,2297],{"class":67},[61,2306,2307],{"class":81},"config\n",[61,2309,2310,2312],{"class":63,"line":182},[61,2311,2297],{"class":67},[61,2313,2314],{"class":81},"bootstrap\n",[61,2316,2317,2319],{"class":63,"line":194},[61,2318,2297],{"class":67},[61,2320,2321],{"class":81},"database\u002Ffactories\n",[61,2323,2324,2326],{"class":63,"line":206},[61,2325,2297],{"class":67},[61,2327,2328],{"class":81},"routes\n",[10,2330,2331],{},"This configuration tells Larastan what to load and which parts of the project to analyze:",[633,2333,2334,2347,2352,2358],{},[20,2335,2336,2338,2339,2342,2343,2346],{},[47,2337,2242],{},": This section includes additional configuration files that extend the functionality of Larastan. In this case, we are including the ",[47,2340,2341],{},"larastan\u002Flarastan\u002Fextension.neon"," file and the ",[47,2344,2345],{},"phpstan\u002Fphpstan\u002Fconf\u002FbleedingEdge.neon"," file.",[20,2348,2349,2351],{},[47,2350,2269],{},": This section contains the main configuration parameters for Larastan.",[20,2353,2354,2357],{},[47,2355,2356],{},"level",": This parameter sets the strictness of the analysis. Higher levels catch more potential issues but can also produce more false positives. Level 6 is a reasonable balance for this project, but starting at level 2 and increasing it gradually is also a good approach.",[20,2359,2360,2363,2364,874,2366,874,2368,874,2371,881,2374,1665],{},[47,2361,2362],{},"paths",": This parameter specifies the paths to the directories and files that Larastan should analyze. In this case, we are including the ",[47,2365,873],{},[47,2367,877],{},[47,2369,2370],{},"bootstrap",[47,2372,2373],{},"database\u002Ffactories",[47,2375,884],{},[10,2377,1718,2378,829],{},[47,2379,828],{},[52,2381,2383],{"className":54,"code":2382,"filename":828,"language":56,"meta":57,"style":57},"{\n  \"scripts\": {\n    \"test:types\": \"phpstan analyse\"\n  }\n}\n",[47,2384,2385,2389,2395,2405,2409],{"__ignoreMap":57},[61,2386,2387],{"class":63,"line":64},[61,2388,68],{"class":67},[61,2390,2391,2393],{"class":63,"line":71},[61,2392,843],{"class":74},[61,2394,94],{"class":67},[61,2396,2397,2400,2402],{"class":63,"line":88},[61,2398,2399],{"class":74},"    \"test:types\"",[61,2401,78],{"class":67},[61,2403,2404],{"class":81},"\"phpstan analyse\"\n",[61,2406,2407],{"class":63,"line":97},[61,2408,622],{"class":67},[61,2410,2411],{"class":63,"line":110},[61,2412,628],{"class":67},[10,2414,2415],{},"Unlike Pint and Rector, Larastan isn't automatic and can't fix the code for you. Instead, it will raise errors and warnings that you need to fix manually.",[10,2417,2418,2419,2422,2423,874,2425,874,2427,874,2429,881,2431,2433],{},"Run ",[47,2420,2421],{},"composer test:types"," to analyze the files in ",[47,2424,873],{},[47,2426,877],{},[47,2428,2370],{},[47,2430,2373],{},[47,2432,884],{},". Larastan reports problems that must be fixed manually. You should see output similar to this:",[52,2435,2437],{"className":891,"code":2436,"filename":893,"language":894,"meta":57,"style":57},"➜ composer test:types\n> phpstan analyse\nNote: Using configuration file \u002FUsers\u002Fesoub\u002Fdev\u002Fp\u002Fmimram\u002Fphpstan.neon.\n 20\u002F20 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n\n ------ ---------------------------\n  Line   routes\u002Fconsole.php\n ------ ---------------------------\n  :9     Undefined variable: $this\n         🪪  variable.undefined\n ------ ---------------------------\n\n [ERROR] Found 1 error\n\nScript phpstan analyse handling the test:types event returned with error code 1\n",[47,2438,2439,2448,2455,2472,2478,2482,2490,2498,2504,2518,2526,2532,2536,2550,2554],{"__ignoreMap":57},[61,2440,2441,2443,2445],{"class":63,"line":64},[61,2442,902],{"class":901},[61,2444,905],{"class":81},[61,2446,2447],{"class":81}," test:types\n",[61,2449,2450,2452],{"class":63,"line":71},[61,2451,914],{"class":913},[61,2453,2454],{"class":67}," phpstan analyse\n",[61,2456,2457,2460,2463,2466,2469],{"class":63,"line":88},[61,2458,2459],{"class":901},"Note:",[61,2461,2462],{"class":81}," Using",[61,2464,2465],{"class":81}," configuration",[61,2467,2468],{"class":81}," file",[61,2470,2471],{"class":81}," \u002FUsers\u002Fesoub\u002Fdev\u002Fp\u002Fmimram\u002Fphpstan.neon.\n",[61,2473,2474,2476],{"class":63,"line":97},[61,2475,1797],{"class":901},[61,2477,1800],{"class":67},[61,2479,2480],{"class":63,"line":110},[61,2481,923],{"emptyLinePlaceholder":922},[61,2483,2484,2487],{"class":63,"line":122},[61,2485,2486],{"class":901}," ------",[61,2488,2489],{"class":74}," ---------------------------\n",[61,2491,2492,2495],{"class":63,"line":134},[61,2493,2494],{"class":901},"  Line",[61,2496,2497],{"class":81},"   routes\u002Fconsole.php\n",[61,2499,2500,2502],{"class":63,"line":146},[61,2501,2486],{"class":901},[61,2503,2489],{"class":74},[61,2505,2506,2509,2512,2515],{"class":63,"line":158},[61,2507,2508],{"class":901},"  :9",[61,2510,2511],{"class":81},"     Undefined",[61,2513,2514],{"class":81}," variable:",[61,2516,2517],{"class":67}," $this\n",[61,2519,2520,2523],{"class":63,"line":170},[61,2521,2522],{"class":901},"         🪪",[61,2524,2525],{"class":81},"  variable.undefined\n",[61,2527,2528,2530],{"class":63,"line":182},[61,2529,2486],{"class":901},[61,2531,2489],{"class":74},[61,2533,2534],{"class":63,"line":194},[61,2535,923],{"emptyLinePlaceholder":922},[61,2537,2538,2541,2544,2547],{"class":63,"line":206},[61,2539,2540],{"class":67}," [ERROR] ",[61,2542,2543],{"class":901},"Found",[61,2545,2546],{"class":74}," 1",[61,2548,2549],{"class":81}," error\n",[61,2551,2552],{"class":63,"line":218},[61,2553,923],{"emptyLinePlaceholder":922},[61,2555,2556,2559,2562,2565,2568,2571,2574,2577,2580,2582,2585,2588],{"class":63,"line":226},[61,2557,2558],{"class":901},"Script",[61,2560,2561],{"class":81}," phpstan",[61,2563,2564],{"class":81}," analyse",[61,2566,2567],{"class":81}," handling",[61,2569,2570],{"class":81}," the",[61,2572,2573],{"class":81}," test:types",[61,2575,2576],{"class":81}," event",[61,2578,2579],{"class":81}," returned",[61,2581,1811],{"class":81},[61,2583,2584],{"class":81}," error",[61,2586,2587],{"class":81}," code",[61,2589,2590],{"class":74}," 1\n",[10,2592,2593,2594,2597],{},"The error comes from the default command in ",[47,2595,2596],{},"routes\u002Fconsole.php",", which we do not need for this project. Remove that command to fix it.",[52,2599,2601],{"className":1371,"code":2600,"filename":2596,"language":1374,"meta":57,"style":57},"\u003C?php\n\nuse Illuminate\\Foundation\\Inspiring; \u002F\u002F [!code --]\nuse Illuminate\\Support\\Facades\\Artisan; \u002F\u002F [!code --]\n\nArtisan::command('inspire', function () { \u002F\u002F [!code --]\n    $this->comment(Inspiring::quote()); \u002F\u002F [!code --]\n})->purpose('Display an inspiring quote'); \u002F\u002F [!code --]\n",[47,2602,2603,2607,2611,2616,2621,2625,2630,2635],{"__ignoreMap":57},[61,2604,2605],{"class":63,"line":64},[61,2606,1512],{},[61,2608,2609],{"class":63,"line":71},[61,2610,923],{"emptyLinePlaceholder":922},[61,2612,2613],{"class":63,"line":88},[61,2614,2615],{},"use Illuminate\\Foundation\\Inspiring; \u002F\u002F [!code --]\n",[61,2617,2618],{"class":63,"line":97},[61,2619,2620],{},"use Illuminate\\Support\\Facades\\Artisan; \u002F\u002F [!code --]\n",[61,2622,2623],{"class":63,"line":110},[61,2624,923],{"emptyLinePlaceholder":922},[61,2626,2627],{"class":63,"line":122},[61,2628,2629],{},"Artisan::command('inspire', function () { \u002F\u002F [!code --]\n",[61,2631,2632],{"class":63,"line":134},[61,2633,2634],{},"    $this->comment(Inspiring::quote()); \u002F\u002F [!code --]\n",[61,2636,2637],{"class":63,"line":146},[61,2638,2639],{},"})->purpose('Display an inspiring quote'); \u002F\u002F [!code --]\n",[10,2641,2418,2642,2644],{},[47,2643,2421],{}," again:",[52,2646,2648],{"className":891,"code":2647,"filename":893,"language":894,"meta":57,"style":57},"➜ composer test:types\n> phpstan analyse\nNote: Using configuration file \u002FUsers\u002Fesoub\u002Fdev\u002Fp\u002Fmimram\u002Fphpstan.neon.\n 20\u002F20 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n\n [OK] No errors\n",[47,2649,2650,2658,2664,2676,2682,2686],{"__ignoreMap":57},[61,2651,2652,2654,2656],{"class":63,"line":64},[61,2653,902],{"class":901},[61,2655,905],{"class":81},[61,2657,2447],{"class":81},[61,2659,2660,2662],{"class":63,"line":71},[61,2661,914],{"class":913},[61,2663,2454],{"class":67},[61,2665,2666,2668,2670,2672,2674],{"class":63,"line":88},[61,2667,2459],{"class":901},[61,2669,2462],{"class":81},[61,2671,2465],{"class":81},[61,2673,2468],{"class":81},[61,2675,2471],{"class":81},[61,2677,2678,2680],{"class":63,"line":97},[61,2679,1797],{"class":901},[61,2681,1800],{"class":67},[61,2683,2684],{"class":63,"line":110},[61,2685,923],{"emptyLinePlaceholder":922},[61,2687,2688,2691,2694],{"class":63,"line":122},[61,2689,2690],{"class":67}," [OK] ",[61,2692,2693],{"class":901},"No",[61,2695,2696],{"class":81}," errors\n",[36,2698,2700],{"id":2699},"pest","Pest",[10,2702,2703],{},"The last tool is Pest, a PHP testing framework focused on simple, expressive tests. Pest is the default testing framework in a new Laravel project, so there is nothing to install.",[10,2705,2706,2707,1306],{},"We will configure it and add a few custom commands to ",[47,2708,828],{},[10,2710,2711,2712,829],{},"First, let's edit the ",[47,2713,2714],{},"phpunit.xml",[52,2716,2720],{"className":2717,"code":2718,"filename":2714,"language":2719,"meta":57,"style":57},"language-xml shiki shiki-themes github-light github-light github-dark","\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\u003Cphpunit xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"\n         bootstrap=\"vendor\u002Fautoload.php\"\n         colors=\"true\"\n>\n    \u003Ctestsuites>\n        \u003Ctestsuite name=\"Http\">\n            \u003Cdirectory>tests\u002FHttp\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n        \u003Ctestsuite name=\"Unit\">\n            \u003Cdirectory>tests\u002FUnit\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n    \u003C\u002Ftestsuites>\n    \u003Csource>\n        \u003Cinclude>\n            \u003Cdirectory>app\u003C\u002Fdirectory>\n            \u003Cdirectory>config\u003C\u002Fdirectory>\n            \u003Cdirectory>routes\u003C\u002Fdirectory>\n        \u003C\u002Finclude>\n    \u003C\u002Fsource>\n    \u003Cphp>\n        \u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>\n        \u003Cenv name=\"APP_MAINTENANCE_DRIVER\" value=\"file\"\u002F>\n        \u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>\n        \u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>\n        \u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>\n        \u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>\n        \u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>\n        \u003Cenv name=\"PULSE_ENABLED\" value=\"false\"\u002F>\n        \u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>\n        \u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>\n        \u003Cenv name=\"TELESCOPE_ENABLED\" value=\"false\"\u002F>\n    \u003C\u002Fphp>\n\u003C\u002Fphpunit>\n","xml",[47,2721,2722,2727,2732,2737,2742,2747,2752,2757,2762,2767,2772,2777,2782,2786,2791,2796,2801,2806,2811,2816,2821,2826,2831,2836,2841,2846,2851,2856,2861,2866,2871,2876,2881,2886,2891],{"__ignoreMap":57},[61,2723,2724],{"class":63,"line":64},[61,2725,2726],{},"\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",[61,2728,2729],{"class":63,"line":71},[61,2730,2731],{},"\u003Cphpunit xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"\n",[61,2733,2734],{"class":63,"line":88},[61,2735,2736],{},"         xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"\n",[61,2738,2739],{"class":63,"line":97},[61,2740,2741],{},"         bootstrap=\"vendor\u002Fautoload.php\"\n",[61,2743,2744],{"class":63,"line":110},[61,2745,2746],{},"         colors=\"true\"\n",[61,2748,2749],{"class":63,"line":122},[61,2750,2751],{},">\n",[61,2753,2754],{"class":63,"line":134},[61,2755,2756],{},"    \u003Ctestsuites>\n",[61,2758,2759],{"class":63,"line":146},[61,2760,2761],{},"        \u003Ctestsuite name=\"Http\">\n",[61,2763,2764],{"class":63,"line":158},[61,2765,2766],{},"            \u003Cdirectory>tests\u002FHttp\u003C\u002Fdirectory>\n",[61,2768,2769],{"class":63,"line":170},[61,2770,2771],{},"        \u003C\u002Ftestsuite>\n",[61,2773,2774],{"class":63,"line":182},[61,2775,2776],{},"        \u003Ctestsuite name=\"Unit\">\n",[61,2778,2779],{"class":63,"line":194},[61,2780,2781],{},"            \u003Cdirectory>tests\u002FUnit\u003C\u002Fdirectory>\n",[61,2783,2784],{"class":63,"line":206},[61,2785,2771],{},[61,2787,2788],{"class":63,"line":218},[61,2789,2790],{},"    \u003C\u002Ftestsuites>\n",[61,2792,2793],{"class":63,"line":226},[61,2794,2795],{},"    \u003Csource>\n",[61,2797,2798],{"class":63,"line":238},[61,2799,2800],{},"        \u003Cinclude>\n",[61,2802,2803],{"class":63,"line":250},[61,2804,2805],{},"            \u003Cdirectory>app\u003C\u002Fdirectory>\n",[61,2807,2808],{"class":63,"line":261},[61,2809,2810],{},"            \u003Cdirectory>config\u003C\u002Fdirectory>\n",[61,2812,2813],{"class":63,"line":267},[61,2814,2815],{},"            \u003Cdirectory>routes\u003C\u002Fdirectory>\n",[61,2817,2818],{"class":63,"line":279},[61,2819,2820],{},"        \u003C\u002Finclude>\n",[61,2822,2823],{"class":63,"line":291},[61,2824,2825],{},"    \u003C\u002Fsource>\n",[61,2827,2828],{"class":63,"line":304},[61,2829,2830],{},"    \u003Cphp>\n",[61,2832,2833],{"class":63,"line":316},[61,2834,2835],{},"        \u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>\n",[61,2837,2838],{"class":63,"line":328},[61,2839,2840],{},"        \u003Cenv name=\"APP_MAINTENANCE_DRIVER\" value=\"file\"\u002F>\n",[61,2842,2843],{"class":63,"line":340},[61,2844,2845],{},"        \u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>\n",[61,2847,2848],{"class":63,"line":348},[61,2849,2850],{},"        \u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>\n",[61,2852,2853],{"class":63,"line":357},[61,2854,2855],{},"        \u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>\n",[61,2857,2858],{"class":63,"line":365},[61,2859,2860],{},"        \u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>\n",[61,2862,2863],{"class":63,"line":373},[61,2864,2865],{},"        \u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>\n",[61,2867,2868],{"class":63,"line":381},[61,2869,2870],{},"        \u003Cenv name=\"PULSE_ENABLED\" value=\"false\"\u002F>\n",[61,2872,2873],{"class":63,"line":389},[61,2874,2875],{},"        \u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>\n",[61,2877,2878],{"class":63,"line":397},[61,2879,2880],{},"        \u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>\n",[61,2882,2883],{"class":63,"line":405},[61,2884,2885],{},"        \u003Cenv name=\"TELESCOPE_ENABLED\" value=\"false\"\u002F>\n",[61,2887,2888],{"class":63,"line":413},[61,2889,2890],{},"    \u003C\u002Fphp>\n",[61,2892,2893],{"class":63,"line":421},[61,2894,2895],{},"\u003C\u002Fphpunit>\n",[10,2897,2898],{},"This configuration defines the test suites, the application source files, and the environment used during tests:",[633,2900,2901,2907,2913,2919,2925,2931,2937,2943,2949,2955,2961,2967,2973,2979,2988,2995,3002,3008,3021,3032,3043,3054,3065,3076,3086,3096,3107,3117],{},[20,2902,2903,2906],{},[47,2904,2905],{},"\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>",": This line specifies the XML version and encoding.",[20,2908,2909,2912],{},[47,2910,2911],{},"\u003Cphpunit ...>",": This line starts the PHPUnit configuration.",[20,2914,2915,2918],{},[47,2916,2917],{},"xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"",": This attribute specifies the XML namespace for the schema instance.",[20,2920,2921,2924],{},[47,2922,2923],{},"xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"",": This attribute specifies the location of the XML schema for PHPUnit.",[20,2926,2927,2930],{},[47,2928,2929],{},"bootstrap=\"vendor\u002Fautoload.php\"",": This attribute specifies the bootstrap file for PHPUnit, which is responsible for loading the necessary dependencies.",[20,2932,2933,2936],{},[47,2934,2935],{},"colors=\"true\"",": This attribute enables colored output in the console.",[20,2938,2939,2942],{},[47,2940,2941],{},"\u003Ctestsuites>",": This section defines the test suites for the project.",[20,2944,2945,2948],{},[47,2946,2947],{},"\u003Ctestsuite name=\"Http\">",": This line defines a test suite named \"Http\".",[20,2950,2951,2954],{},[47,2952,2953],{},"\u003Cdirectory>tests\u002FHttp\u003C\u002Fdirectory>",": This line specifies the directory containing the tests for the \"Http\" test suite.",[20,2956,2957,2960],{},[47,2958,2959],{},"\u003Ctestsuite name=\"Unit\">",": This line defines a test suite named \"Unit\".",[20,2962,2963,2966],{},[47,2964,2965],{},"\u003Cdirectory>tests\u002FUnit\u003C\u002Fdirectory>",": This line specifies the directory containing the tests for the \"Unit\" test suite.",[20,2968,2969,2972],{},[47,2970,2971],{},"\u003Csource>",": This section defines the source directories for the project.",[20,2974,2975,2978],{},[47,2976,2977],{},"\u003Cinclude>",": This section includes the specified directories in the source.",[20,2980,2981,2984,2985,2987],{},[47,2982,2983],{},"\u003Cdirectory>app\u003C\u002Fdirectory>",": This line specifies the ",[47,2986,873],{}," directory as a source directory.",[20,2989,2990,2984,2993,2987],{},[47,2991,2992],{},"\u003Cdirectory>config\u003C\u002Fdirectory>",[47,2994,877],{},[20,2996,2997,2984,3000,2987],{},[47,2998,2999],{},"\u003Cdirectory>routes\u003C\u002Fdirectory>",[47,3001,884],{},[20,3003,3004,3007],{},[47,3005,3006],{},"\u003Cphp>",": This section defines the PHP environment variables for the project.",[20,3009,3010,3013,3014,3017,3018,1306],{},[47,3011,3012],{},"\u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>",": This line sets the ",[47,3015,3016],{},"APP_ENV"," environment variable to ",[47,3019,3020],{},"testing",[20,3022,3023,3013,3026,3017,3029,1306],{},[47,3024,3025],{},"\u003Cenv name=\"APP_MAINTENANCE_DRIVER\" value=\"file\"\u002F>",[47,3027,3028],{},"APP_MAINTENANCE_DRIVER",[47,3030,3031],{},"file",[20,3033,3034,3013,3037,3017,3040,1306],{},[47,3035,3036],{},"\u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>",[47,3038,3039],{},"BCRYPT_ROUNDS",[47,3041,3042],{},"4",[20,3044,3045,3013,3048,3017,3051,1306],{},[47,3046,3047],{},"\u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>",[47,3049,3050],{},"CACHE_STORE",[47,3052,3053],{},"array",[20,3055,3056,3013,3059,3017,3062,1306],{},[47,3057,3058],{},"\u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>",[47,3060,3061],{},"DB_CONNECTION",[47,3063,3064],{},"sqlite",[20,3066,3067,3013,3070,3017,3073,1306],{},[47,3068,3069],{},"\u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>",[47,3071,3072],{},"DB_DATABASE",[47,3074,3075],{},":memory:",[20,3077,3078,3013,3081,3017,3084,1306],{},[47,3079,3080],{},"\u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>",[47,3082,3083],{},"MAIL_MAILER",[47,3085,3053],{},[20,3087,3088,3013,3091,3017,3094,1306],{},[47,3089,3090],{},"\u003Cenv name=\"PULSE_ENABLED\" value=\"false\"\u002F>",[47,3092,3093],{},"PULSE_ENABLED",[47,3095,299],{},[20,3097,3098,3013,3101,3017,3104,1306],{},[47,3099,3100],{},"\u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>",[47,3102,3103],{},"QUEUE_CONNECTION",[47,3105,3106],{},"sync",[20,3108,3109,3013,3112,3017,3115,1306],{},[47,3110,3111],{},"\u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>",[47,3113,3114],{},"SESSION_DRIVER",[47,3116,3053],{},[20,3118,3119,3013,3122,3017,3125,1306],{},[47,3120,3121],{},"\u003Cenv name=\"TELESCOPE_ENABLED\" value=\"false\"\u002F>",[47,3123,3124],{},"TELESCOPE_ENABLED",[47,3126,299],{},[10,3128,3129],{},"These variables give the tests a predictable environment, which reduces flakiness and keeps the test setup simple.",[10,3131,3132,3133,3136,3137,3140,3141,3136,3144,1306],{},"Because we changed the integration-test folder from ",[47,3134,3135],{},"Feature"," to ",[47,3138,3139],{},"Http",", rename ",[47,3142,3143],{},"tests\u002FFeature",[47,3145,3146],{},"tests\u002FHttp",[52,3148,3150],{"className":891,"code":3149,"filename":893,"language":894,"meta":57,"style":57},"mv tests\u002FFeature\u002F** tests\u002FHttp\u002F** && sed -i '' 's\u002FFeature\u002FHttp\u002Fg' tests\u002FPest.php\n",[47,3151,3152],{"__ignoreMap":57},[61,3153,3154,3157,3160,3163,3166,3168,3171,3174,3177,3180,3183],{"class":63,"line":64},[61,3155,3156],{"class":901},"mv",[61,3158,3159],{"class":81}," tests\u002FFeature\u002F",[61,3161,3162],{"class":74},"**",[61,3164,3165],{"class":81}," tests\u002FHttp\u002F",[61,3167,3162],{"class":74},[61,3169,3170],{"class":67}," && ",[61,3172,3173],{"class":901},"sed",[61,3175,3176],{"class":74}," -i",[61,3178,3179],{"class":81}," ''",[61,3181,3182],{"class":81}," 's\u002FFeature\u002FHttp\u002Fg'",[61,3184,3185],{"class":81}," tests\u002FPest.php\n",[10,3187,3188],{},"In the tests folder, we now have two folders and two files:",[17,3190,3191,3196,3202,3208],{},[20,3192,3193,3195],{},[47,3194,3146],{},": This folder contains the integration tests for the application.",[20,3197,3198,3201],{},[47,3199,3200],{},"tests\u002FUnit",": This folder contains the unit tests for the application.",[20,3203,3204,3207],{},[47,3205,3206],{},"tests\u002FPest.php",": This file contains the Pest configuration.",[20,3209,3210,3213],{},[47,3211,3212],{},"tests\u002FTestCase.php",": This file contains the base test case for the application.",[10,3215,3216,3217,829],{},"Finally, let's add some custom commands to our ",[47,3218,828],{},[52,3220,3222],{"className":54,"code":3221,"filename":828,"language":56,"meta":57,"style":57},"{\n  \"scripts\": {\n    \"test:type-coverage\": \"pest --type-coverage --min=100\",\n    \"test:unit\": \"pest --parallel --coverage --min=100\",\n    \"test\": [\n      \"@test:lint\",\n      \"@test:refactor\",\n      \"@test:types\",\n      \"@test:type-coverage\",\n      \"@test:unit\"\n    ]\n  }\n}\n",[47,3223,3224,3228,3234,3246,3258,3265,3272,3279,3286,3293,3298,3303,3307],{"__ignoreMap":57},[61,3225,3226],{"class":63,"line":64},[61,3227,68],{"class":67},[61,3229,3230,3232],{"class":63,"line":71},[61,3231,843],{"class":74},[61,3233,94],{"class":67},[61,3235,3236,3239,3241,3244],{"class":63,"line":88},[61,3237,3238],{"class":74},"    \"test:type-coverage\"",[61,3240,78],{"class":67},[61,3242,3243],{"class":81},"\"pest --type-coverage --min=100\"",[61,3245,85],{"class":67},[61,3247,3248,3251,3253,3256],{"class":63,"line":97},[61,3249,3250],{"class":74},"    \"test:unit\"",[61,3252,78],{"class":67},[61,3254,3255],{"class":81},"\"pest --parallel --coverage --min=100\"",[61,3257,85],{"class":67},[61,3259,3260,3263],{"class":63,"line":110},[61,3261,3262],{"class":74},"    \"test\"",[61,3264,354],{"class":67},[61,3266,3267,3270],{"class":63,"line":122},[61,3268,3269],{"class":81},"      \"@test:lint\"",[61,3271,85],{"class":67},[61,3273,3274,3277],{"class":63,"line":134},[61,3275,3276],{"class":81},"      \"@test:refactor\"",[61,3278,85],{"class":67},[61,3280,3281,3284],{"class":63,"line":146},[61,3282,3283],{"class":81},"      \"@test:types\"",[61,3285,85],{"class":67},[61,3287,3288,3291],{"class":63,"line":158},[61,3289,3290],{"class":81},"      \"@test:type-coverage\"",[61,3292,85],{"class":67},[61,3294,3295],{"class":63,"line":170},[61,3296,3297],{"class":81},"      \"@test:unit\"\n",[61,3299,3300],{"class":63,"line":182},[61,3301,3302],{"class":67},"    ]\n",[61,3304,3305],{"class":63,"line":194},[61,3306,622],{"class":67},[61,3308,3309],{"class":63,"line":206},[61,3310,628],{"class":67},[10,3312,3313],{},"These commands do the following:",[633,3315,3316,3325,3337],{},[20,3317,3318,3321,3322,1306],{},[47,3319,3320],{},"test:type-coverage",": Runs the tests with type coverage and requires 100% coverage through ",[47,3323,3324],{},"--min=100",[20,3326,3327,3330,3331,3334,3335,1306],{},[47,3328,3329],{},"test:unit",": Runs the tests with line coverage and requires every line to be covered through ",[47,3332,3333],{},"--coverage"," and ",[47,3336,3324],{},[20,3338,3339,3342],{},[47,3340,3341],{},"test",": Runs linting, refactoring, type checking, type coverage, and the test suite. This is the command we will use in CI.",[10,3344,3345,3346,3348],{},"To have the command ",[47,3347,3320],{}," working, we need to install a plugin for Pest:",[52,3350,3352],{"className":891,"code":3351,"filename":893,"language":894,"meta":57,"style":57},"composer require pestphp\u002Fpest-plugin-type-coverage --dev\n",[47,3353,3354],{"__ignoreMap":57},[61,3355,3356,3358,3360,3363],{"class":63,"line":64},[61,3357,1487],{"class":901},[61,3359,1490],{"class":81},[61,3361,3362],{"class":81}," pestphp\u002Fpest-plugin-type-coverage",[61,3364,1496],{"class":74},[812,3366,3367],{"color":814,"icon":815},[10,3368,3369,3370,1306],{},"Code coverage requires ",[47,3371,3372],{},"xdebug",[36,3374,3376],{"id":3375},"final-thoughts","Final thoughts",[10,3378,3379],{},"With Pint, Rector, Larastan, and Pest configured, the project now has a repeatable quality workflow. Formatting, refactoring, static analysis, and tests can support us as the codebase grows instead of becoming cleanup work we postpone.",[10,3381,3382],{},"The Laravel foundation is ready, so we can start building features on top of it. Next, we will add GitHub authentication with Socialite so users can identify themselves before they manage comments.",[3384,3385,3386],"style",{},"html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}",{"title":57,"searchDepth":71,"depth":71,"links":3388},[3389,3390,3391,3392,3393],{"id":38,"depth":71,"text":39},{"id":1364,"depth":71,"text":1365},{"id":2203,"depth":71,"text":2204},{"id":2699,"depth":71,"text":2700},{"id":3375,"depth":71,"text":3376},"d566d5f4-3c4a-44e5-89cb-b3c547673ffa","2025-02-25","Explore the four indispensable tools for maintaining code quality and consistency in Laravel projects: Pint, Rector, Larastan, and Pest.","md",null,{},"\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fpint-larastan-rector-and-pest-essential-for-success","---\ncontentId: d566d5f4-3c4a-44e5-89cb-b3c547673ffa\npart: 2\ntitle: \"Pint, Rector, Larastan, and Pest: Essentials for Success\"\ndescription: \"Explore the four indispensable tools for maintaining code quality and consistency in Laravel projects: Pint, Rector, Larastan, and Pest.\"\ndate: 2025-02-25\nseriesSlug: empower-and-dynamize-our-vitepress-blog-with-a-laravel-api\n---\n\nNow that the Laravel project is in place and its structure is familiar, it is time to make the codebase easier to maintain.\n\nAs the project grows, consistent formatting, automated refactoring, static analysis, and tests will help us move quickly without losing confidence. In this article, we will configure four tools that support that workflow: Pint, Rector, Larastan, and Pest.\n\n1. Pint formats PHP code according to a consistent style. In the JavaScript ecosystem, it is closest to Prettier or ESLint's formatting rules.\n2. Rector refactors PHP code automatically. It can modernize syntax, remove deprecated patterns, and apply project-wide improvements.\n3. Larastan performs static analysis tailored to Laravel. It catches many potential problems before the code runs.\n4. Pest is a testing framework focused on simple, expressive tests. It is the closest PHP equivalent to tools such as Jest in the JavaScript ecosystem.\n\nUsing these tools from the start keeps the codebase easier to maintain and gives future contributors a clear, consistent foundation. It also saves time as the project grows.\n\n## Pint\n\nPint comes pre-installed with Laravel, so there is nothing to install. We only need to configure it and add a Composer script for formatting the code.\n\nCreate a `pint.json` file in the project root. This file lets us choose the rules that should be applied across the codebase.\n\n```json [pint.json]\n{\n  \"preset\": \"laravel\",\n  \"rules\": {\n    \"array_push\": true,\n    \"backtick_to_shell_exec\": true,\n    \"date_time_immutable\": true,\n    \"declare_strict_types\": true,\n    \"lowercase_keywords\": true,\n    \"lowercase_static_reference\": true,\n    \"final_class\": true,\n    \"final_internal_class\": true,\n    \"final_public_method_for_abstract_class\": true,\n    \"fully_qualified_strict_types\": true,\n    \"global_namespace_import\": {\n      \"import_classes\": true,\n      \"import_constants\": true,\n      \"import_functions\": true\n    },\n    \"mb_str_functions\": true,\n    \"modernize_types_casting\": true,\n    \"new_with_parentheses\": false,\n    \"no_superfluous_elseif\": true,\n    \"no_useless_else\": true,\n    \"no_multiple_statements_per_line\": true,\n    \"ordered_class_elements\": {\n      \"order\": [\n        \"use_trait\",\n        \"case\",\n        \"constant\",\n        \"constant_public\",\n        \"constant_protected\",\n        \"constant_private\",\n        \"property_public\",\n        \"property_protected\",\n        \"property_private\",\n        \"construct\",\n        \"destruct\",\n        \"magic\",\n        \"phpunit\",\n        \"method_abstract\",\n        \"method_public_static\",\n        \"method_public\",\n        \"method_protected_static\",\n        \"method_protected\",\n        \"method_private_static\",\n        \"method_private\"\n      ],\n      \"sort_algorithm\": \"none\"\n    },\n    \"ordered_interfaces\": true,\n    \"ordered_traits\": true,\n    \"protected_to_private\": true,\n    \"self_accessor\": true,\n    \"self_static_accessor\": true,\n    \"strict_comparison\": true,\n    \"visibility_required\": true\n  }\n}\n```\n\nLet's break down the configuration:\n\n- `preset`: This option allows you to choose a preset configuration for Pint. In this case, we are using the `laravel` preset, which comes with a set of recommended rules for Laravel projects.\n- `rules`: This section contains the specific rules we want to apply to our codebase. Each rule can be set to `true` or `false`, depending on whether we want to enable or disable it.\n- `array_push`: Enforces the use of array push syntax instead of array merging.\n- `backtick_to_shell_exec`: Converts backticks to the `shell_exec` function.\n- `date_time_immutable`: Enforces the use of immutable date and time objects.\n- `declare_strict_types`: Enforces the use of strict types in PHP files.\n- `lowercase_keywords`: Enforces the use of lowercase keywords in PHP.\n- `lowercase_static_reference`: Enforces the use of lowercase static references in PHP.\n- `final_class`: Enforces the use of final classes.\n- `final_internal_class`: Enforces the use of final classes for internal classes.\n- `final_public_method_for_abstract_class`: Enforces the use of final public methods for abstract classes.\n- `fully_qualified_strict_types`: Enforces the use of fully qualified strict types in PHP files.\n- `global_namespace_import`: Enforces the use of global namespace imports for classes, constants, and functions.\n- `mb_str_functions`: Enforces the use of multibyte string functions.\n- `modernize_types_casting`: Enforces the use of modern type casting in PHP.\n- `new_with_parentheses`: Enforces the use of parentheses when creating new objects.\n- `no_superfluous_elseif`: Enforces the removal of superfluous elseif statements.\n- `no_useless_else`: Enforces the removal of useless else statements.\n- `no_multiple_statements_per_line`: Enforces the use of a single statement per line.\n- `ordered_class_elements`: Enforces the ordering of class elements, such as traits, constants, properties, and methods.\n- `ordered_interfaces`: Enforces the ordering of interfaces.\n- `ordered_traits`: Enforces the ordering of traits.\n- `protected_to_private`: Enforces the use of private visibility for properties and methods.\n- `self_accessor`: Enforces the use of self accessors for properties and methods.\n- `self_static_accessor`: Enforces the use of self static accessors for properties and methods.\n- `strict_comparison`: Enforces the use of strict comparison operators.\n- `visibility_required`: Enforces the use of visibility keywords for properties and methods.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nIf you have questions about any of these rules, feel free to ask in the comments.\n::\n\nNow, let's add a custom command to lint our code. We will add a `lint` command to our `composer.json` file:\n\n```json [composer.json]\n{\n  \"scripts\": {\n    \"lint\": \"pint\"\n  }\n}\n```\n\nFrom now on, we can run `composer lint` to format the code. Pint will process the files in the `app`, `config`, `database`, and `routes` folders and keep their style consistent.\n\nYou should see something like this:\n\n```bash [terminal]\n➜ composer lint\n> pint\n\n  ✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓✓\n\n  ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Laravel\n    FIXED   ......................................................................................................................... 26 files, 26 style issues fixed\n  ✓ app\u002FHttp\u002FControllers\u002FController.php                                                                            declare_strict_types, blank_line_after_opening_tag\n  ✓ app\u002FModels\u002FUser.php                                                                               final_class, declare_strict_types, blank_line_after_opening_tag\n  ✓ app\u002FProviders\u002FAppServiceProvider.php                                                              final_class, declare_strict_types, blank_line_after_opening_tag\n  ✓ bootstrap\u002Fapp.php                                                                                              declare_strict_types, blank_line_after_opening_tag\n  ✓ bootstrap\u002Fproviders.php                                                                                        declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fapp.php                                                                                                 declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fauth.php                                                                                                declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fcache.php                                                                                               declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fdatabase.php                                                                                            declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Ffilesystems.php                                                                                         declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Flogging.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fmail.php                                                                                                declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fqueue.php                                                                                               declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fservices.php                                                                                            declare_strict_types, blank_line_after_opening_tag\n  ✓ config\u002Fsession.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ database\u002Ffactories\u002FUserFactory.php                                          final_class, self_static_accessor, declare_strict_types, blank_line_after_opening_tag\n  ✓ database\u002Fmigrations\u002F0001_01_01_000000_create_users_table.php                class_definition, declare_strict_types, blank_line_after_opening_tag, braces_position\n  ✓ database\u002Fmigrations\u002F0001_01_01_000001_create_cache_table.php                class_definition, declare_strict_types, blank_line_after_opening_tag, braces_position\n  ✓ database\u002Fmigrations\u002F0001_01_01_000002_create_jobs_table.php                 class_definition, declare_strict_types, blank_line_after_opening_tag, braces_position\n  ✓ database\u002Fseeders\u002FDatabaseSeeder.php                                                               final_class, declare_strict_types, blank_line_after_opening_tag\n  ✓ public\u002Findex.php                                                                                               declare_strict_types, blank_line_after_opening_tag\n  ✓ routes\u002Fconsole.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ routes\u002Fweb.php                                                                                                 declare_strict_types, blank_line_after_opening_tag\n  ✓ tests\u002FFeature\u002FExampleTest.php                                                                                  declare_strict_types, blank_line_after_opening_tag\n  ✓ tests\u002FTestCase.php                                                                                             declare_strict_types, blank_line_after_opening_tag\n  ✓ tests\u002FUnit\u002FExampleTest.php                                                                                     declare_strict_types, blank_line_after_opening_tag\n```\n\nThe output shows each file and the rules that Pint applied. A `✓` means that Pint changed the file; a `.` means that the file was already formatted correctly.\n\nWe will also add a `test:lint` command for CI. Instead of changing files, it checks the formatting and exits with an error if a file needs changes.\n\n```json [composer.json]\n{\n  \"scripts\": {\n    \"lint\": \"pint\",\n    \"test:lint\": \"pint --test\"\n  }\n}\n```\n\nPerfect!\n\n## Rector\n\nThe second tool is Rector, which complements Pint. Pint changes formatting, while Rector changes the structure and behavior of the code according to its rules. For example:\n\n```php [Example]\nclass SomeClass\n{\n    public function getValue(int $number)\n    {\n        if ($number) {\n            return 100;\n        }\n\n        return 500;\n    }\n}\n```\n\nWould be refactored to this:\n\n```php [Example]\nfinal class SomeClass\n{\n    public function getValue(int $number): int\n    {\n        return $number ? 100 : 500;\n    }\n}\n```\n\nBy applying the `ReturnTypeFromStrictTernaryRector` rule.\n\nLet's install Rector with Composer:\n\n```bash [terminal]\ncomposer require rector\u002Frector --dev\n```\n\nCreate a `rector.php` configuration file:\n\n```php [rector.php]\n\u003C?php\n\ndeclare(strict_types=1);\n\nuse Rector\\Config\\RectorConfig;\n\nreturn RectorConfig::configure()\n    ->withPaths([\n        __DIR__.'\u002Fapp',\n        __DIR__.'\u002Fbootstrap\u002Fapp.php',\n        __DIR__.'\u002Fconfig',\n        __DIR__.'\u002Fdatabase',\n        __DIR__.'\u002Fpublic',\n    ])\n    ->withPreparedSets(\n        deadCode: true,\n        codeQuality: true,\n        typeDeclarations: true,\n        privatization: true,\n        earlyReturn: true,\n        strictBooleans: true,\n    )\n    ->withPhpSets();\n```\n\nThis configuration is a little more involved than Pint's. Here is what each part does:\n\n- `declare(strict_types=1)`: This line enables strict typing in the file, ensuring that PHP enforces type declarations.\n- `use Rector\\Config\\RectorConfig`: This line imports the `RectorConfig` class, which is used to configure Rector.\n- `return RectorConfig::configure()`: This line starts the configuration process for Rector.\n- `->withPaths([...])`: This method specifies the paths to the directories and files that Rector should analyze and refactor. In this case, we are including the `app`, `bootstrap\u002Fapp.php`, `config`, `database`, and `public` directories.\n- `->withPreparedSets(...)`: This method allows you to enable predefined sets of rules for Rector. In this case, we are enabling several sets:\n  - `deadCode`: Removes dead code from the project.\n  - `codeQuality`: Improves code quality by applying various best practices.\n  - `typeDeclarations`: Adds type declarations to functions and methods.\n  - `privatization`: Makes properties and methods private when possible.\n  - `earlyReturn`: Applies early return patterns to improve readability.\n  - `strictBooleans`: Enforces strict boolean comparisons.\n- `->withPhpSets()`: This method enables a set of rules specifically designed for PHP.\n\nNow, let's add a custom command to our `composer.json` file:\n\n```json [composer.json]\n{\n  \"scripts\": {\n    \"refactor\": \"rector\"\n  }\n}\n```\n\nWe can now run `composer refactor`. Rector will inspect the files in `app`, `bootstrap\u002Fapp.php`, `config`, `database`, and `public` and apply the configured transformations. You should see output similar to this:\n\n```bash [terminal]\n➜ composer refactor\n> rector\n 20\u002F20 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n8 files with changes\n====================\n\n1) database\u002Fmigrations\u002F0001_01_01_000001_create_cache_table.php:12\n\n    ---------- begin diff ----------\n@@ @@\n      *\u002F\n     public function up(): void\n     {\n-        Schema::create('cache', function (Blueprint $table) {\n+        Schema::create('cache', function (Blueprint $table): void {\n             $table->string('key')->primary();\n             $table->mediumText('value');\n             $table->integer('expiration');\n         });\n\n-        Schema::create('cache_locks', function (Blueprint $table) {\n+        Schema::create('cache_locks', function (Blueprint $table): void {\n             $table->string('key')->primary();\n             $table->string('owner');\n             $table->integer('expiration');\n    ----------- end diff -----------\n\nApplied rules:\n * AddClosureVoidReturnTypeWhereNoReturnRector\n#  ...\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe output is shortened here. Your terminal should list every file that Rector modified.\n::\n\nThe output lists each modified file, shows a diff, and identifies the rules that were applied.\n\nWe will also add a `test:refactor` command for CI. It runs Rector in dry-run mode and reports changes without modifying files.\n\n```json [composer.json]\n{\n  \"scripts\": {\n    \"refactor\": \"rector\",\n    \"test:refactor\": \"rector --dry-run\"\n  }\n}\n```\n\n## Larastan\n\nInstall Larastan with Composer:\n\n```bash [terminal]\ncomposer require --dev \"larastan\u002Flarastan:^3.0\"\n```\n\nCreate a `phpstan.neon` file:\n\n```yml [phpstan.neon]\nincludes:\n  - vendor\u002Flarastan\u002Flarastan\u002Fextension.neon\n  - vendor\u002Fphpstan\u002Fphpstan\u002Fconf\u002FbleedingEdge.neon\n\nparameters:\n  level: 6\n\n  paths:\n    - app\n    - config\n    - bootstrap\n    - database\u002Ffactories\n    - routes\n```\n\nThis configuration tells Larastan what to load and which parts of the project to analyze:\n\n- `includes`: This section includes additional configuration files that extend the functionality of Larastan. In this case, we are including the `larastan\u002Flarastan\u002Fextension.neon` file and the `phpstan\u002Fphpstan\u002Fconf\u002FbleedingEdge.neon` file.\n- `parameters`: This section contains the main configuration parameters for Larastan.\n- `level`: This parameter sets the strictness of the analysis. Higher levels catch more potential issues but can also produce more false positives. Level 6 is a reasonable balance for this project, but starting at level 2 and increasing it gradually is also a good approach.\n- `paths`: This parameter specifies the paths to the directories and files that Larastan should analyze. In this case, we are including the `app`, `config`, `bootstrap`, `database\u002Ffactories`, and `routes` directories.\n\nNow, let's add a custom command to our `composer.json` file:\n\n```json [composer.json]\n{\n  \"scripts\": {\n    \"test:types\": \"phpstan analyse\"\n  }\n}\n```\n\nUnlike Pint and Rector, Larastan isn't automatic and can't fix the code for you. Instead, it will raise errors and warnings that you need to fix manually.\n\nRun `composer test:types` to analyze the files in `app`, `config`, `bootstrap`, `database\u002Ffactories`, and `routes`. Larastan reports problems that must be fixed manually. You should see output similar to this:\n\n```bash [terminal]\n➜ composer test:types\n> phpstan analyse\nNote: Using configuration file \u002FUsers\u002Fesoub\u002Fdev\u002Fp\u002Fmimram\u002Fphpstan.neon.\n 20\u002F20 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n\n ------ ---------------------------\n  Line   routes\u002Fconsole.php\n ------ ---------------------------\n  :9     Undefined variable: $this\n         🪪  variable.undefined\n ------ ---------------------------\n\n [ERROR] Found 1 error\n\nScript phpstan analyse handling the test:types event returned with error code 1\n```\n\nThe error comes from the default command in `routes\u002Fconsole.php`, which we do not need for this project. Remove that command to fix it.\n\n```php [routes\u002Fconsole.php]\n\u003C?php\n\nuse Illuminate\\Foundation\\Inspiring; \u002F\u002F [!code --]\nuse Illuminate\\Support\\Facades\\Artisan; \u002F\u002F [!code --]\n\nArtisan::command('inspire', function () { \u002F\u002F [!code --]\n    $this->comment(Inspiring::quote()); \u002F\u002F [!code --]\n})->purpose('Display an inspiring quote'); \u002F\u002F [!code --]\n```\n\nRun `composer test:types` again:\n\n```bash [terminal]\n➜ composer test:types\n> phpstan analyse\nNote: Using configuration file \u002FUsers\u002Fesoub\u002Fdev\u002Fp\u002Fmimram\u002Fphpstan.neon.\n 20\u002F20 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%\n\n [OK] No errors\n```\n\n## Pest\n\nThe last tool is Pest, a PHP testing framework focused on simple, expressive tests. Pest is the default testing framework in a new Laravel project, so there is nothing to install.\n\nWe will configure it and add a few custom commands to `composer.json`.\n\nFirst, let's edit the `phpunit.xml` file:\n\n```xml [phpunit.xml]\n\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\u003Cphpunit xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"\n         xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"\n         bootstrap=\"vendor\u002Fautoload.php\"\n         colors=\"true\"\n>\n    \u003Ctestsuites>\n        \u003Ctestsuite name=\"Http\">\n            \u003Cdirectory>tests\u002FHttp\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n        \u003Ctestsuite name=\"Unit\">\n            \u003Cdirectory>tests\u002FUnit\u003C\u002Fdirectory>\n        \u003C\u002Ftestsuite>\n    \u003C\u002Ftestsuites>\n    \u003Csource>\n        \u003Cinclude>\n            \u003Cdirectory>app\u003C\u002Fdirectory>\n            \u003Cdirectory>config\u003C\u002Fdirectory>\n            \u003Cdirectory>routes\u003C\u002Fdirectory>\n        \u003C\u002Finclude>\n    \u003C\u002Fsource>\n    \u003Cphp>\n        \u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>\n        \u003Cenv name=\"APP_MAINTENANCE_DRIVER\" value=\"file\"\u002F>\n        \u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>\n        \u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>\n        \u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>\n        \u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>\n        \u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>\n        \u003Cenv name=\"PULSE_ENABLED\" value=\"false\"\u002F>\n        \u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>\n        \u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>\n        \u003Cenv name=\"TELESCOPE_ENABLED\" value=\"false\"\u002F>\n    \u003C\u002Fphp>\n\u003C\u002Fphpunit>\n```\n\nThis configuration defines the test suites, the application source files, and the environment used during tests:\n\n- `\u003C?xml version=\"1.0\" encoding=\"UTF-8\"?>`: This line specifies the XML version and encoding.\n- `\u003Cphpunit ...>`: This line starts the PHPUnit configuration.\n- `xmlns:xsi=\"http:\u002F\u002Fwww.w3.org\u002F2001\u002FXMLSchema-instance\"`: This attribute specifies the XML namespace for the schema instance.\n- `xsi:noNamespaceSchemaLocation=\"vendor\u002Fphpunit\u002Fphpunit\u002Fphpunit.xsd\"`: This attribute specifies the location of the XML schema for PHPUnit.\n- `bootstrap=\"vendor\u002Fautoload.php\"`: This attribute specifies the bootstrap file for PHPUnit, which is responsible for loading the necessary dependencies.\n- `colors=\"true\"`: This attribute enables colored output in the console.\n- `\u003Ctestsuites>`: This section defines the test suites for the project.\n- `\u003Ctestsuite name=\"Http\">`: This line defines a test suite named \"Http\".\n- `\u003Cdirectory>tests\u002FHttp\u003C\u002Fdirectory>`: This line specifies the directory containing the tests for the \"Http\" test suite.\n- `\u003Ctestsuite name=\"Unit\">`: This line defines a test suite named \"Unit\".\n- `\u003Cdirectory>tests\u002FUnit\u003C\u002Fdirectory>`: This line specifies the directory containing the tests for the \"Unit\" test suite.\n- `\u003Csource>`: This section defines the source directories for the project.\n- `\u003Cinclude>`: This section includes the specified directories in the source.\n- `\u003Cdirectory>app\u003C\u002Fdirectory>`: This line specifies the `app` directory as a source directory.\n- `\u003Cdirectory>config\u003C\u002Fdirectory>`: This line specifies the `config` directory as a source directory.\n- `\u003Cdirectory>routes\u003C\u002Fdirectory>`: This line specifies the `routes` directory as a source directory.\n- `\u003Cphp>`: This section defines the PHP environment variables for the project.\n- `\u003Cenv name=\"APP_ENV\" value=\"testing\"\u002F>`: This line sets the `APP_ENV` environment variable to `testing`.\n- `\u003Cenv name=\"APP_MAINTENANCE_DRIVER\" value=\"file\"\u002F>`: This line sets the `APP_MAINTENANCE_DRIVER` environment variable to `file`.\n- `\u003Cenv name=\"BCRYPT_ROUNDS\" value=\"4\"\u002F>`: This line sets the `BCRYPT_ROUNDS` environment variable to `4`.\n- `\u003Cenv name=\"CACHE_STORE\" value=\"array\"\u002F>`: This line sets the `CACHE_STORE` environment variable to `array`.\n- `\u003Cenv name=\"DB_CONNECTION\" value=\"sqlite\"\u002F>`: This line sets the `DB_CONNECTION` environment variable to `sqlite`.\n- `\u003Cenv name=\"DB_DATABASE\" value=\":memory:\"\u002F>`: This line sets the `DB_DATABASE` environment variable to `:memory:`.\n- `\u003Cenv name=\"MAIL_MAILER\" value=\"array\"\u002F>`: This line sets the `MAIL_MAILER` environment variable to `array`.\n- `\u003Cenv name=\"PULSE_ENABLED\" value=\"false\"\u002F>`: This line sets the `PULSE_ENABLED` environment variable to `false`.\n- `\u003Cenv name=\"QUEUE_CONNECTION\" value=\"sync\"\u002F>`: This line sets the `QUEUE_CONNECTION` environment variable to `sync`.\n- `\u003Cenv name=\"SESSION_DRIVER\" value=\"array\"\u002F>`: This line sets the `SESSION_DRIVER` environment variable to `array`.\n- `\u003Cenv name=\"TELESCOPE_ENABLED\" value=\"false\"\u002F>`: This line sets the `TELESCOPE_ENABLED` environment variable to `false`.\n\nThese variables give the tests a predictable environment, which reduces flakiness and keeps the test setup simple.\n\nBecause we changed the integration-test folder from `Feature` to `Http`, rename `tests\u002FFeature` to `tests\u002FHttp`.\n\n```bash [terminal]\nmv tests\u002FFeature\u002F** tests\u002FHttp\u002F** && sed -i '' 's\u002FFeature\u002FHttp\u002Fg' tests\u002FPest.php\n```\n\nIn the tests folder, we now have two folders and two files:\n\n1. `tests\u002FHttp`: This folder contains the integration tests for the application.\n2. `tests\u002FUnit`: This folder contains the unit tests for the application.\n3. `tests\u002FPest.php`: This file contains the Pest configuration.\n4. `tests\u002FTestCase.php`: This file contains the base test case for the application.\n\nFinally, let's add some custom commands to our `composer.json` file:\n\n```json [composer.json]\n{\n  \"scripts\": {\n    \"test:type-coverage\": \"pest --type-coverage --min=100\",\n    \"test:unit\": \"pest --parallel --coverage --min=100\",\n    \"test\": [\n      \"@test:lint\",\n      \"@test:refactor\",\n      \"@test:types\",\n      \"@test:type-coverage\",\n      \"@test:unit\"\n    ]\n  }\n}\n```\n\nThese commands do the following:\n\n- `test:type-coverage`: Runs the tests with type coverage and requires 100% coverage through `--min=100`.\n- `test:unit`: Runs the tests with line coverage and requires every line to be covered through `--coverage` and `--min=100`.\n- `test`: Runs linting, refactoring, type checking, type coverage, and the test suite. This is the command we will use in CI.\n\nTo have the command `test:type-coverage` working, we need to install a plugin for Pest:\n\n```bash [terminal]\ncomposer require pestphp\u002Fpest-plugin-type-coverage --dev\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nCode coverage requires `xdebug`.\n::\n\n## Final thoughts\n\nWith Pint, Rector, Larastan, and Pest configured, the project now has a repeatable quality workflow. Formatting, refactoring, static analysis, and tests can support us as the codebase grows instead of becoming cleanup work we postpone.\n\nThe Laravel foundation is ready, so we can start building features on top of it. Next, we will add GitHub authentication with Socialite so users can identify themselves before they manage comments.\n",{"title":5,"description":3396},"empower-and-dynamize-our-vitepress-blog-with-a-laravel-api",{"loc":3400},"series\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fpint-larastan-rector-and-pest-essential-for-success","tcT6BNQIAp84sApgdvc3hKmvirjNQ1bEROFzLOrEE44",{"overview":3408,"chapters":3579},{"id":3409,"title":3410,"body":3411,"contentId":3564,"date":3565,"description":3566,"extension":3397,"github":3398,"meetTheInstructor":3567,"meta":3568,"navigation":922,"part":3398,"path":3569,"rawbody":3570,"robots":3398,"schemaOrg":3398,"seo":3571,"seriesSlug":3403,"sitemap":3572,"stem":3573,"subtitle":3574,"topics":3575,"__hash__":3578},"series\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api.md","Empower and Enhance Your VitePress Blog with a Laravel API",{"type":7,"value":3412,"toc":3561},[3413,3416,3419,3422,3426,3437,3440,3449,3452,3455,3532,3535,3538,3541,3551,3555],[10,3414,3415],{},"Hello! 👋",[10,3417,3418],{},"After building our VitePress blog, we are ready to make it more dynamic with a Laravel API.",[10,3420,3421],{},"In the previous series, we explored VitePress from the initial project setup to deployment on Cloudflare Pages. We built a functional, automated blog with SEO metadata, Open Graph images, and a GitHub projects page. The blog handled everything at build time, so publishing content was the only task left.",[3423,3424],"callout-read-more",{"id":3425},"43c95b33-041c-4108-ab98-0d21ef60ed7f",[10,3427,3428,3429,3436],{},"This series introduces back-end development by creating a ",[3430,3431,3435],"a",{"href":3432,"rel":3433},"https:\u002F\u002Flaravel.com",[3434],"nofollow","Laravel"," API that gives our blog a few interactive features.",[10,3438,3439],{},"Until now, our blog has been mostly static. Content was generated at build time, with a small amount of data loaded dynamically, and the resulting HTML files were distributed through a CDN. By adding a Laravel API, we will let readers interact with the blog through features such as post reactions and comments.",[10,3441,3442,3443,3448],{},"Although the focus is on the back end, we will also integrate the API into our VitePress blog. We will use Vue.js and ",[3430,3444,3447],{"href":3445,"rel":3446},"https:\u002F\u002Fpinia-colada.esm.dev\u002F",[3434],"Pinia Colada"," as our data-fetching framework. VitePress is a Vue.js application, so we can extend it with the components we need.",[10,3450,3451],{},"The examples are designed to be easy to follow. Unnecessary complexity and over-engineering are neither desirable nor necessary here. We will focus on simplicity, clarity, and efficiency.",[10,3453,3454],{},"Throughout the series, we will build a Laravel API and integrate it with our VitePress blog. We will cover:",[633,3456,3457,3464,3487,3498,3504,3514,3520,3526],{},[20,3458,3459,3463],{},[3460,3461,3462],"strong",{},"Setting up the Laravel project",": Create a new Laravel project and become familiar with its structure.",[20,3465,3466,3469,3470,874,3474,874,3478,881,3482,3486],{},[3460,3467,3468],{},"Improving the development workflow",": Configure ",[3430,3471,39],{"href":3472,"rel":3473},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fpint",[3434],[3430,3475,1365],{"href":3476,"rel":3477},"https:\u002F\u002Fgithub.com\u002Frectorphp\u002Frector",[3434],[3430,3479,2204],{"href":3480,"rel":3481},"https:\u002F\u002Fgithub.com\u002Flarastan\u002Flarastan",[3434],[3430,3483,2700],{"href":3484,"rel":3485},"https:\u002F\u002Fpestphp.com\u002F",[3434]," for formatting, refactoring, static analysis, and testing.",[20,3488,3489,3492,3493,1306],{},[3460,3490,3491],{},"Adding social authentication",": Let users sign in with GitHub through ",[3430,3494,3497],{"href":3495,"rel":3496},"https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fsocialite",[3434],"Laravel Socialite",[20,3499,3500,3503],{},[3460,3501,3502],{},"Connecting the applications",": Configure Sanctum, CORS, CSRF protection, and the first requests between the VitePress frontend and the Laravel API.",[20,3505,3506,3509,3510,3513],{},[3460,3507,3508],{},"Managing authentication state",": Use ",[3430,3511,3447],{"href":3445,"rel":3512},[3434]," to retrieve the current user and log out with an optimistic update.",[20,3515,3516,3519],{},[3460,3517,3518],{},"Building the comment API",": Create the models, relationships, endpoints, validation, authorization, and tests for comments.",[20,3521,3522,3525],{},[3460,3523,3524],{},"Keeping the backend in sync",": Generate post metadata from VitePress and synchronize it with the Laravel database.",[20,3527,3528,3531],{},[3460,3529,3530],{},"Building the comment interface",": Fetch, create, edit, and delete comments from the VitePress frontend.",[10,3533,3534],{},"By the end of the series, you will have a blog backed by a Laravel API. Readers will be able to sign in with GitHub and leave comments, and the architecture will be ready for additional interactive features.",[10,3536,3537],{},"Testing is part of the development process and will be included at each stage, so it does not need a dedicated article.",[10,3539,3540],{},"If you have questions, feedback, or suggestions, feel free to share them in the comments. Your input helps improve the series.",[812,3542,3543],{"color":814,"icon":815},[10,3544,3545,3546,3550],{},"This series assumes prior knowledge of TypeScript, Vue.js, and Laravel. If you are unfamiliar with any of these technologies, review the ",[3430,3547,3549],{"href":3548},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","Create a Blog with VitePress and Vue.js from Scratch"," first.",[36,3552,3554],{"id":3553},"chapters","Chapters",[3556,3557],"series-chapters-list",{"className":3558},[3559,3560],"mx-auto","max-w-5xl",{"title":57,"searchDepth":71,"depth":71,"links":3562},[3563],{"id":3553,"depth":71,"text":3554},"676d45dd-eb18-42ec-803e-b9d6b7f04b42","2024-11-19","Transform your VitePress blog into a dynamic platform with a Laravel API. Leverage backend API capabilities to create advanced features.","I create this series because I love \u003Cstrong>VitePress\u003C\u002Fstrong> and \u003Cstrong>Laravel\u003C\u002Fstrong>. I truly believe that combining the two results in a simple yet \u003Cstrong>powerful solution\u003C\u002Fstrong> for creating a blog. I want to empower developers to enhance their VitePress blogs with a Laravel API to create advanced features.",{},"\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api","---\ncontentId: 676d45dd-eb18-42ec-803e-b9d6b7f04b42\ntitle: Empower and Enhance Your VitePress Blog with a Laravel API\nsubtitle: Transform your VitePress blog into a dynamic platform with an API\ndescription: Transform your VitePress blog into a dynamic platform with a Laravel API. Leverage backend API capabilities to create advanced features.\ndate: 2024-11-19\ntopics:\n  - laravel\n  - vitepress\n  - api\nmeetTheInstructor: I create this series because I love \u003Cstrong>VitePress\u003C\u002Fstrong> and \u003Cstrong>Laravel\u003C\u002Fstrong>. I truly believe that combining the two results in a simple yet \u003Cstrong>powerful solution\u003C\u002Fstrong> for creating a blog. I want to empower developers to enhance their VitePress blogs with a Laravel API to create advanced features.\nseriesSlug: empower-and-dynamize-our-vitepress-blog-with-a-laravel-api\n---\n\nHello! 👋\n\nAfter building our VitePress blog, we are ready to make it more dynamic with a Laravel API.\n\nIn the previous series, we explored VitePress from the initial project setup to deployment on Cloudflare Pages. We built a functional, automated blog with SEO metadata, Open Graph images, and a GitHub projects page. The blog handled everything at build time, so publishing content was the only task left.\n\n\u003CCalloutReadMore id=\"43c95b33-041c-4108-ab98-0d21ef60ed7f\" \u002F>\n\nThis series introduces back-end development by creating a [Laravel](https:\u002F\u002Flaravel.com) API that gives our blog a few interactive features.\n\nUntil now, our blog has been mostly static. Content was generated at build time, with a small amount of data loaded dynamically, and the resulting HTML files were distributed through a CDN. By adding a Laravel API, we will let readers interact with the blog through features such as post reactions and comments.\n\nAlthough the focus is on the back end, we will also integrate the API into our VitePress blog. We will use Vue.js and [Pinia Colada](https:\u002F\u002Fpinia-colada.esm.dev\u002F) as our data-fetching framework. VitePress is a Vue.js application, so we can extend it with the components we need.\n\nThe examples are designed to be easy to follow. Unnecessary complexity and over-engineering are neither desirable nor necessary here. We will focus on simplicity, clarity, and efficiency.\n\nThroughout the series, we will build a Laravel API and integrate it with our VitePress blog. We will cover:\n\n- **Setting up the Laravel project**: Create a new Laravel project and become familiar with its structure.\n- **Improving the development workflow**: Configure [Pint](https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fpint), [Rector](https:\u002F\u002Fgithub.com\u002Frectorphp\u002Frector), [Larastan](https:\u002F\u002Fgithub.com\u002Flarastan\u002Flarastan), and [Pest](https:\u002F\u002Fpestphp.com\u002F) for formatting, refactoring, static analysis, and testing.\n- **Adding social authentication**: Let users sign in with GitHub through [Laravel Socialite](https:\u002F\u002Flaravel.com\u002Fdocs\u002F11.x\u002Fsocialite).\n- **Connecting the applications**: Configure Sanctum, CORS, CSRF protection, and the first requests between the VitePress frontend and the Laravel API.\n- **Managing authentication state**: Use [Pinia Colada](https:\u002F\u002Fpinia-colada.esm.dev\u002F) to retrieve the current user and log out with an optimistic update.\n- **Building the comment API**: Create the models, relationships, endpoints, validation, authorization, and tests for comments.\n- **Keeping the backend in sync**: Generate post metadata from VitePress and synchronize it with the Laravel database.\n- **Building the comment interface**: Fetch, create, edit, and delete comments from the VitePress frontend.\n\nBy the end of the series, you will have a blog backed by a Laravel API. Readers will be able to sign in with GitHub and leave comments, and the architecture will be ready for additional interactive features.\n\nTesting is part of the development process and will be included at each stage, so it does not need a dedicated article.\n\nIf you have questions, feedback, or suggestions, feel free to share them in the comments. Your input helps improve the series.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis series assumes prior knowledge of TypeScript, Vue.js, and Laravel. If you are unfamiliar with any of these technologies, review the [Create a Blog with VitePress and Vue.js from Scratch](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch) first.\n::\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":3410,"description":3566},{"loc":3569},"series\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api","Transform your VitePress blog into a dynamic platform with an API",[643,3576,3577],"vitepress","api","JLBtX9BKfN72BkhcYisEXraNGTvZSnT5YHM05A_uemk",[3580,3585,3586,3591,3596,3601,3606,3611],{"contentId":3581,"title":3582,"description":3583,"path":3584,"part":64,"github":3398,"topics":3398},"06469e25-715e-4a92-87b9-0db6db845a50","Setting Up Your Laravel Project Structure and Essentials","A comprehensive guide to setting up your Laravel project and understanding its structure for a better development experience.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsetting-up-your-laravel-project-structure-and-essentials",{"contentId":3394,"title":5,"description":3396,"path":3400,"part":71,"github":3398,"topics":3398},{"contentId":3587,"title":3588,"description":3589,"path":3590,"part":88,"github":3398,"topics":3398},"3729f419-a8b6-486c-a845-ab5ba1a33172","Effortless Social Authentication with Laravel Socialite","Add GitHub authentication to Laravel with Socialite, OAuth callbacks, database synchronization, secure sessions, and test-first development.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Feffortless-social-authentication-with-laravel-socialite",{"contentId":3592,"title":3593,"description":3594,"path":3595,"part":97,"github":3398,"topics":3398},"b07ec3b5-ca56-4d14-ae2f-8c0702218293","Building a Simple Comment System for User Engagement","Build a Laravel comment API with models, migrations, resources, policies, form requests, controllers, routes, and comprehensive tests.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fbuilding-a-simple-comment-system-for-user-engagement",{"contentId":3597,"title":3598,"description":3599,"path":3600,"part":110,"github":3398,"topics":3398},"53a607df-d10e-4423-966c-500d2885e6e0","Automating Your Backend to Stay in Sync Effortlessly","Generate frontend metadata with VitePress, synchronize posts with Laravel, and keep the backend database aligned automatically.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fautomating-your-backend-to-stay-in-sync-effortlessly",{"contentId":3602,"title":3603,"description":3604,"path":3605,"part":122,"github":3398,"topics":3398},"e6040e0a-4997-40d6-bde8-332cbca0f307","Bridging the Gap: Connecting Your Frontend and Backend","Connect a VitePress frontend to a Laravel API with Sanctum, CORS, CSRF protection, shared credentials, and a reusable API client.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fbridging-the-gap-connecting-your-frontend-and-backend",{"contentId":3607,"title":3608,"description":3609,"path":3610,"part":134,"github":3398,"topics":3398},"d507f8af-7c76-4660-859e-23af11c0728e","Streamlining User Authentication from Frontend to Backend","Connect frontend authentication to Laravel with a current-user query, GitHub logout flow, Pinia Colada caching, and optimistic state updates.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fstreamlining-user-authentication-from-frontend-to-backend",{"contentId":3612,"title":3613,"description":3614,"path":3615,"part":146,"github":3398,"topics":3398},"1b2a6cc0-c10f-421a-9344-60cb1583a136","Simplifying Comment Querying and Editing with Pinia Colada","Build the VitePress comment interface with Pinia Colada queries, mutations, optimistic updates, reusable Vue components, and permissions.","\u002Fseries\u002Fempower-and-dynamize-our-vitepress-blog-with-a-laravel-api\u002Fsimplifying-comment-querying-and-editing-with-pinia-colada",1795016693430]