Skip to content

Modernise code#156

Open
mrliptontea wants to merge 63 commits intomasterfrom
PLT-951-modernise-code
Open

Modernise code#156
mrliptontea wants to merge 63 commits intomasterfrom
PLT-951-modernise-code

Conversation

@mrliptontea
Copy link
Copy Markdown
Member

@mrliptontea mrliptontea commented Feb 27, 2026

  • Precursor to PLT-951
    • Modernise codebase with PHPStan, PHP CS Fixer, and Rector
    • Drop PHP 7.3
    • Use PHP 7.4 features
    • Strict types where possible
    • Resolve todo: use ObjectId->getTimestamp()
Used rector.php
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\Config\RectorConfig;
use Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector;
use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
use Rector\TypeDeclarationDocblocks\Rector\Class_\AddReturnDocblockDataProviderRector;
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDimFetchAccessRector;
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector;

return RectorConfig::configure()
    ->withPaths([
        __DIR__ . '/scripts',
        __DIR__ . '/src',
        __DIR__ . '/test',
    ])
    ->withBootstrapFiles([
        __DIR__ . '/src/tripod.inc.php',
    ])
    ->withPhpSets(php74: true)
    ->withPreparedSets(
        deadCode: true,
        codeQuality: true,
        codingStyle: true,
        typeDeclarations: true,
        typeDeclarationDocblocks: true,
        privatization: true,
        naming: true,
        instanceOf: true,
        earlyReturn: true,
        rectorPreset: true,
        phpunitCodeQuality: true,
    )
    ->withSkip([
        AddReturnDocblockDataProviderRector::class,
        CatchExceptionNameMatchingTypeRector::class,
        DisallowedEmptyRuleFixerRector::class,
        FinalizeTestCaseClassRector::class,
        MakeInheritedMethodVisibilitySameAsParentRector::class,
        ParamTypeByMethodCallTypeRector::class,
        PostIncDecToPreIncDecRector::class,
        RenameForeachValueVariableToMatchExprVariableRector::class,
        RenameParamToMatchTypeRector::class,
        RenamePropertyToMatchTypeRector::class,
        RenameVariableToMatchMethodCallReturnTypeRector::class,
        RenameVariableToMatchNewTypeRector::class,
        SimplifyEmptyCheckOnEmptyArrayRector::class,
        FlipTypeControlToUseExclusiveTypeRector::class,
        AddParamArrayDocblockFromDimFetchAccessRector::class,
        DocblockReturnArrayFromDirectArrayInstanceRector::class,
    ])
;

@mrliptontea mrliptontea force-pushed the PLT-951-modernise-code branch 9 times, most recently from a1fa945 to 6a0ca80 Compare March 5, 2026 23:25
@mrliptontea mrliptontea force-pushed the PLT-951-modernise-code branch 6 times, most recently from 862e276 to 5d0a630 Compare March 11, 2026 23:44
@mrliptontea mrliptontea force-pushed the PLT-951-modernise-code branch 8 times, most recently from ba3d8fe to 143e27b Compare March 18, 2026 11:20
@mrliptontea mrliptontea marked this pull request as ready for review March 18, 2026 11:30
@mrliptontea mrliptontea force-pushed the PLT-951-modernise-code branch from b76f569 to 2adc875 Compare March 19, 2026 13:25
$a[$rdf] = $parser->getSimpleIndex(0);
} elseif (
is_array($a[$rdf])
and isset($a[$rdf][0])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd long since forgotten and existed in PHP...!

* @param ObjectType $type
*/
private function get_subjects_where($p, $o, $type)
private function get_subjects_where(string $p, $o, string $type): array
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the docblock type it as a TriplePredicate but in the function it types it as a string ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types like TriplePredicate, ObjectValue are PHPStan type aliases, defined here:

* @phpstan-type ObjectResource string
* @phpstan-type ObjectLiteral string|int|float|bool
* @phpstan-type ObjectType 'bnode'|'uri'|'literal'
* @phpstan-type ObjectValue ObjectResource|ObjectLiteral
* @phpstan-type TripleSubject string
* @phpstan-type TriplePredicate string

(though language servers in PHPStorm, Intelephense in VSCode, etc. also interpret them and provide completions based on them)

I'm using TriplePredicate for consistency, even though it translates to just string. This helps make a better sense of what's inside the object, which is especially visible here:

* @phpstan-type TripleGraph array<TripleSubject, array<TriplePredicate, TripleObject[]>>

I think this enhances the reading experience as you can quickly find where predicates are referenced, such as here:

* @return TriplePredicate[] list of property URIs
*/
public function get_subject_properties(string $s, bool $distinct = true): array

So you know it's not just an array being returned, it's an array of predicates.

* @param 'literal'|'resource' $type
*/
private function add_to_sequence($s, $o, $type = 'resource')
private function add_to_sequence(string $s, $o, string $type = 'resource'): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above, but TripleSubject vs. string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

phpstan.neon Outdated
@@ -0,0 +1,17 @@
parameters:
level: 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woop woop

Copy link
Copy Markdown
Member

@astilla astilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well...it's massive... 🤣
Looks like some good automated updates.
I've left a couple of questions I wasn't sure about a difference in typing between docblock and function param definition.
Other than than it looks sane but being so big I've somewhat skimmed it.

@mrliptontea mrliptontea force-pushed the PLT-951-modernise-code branch from 8462d75 to e40d121 Compare March 31, 2026 10:46
@mrliptontea mrliptontea force-pushed the PLT-951-modernise-code branch from e40d121 to 29a2458 Compare March 31, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants