Page MenuHomePhorge

Replace dirname(__FILE__) with __DIR__ (available since PHP 5.3)
AbandonedPublic

Authored by valerio.bozzolan on Mar 11 2023, 21:33.

Details

Summary

This replacement is totally safe since this works after PHP 5.3 (note the current minimum is PHP 5.5).

The goal is to avoid workarounds that only made sense in very old versions of PHP.
This also improves readability in my personal opinion.

Here the changelog for PHP 5.3 mentioning __DIR__:

https://www.php.net/ChangeLog-5.php#5.3.0

Here a source indicating that this change is totally safe:

https://stackoverflow.com/q/2749416

Here another source indicating that this is safe:

https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#dirnamefileconstanttodirconstantrector

About that, this is automagic change was executed by Rector.php.

Thank you Rector.php for making this repository even more performant,
recent and readable. I also donated 15€ to Rector.php since I was really
impressed by its potential.

God bless Rector.php. I love you Rector.php. Thank you Rector.php. Such wow.

Ref T15158

Test Plan
  • I checked every single line with my big eyes
  • matrioska test: I hot-used my Arcanist to run arc diff and it worked

Diff Detail

Repository
rARC Arcanist
Branch
T15158-modernize-dirname
Lint
Lint Passed
Unit
Test Failures
Build Status
Buildable 129
Build 129: arc lint + arc unit

Unit TestsFailed

TimeTest
4,914 msArcanistCoffeeLintLinterTestCase::testLinter
Lint emitted an unexpected set of messages for file "no_trailing_whitespace.lint-test". MISSING MESSAGES Message with severity "error" at "1:0"
101 msArcanistCppcheckLinterTestCase::testLinter
Lint emitted an unexpected set of messages for file "zblair.lint-test". MISSING MESSAGES Message with severity "error" at "10:<null>"
254 msArcanistCpplintLinterTestCase::testLinter
Assertion failed, expected values to be equal (at ArcanistLinterTestCase.php:180): Some linters failed: - CommandException: Command failed with error #1! COMMAND
2,544 msArcanistJSHintLinterTestCase::testLinter
Lint emitted an unexpected set of messages for file "too-many-errors.lint-test". MISSING MESSAGES Message with severity "disabled" at "2:22" (E043)
1,127 msArcanistJscsLinterTestCase::testLinter
Lint emitted an unexpected set of messages for file "curly-brace.lint-test". MISSING MESSAGES Message with severity "error" at "2:3"
View Full Test Results (7 Failed · 256 Passed · 17 Skipped)

Event Timeline

NOTE: I spent 4 hours to fight with the lints, to then realize with maximum certitude that the linters are simply broken, on outdated pieces of software, blessed by dead Gods, and their errors have nothing to do with my life on this planet.
valerio.bozzolan retitled this revision from Replace dirname(__FILE__) with __DIR__ (available since PHP 5.5 - yeah!) to Replace dirname(__FILE__) with __DIR__ (available since PHP 5.3- yeah!).

try to fix lint again - but I don't hope for it

valerio.bozzolan retitled this revision from Replace dirname(__FILE__) with __DIR__ (available since PHP 5.3- yeah!) to Replace dirname(__FILE__) with __DIR__ (available since PHP 5.3).Mar 11 2023, 21:48
valerio.bozzolan edited the summary of this revision. (Show Details)
valerio.bozzolan awarded a token.

I understand that nobody in the world likes refactoring. Even if it makes stuff more readable and a CPU cycle faster.

Feel free to propose to reopen only if you are O1 and you have 15 minutes to look every single line in this file with your big eyes ihih