Skip to content

Conversation

@absumo
Copy link
Contributor

@absumo absumo commented Aug 8, 2025

Summary by Sourcery

Migrate existing Twig extensions to use native Twig attribute annotations, eliminate the PaginatorRuntime and legacy AbstractExtension/API, and update service configuration to register attribute-based extensions.

Enhancements:

  • Convert PaginatorExtension, FrameworkExtension, and ContentExtension to use Twig\Attribute annotations for functions and filters instead of extending AbstractExtension.
  • Inject RequestStack into extensions and move pagination rendering into PaginatorExtension with Environment support.
  • Remove the separate PaginatorRuntime class and render pagination directly in the extension.

Chores:

  • Update service definitions to tag attribute-based Twig extensions with twig.attribute_extension and remove obsolete PaginatorRuntime service.

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 8, 2025

Reviewer's Guide

Refactors all Twig extensions to leverage native Twig attributes on readonly classes, consolidates pagination logic into a single attribute-based method, removes the deprecated runtime, and updates service tags to use twig.attribute_extension.

Class diagram for refactored Twig extensions

classDiagram
    class ContentExtension {
        <<readonly>>
        +__construct(publicFolder: string)
        +getContent(path: string): string
        <<AsTwigFunction('content', isSafe: ['html'])>>
    }
    class FrameworkExtension {
        <<readonly>>
        +__construct(requestStack: RequestStack)
        +ucfirst(string): string <<static>><<AsTwigFilter('ucfirst')>>
        +determineTheme(): string <<AsTwigFunction('theme')>>
        +sidebarIsOpen(): bool <<AsTwigFunction('sidebarIsOpen')>>
    }
    class PaginatorExtension {
        <<readonly>>
        +__construct(requestStack: RequestStack)
        +renderPagination(env: Environment, paginator: Paginator): string <<AsTwigFunction('pagination', needsEnvironment: true, isSafe: ['html'])>>
        -getRequest(): ?Request
    }
    class RequestStack
    class Environment
    class Paginator
    class Request

    ContentExtension --> RequestStack : uses
    FrameworkExtension --> RequestStack : uses
    PaginatorExtension --> RequestStack : uses
    PaginatorExtension --> Environment : uses
    PaginatorExtension --> Paginator : uses
    PaginatorExtension --> Request : uses
Loading

Class diagram for removed PaginatorRuntime

classDiagram
    class PaginatorRuntime {
        -renderPagination(env: Environment, paginator: Paginator): string
    }
    %% Note: PaginatorRuntime class has been removed in this PR.
Loading

File-Level Changes

Change Details Files
Convert Twig extensions to attribute-based definitions on readonly classes
  • Removed AbstractExtension inheritance and getFunctions/getFilters boilerplate
  • Annotated extension methods with AsTwigFunction and AsTwigFilter
  • Marked each extension class as readonly
src/Twig/PaginatorExtension.php
src/Twig/FrameworkExtension.php
src/Twig/ContentExtension.php
Inline and enhance pagination rendering, remove PaginatorRuntime
  • Injected RequestStack into PaginatorExtension constructor
  • Replaced external PaginatorRuntime with renderPagination method using Environment
  • Added sub-request guard, route lookup, and route parameter merging
  • Deleted PaginatorRuntime class
src/Twig/PaginatorExtension.php
src/Twig/PaginatorRuntime.php
Update service configuration for attribute-based Twig extensions
  • Removed twig.extension and twig.runtime tags
  • Tagged extensions with twig.attribute_extension
  • Dropped PaginatorRuntime service definition
config/services.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @absumo - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/Twig/ContentExtension.php:19` </location>
<code_context>
+    #[AsTwigFunction('content', isSafe: ['html'])]
     public function getContent(string $path): string
     {
         return file_get_contents($this->publicFolder . $path);
</code_context>

<issue_to_address>
No error handling for missing or unreadable files.

Handle cases where file_get_contents returns false to prevent warnings and ensure consistent output.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@absumo absumo changed the base branch from 373-invokable-commands to master August 11, 2025 11:17
@absumo absumo merged commit 4d93b7b into master Aug 11, 2025
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