Page MenuHomePhorge

Modernize codebase to features available since PHP 5.5
AbandonedPublic

Authored by valerio.bozzolan on Mar 6 2023, 07:48.

Details

Summary

This refactor includes these scaring changes:

  • avoid id( new A() )->b() and adopt ( new A() )->b() - since PHP 5.4
  • avoid id( $a->b() )->c() and adopt just $a->b()->c() - since PHP 5.4
  • avoid dirname(__FILE__) and adopt __DIR__ - since PHP 5.3
  • avoid $foo ? $foo : $default and adopt $foo ?: $default - since PHP 5.3

To better understand and comment these old PHP features, see:

https://we.phorge.it/T15158

Note that all directories like /__tests__/ were skipped.

Ref T15158
Ref P6

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
arcpatch-D25071
Lint
Lint Errors
SeverityLocationCodeMessage
Errorsrc/repository/api/ArcanistRepositoryAPI.php:782XHP1PHP Syntax Error!
Unit
Test Failures
Build Status
Buildable 125
Build 125: arc lint + arc unit

Unit TestsFailed

TimeTest
2,421 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)
278 msArcanistPhpcsLinterTestCase::testLinter
Lint emitted an unexpected set of messages for file "basics.lint-test". MISSING MESSAGES Message with severity "error" at "2:1"
1,339 msPhutilLibraryTestCase::testLibraryMap
EXCEPTION (XHPASTSyntaxErrorException): repository/api/ArcanistRepositoryAPI.php: XHPAST Parse Error: syntax error, unexpected T_OBJECT_OPERATOR on line 782 #0 /var/www/arcanist/src/moduleutils/PhutilLibraryMapBuilder.php(63): PhutilLibraryMapBuilder->analyzeLibrary() #1 /var/www/arcanist/src/__tests__/PhutilLibraryTestCase.php(29): PhutilLibraryMapBuilder->buildMap()
43 msAbstractDirectedGraphTestCase::testCyclicGraph
1 assertion(s) passed.
43 msAbstractDirectedGraphTestCase::testEdgeLoadFailure
1 assertion(s) passed.
View Full Test Results (3 Failed · 311 Passed · 28 Skipped)

Event Timeline

avoid to replace CLASS to self::class since it's probably nonsense

https://stackoverflow.com/q/75648554/3451846

valerio.bozzolan edited the summary of this revision. (Show Details)

skip the replacement of __CLASS__ to self::class since it can be just confusing

I have an ironical situation. This syntax is very supported:

# this is supported since PHP 5.0
$a->b()->c()

But:

# I'm trying to deprecate this
id( $a->b() )->c()
# but this is supported only in PHP 7.0
( $a->b() )->c()

# so to deprecate id() - we have to strip unuseful parenthesis to obtain this that is supported in PHP 5.0:
$a->b()->c()

simplify ( $a->b() )->$b() to just $a->b()->c() since the first it's only supported in PHP 7.0

Yes, $a->b()->c() just work since PHP 5.0 without using tricks like id( $a->b() )->c().

I would like to fix this lint:

Lint emitted an unexpected set of messages for file "basics.lint-test".
MISSING MESSAGES
    Message with severity "error" at "2:1"

SURPLUS MESSAGES
(No messages.)

But - believe me or not but - I truly does not understand what it would want.

I understand that this is... too much.

I will split this Diff in one that is only about with the modification about dirname() and nothing else, so it will be easy-peasy to review. And it will still be a step forward.