Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and normalize class description comments #1502

Merged
merged 6 commits into from
Dec 14, 2023

Conversation

caendesilva
Copy link
Member

@caendesilva caendesilva commented Dec 14, 2023

Made this crude script to help, posting here in case of me wanting it in the future again.

<?php

// Create a list of all class descriptions (the first line in a PHPDoc) in the Framework package.

require_once __DIR__.'/../vendor/autoload.php';

$files = (new \Illuminate\Filesystem\Filesystem())->allFiles(__DIR__.'/../packages/framework/src');

$html = '';


foreach ($files as $file) {
    $source = file_get_contents($file->getPathname());
    // If file is not a class, skip it.
    if (!str_contains($source, 'class ')) {
        continue;
    }

    $reflection = new ReflectionClass('Hyde\\'.str_replace('/', '\\', substr($file->getPathname(), strlen(__DIR__.'/../packages/framework/src/'), -4)));

    $doc = $reflection->getDocComment();
    if (empty($doc)) {
        $commentText = '<span style="color: red">Missing PHPDoc</span>';
    } else {
        $commentText = trim(str_replace(['*', '/', '@experimental', '@internal', '@property', '@mixin', '@see'], '', getFirstLine($doc) ?: $doc)) ?: '<span style="color: red">Empty PHPDoc</span>';
    }

    $html .= sprintf('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>'."\n", $file->getPathname(), $reflection->getName(), $commentText);
}

$html = "<table><tbody>{$html}</tbody></table>";
file_put_contents(__DIR__.'/framework-classes.html', $html);
echo $html;

function getFirstLine(string $doc): string
{
    $lines = explode("\n", $doc);
    return $lines[1] ?? '';
}

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5029740) 100.00% compared to head (724fc2b) 100.00%.

Additional details and impacted files
@@              Coverage Diff              @@
##              master     #1502     +/-   ##
=============================================
  Coverage     100.00%   100.00%             
- Complexity      1740      3480   +1740     
=============================================
  Files            180       360    +180     
  Lines           4715      9430   +4715     
=============================================
+ Hits            4715      9430   +4715     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@caendesilva caendesilva force-pushed the normalize-code-comments branch from 1679e1c to fcb102b Compare December 14, 2023 10:15
@caendesilva caendesilva changed the title Clean up and normalize code comments Clean up and normalize class description comments Dec 14, 2023
@caendesilva caendesilva marked this pull request as ready for review December 14, 2023 10:44
@caendesilva caendesilva merged commit 56f3bf8 into master Dec 14, 2023
19 checks passed
@caendesilva caendesilva deleted the normalize-code-comments branch December 14, 2023 10:47
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.

1 participant