Skip to content

PHPStan: Fix/phpstan styling#236

Merged
dantleech merged 9 commits intophp-tui:mainfrom
GianfriAur:fix/phpstan-styling
May 4, 2026
Merged

PHPStan: Fix/phpstan styling#236
dantleech merged 9 commits intophp-tui:mainfrom
GianfriAur:fix/phpstan-styling

Conversation

@GianfriAur
Copy link
Copy Markdown
Contributor

Context

The phpstan-baseline.neon file had accumulated 142 ignored errors across the codebase, this branch resolves every entry so that PHPStan runs cleanly with no exceptions,
going forward.

While in there, the branch also applies a one-shot Rector pass and a PHP-CS-Fixer pass to bring the touched files (and a handful of adjacent ones) up to the project's current coding standards.

What changed

  • PHPStan baseline cleared: tightened generic types and array shapes in src/, lib/, example/demo/, and tests/. Notable areas: Display\Buffer, Display\Cell, Display\Display, Color\RgbColor, Text\SpanParser, Extension\Core\Widget\ParagraphRenderer, BarChartRenderer, GaugeRenderer,
    BdfFont/BdfParser, Docgen, HalfBlockGrid, PhpTermBackend.
  • Rector refactorings: simpler array/list handling, removal of redundant array_values() calls on lists, and other small mechanical cleanups across BdfFont, Docgen, Buffer, TableRow, Text, plus the benchmark and unit test suites.

Test plan

  • no php-cs-fixer errore
  • no phpunit errors
  • no changes from composer rector

Note for the maintainer

Making php bumb, from 8.1 to 8.2 on composer.json

@GianfriAur GianfriAur force-pushed the fix/phpstan-styling branch from 0e5ca61 to 55fd3ee Compare April 27, 2026 08:23
Comment thread example/demo/src/App.php Outdated
private Display $display,
private ActivePage $activePage,
private array $pages,
private array $pages,
Copy link
Copy Markdown
Collaborator

@dantleech dantleech Apr 29, 2026

Choose a reason for hiding this comment

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

I assume that this wasn't CS fixer? I'd prefer not to have whitespace alignment...

Comment thread src/Text/LineComposer/LineTruncator.php Outdated
private readonly array $lines,
private readonly int $maxLineWidth,
private int $horizontalOffset = 0,
private readonly int $horizontalOffset = 0,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could simply make the class read only at this point

@dantleech
Copy link
Copy Markdown
Collaborator

thanks, looks good. I'm confused about the whitepace parameter alignment though.

@GianfriAur
Copy link
Copy Markdown
Contributor Author

@dantleech

would you consider using a custom Cs Fixer role for whitespace alignment in the costrustors? something like that

// src/CsFixer/NoAlignedPropertiesFixer.php
<?php

namespace App\CsFixer;

use PhpCsFixer\AbstractFixer;
use PhpCsFixer\FixerDefinition\CodeSample;
use PhpCsFixer\FixerDefinition\FixerDefinition;
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
use PhpCsFixer\Tokenizer\Tokens;

final class NoAlignedPropertiesFixer extends AbstractFixer
{
    public function getName(): string
    {
        return 'App/no_aligned_properties';
    }

    public function getDefinition(): FixerDefinitionInterface
    {
        return new FixerDefinition(
            'Removes whitespace alignment between type and variable name.',
            [
                new CodeSample("<?php\nfunction __construct(\n    private Terminal   \$terminal,\n    private Display    \$display,\n) {}\n"),
            ]
        );
    }

    public function isCandidate(Tokens $tokens): bool
    {
        return true;
    }

    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
    {
        foreach ($tokens as $index => $token) {
            if (!$token->isGivenKind(T_VARIABLE)) {
                continue;
            }

            $prevIndex = $tokens->getPrevNonWhitespace($index);
            if ($prevIndex === null) {
                continue;
            }

            $prevToken = $tokens[$prevIndex];

            if (!$prevToken->isGivenKind([T_STRING, T_ARRAY, T_CALLABLE, T_NULL, T_NS_SEPARATOR])) {
                continue;
            }

            $whitespaceIndex = $prevIndex + 1;
            if ($whitespaceIndex === $index) {
                continue;
            }

            $whitespaceToken = $tokens[$whitespaceIndex];
            if (!$whitespaceToken->isWhitespace()) {
                continue;
            }

            $content = $whitespaceToken->getContent();
            if (!str_contains($content, "\n") && strlen($content) > 1) {
                $tokens[$whitespaceIndex] = new \PhpCsFixer\Tokenizer\Token([T_WHITESPACE, ' ']);
            }
        }
    }
}

@dantleech
Copy link
Copy Markdown
Collaborator

would you consider using a custom Cs Fixer

off there were an existing fixer then why not, but i don't think it's worth adding a custom rule

@dantleech
Copy link
Copy Markdown
Collaborator

Probably 8.1 needs removing from the matrix?

@GianfriAur
Copy link
Copy Markdown
Contributor Author

Hi @dantleech

I just removed 8.1 from CI

@dantleech dantleech merged commit 51b9477 into php-tui:main May 4, 2026
5 checks passed
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.

2 participants