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

Refactoring into clean architecture #4

Merged
merged 3 commits into from
May 12, 2024
Merged

Conversation

DeGraciaMathieu
Copy link
Owner

@DeGraciaMathieu DeGraciaMathieu commented May 12, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new interfaces and classes for handling file inspection and word analysis.
    • Added functionality for word aggregation and error handling in output processes.
  • Enhancements

    • Improved file retrieval and word analysis capabilities through new service adapters.
    • Enhanced command handling for inspecting and analyzing files.
  • Refactor

    • Updated namespaces and reorganized code structure for better clarity and maintenance.
  • Documentation

    • Added detailed comments and structured documentation for new classes and methods.
  • Tests

    • Implemented new unit tests to ensure the reliability of file and word processing functionalities.
  • Chores

    • Updated composer.json and configurations to support new dependencies and command paths.

Copy link

coderabbitai bot commented May 12, 2024

Warning

Rate Limit Exceeded

@DeGraciaMathieu has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 31 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 8c000c2 and e51b2d5.

Walkthrough

The project underwent a significant restructuring and enhancement, focusing on improving file and word handling through new and updated classes across application, domain, and infrastructure layers. Key additions include interfaces for input and output handling, service adapters for file and analysis operations, and a variety of utility classes for managing entities and value objects. This comprehensive update aims to streamline processes and expand functionality within the codebase.

Changes

File Path Change Summary
.../UseCases/InspectHandler.php Enhanced with new constructor parameters and modified methods.
.../UseCases/InspectInput.php
.../UseCases/InspectOutput.php
New files introducing interfaces for input and output handling.
.../Domain/Aggregators/*.php
.../Domain/Entities/*.php
Added classes for handling file and word entities.
.../Domain/Ports/*.php
.../Domain/ValueObjects/Path.php
Introduced interfaces and a value object for path handling.
.../Infrastructure/Analyze/Adapters/*.php
.../Infrastructure/File/Adapters/*.php
Implemented adapters conforming to newly defined interfaces.
.../Infrastructure/Analyze/Mappers/*.php
.../Infrastructure/Analyze/Nodes/*.php
Adjustments to namespaces and added new mapping functionalities.
.../Presenter/Commands/*.php Command layer enhancements to utilize new use case handling.
app/Providers/AppServiceProvider.php
composer.json
Dependency injections and new package additions.
config/commands.php
tests/Builders/*.php
tests/Unit/*.php
Configuration adjustments and expanded testing capabilities.

🐇🌟
In the burrow of code, under the moon's glow,
A rabbit worked hard, with new lines in tow.
Files and words, in harmony dance,
A symphony of code, given a chance.
Hop and skip, the changes deploy,
In the digital field, a rabbit's joy.
🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Out of diff range and nitpick comments (1)
tests/Builders/FileAggregatorBuilder.php (1)

29-36: Method correctly creates a FileEntity from stub data. Ensure this method is used only in testing contexts due to hardcoded paths.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b85224c and 570e58a.
Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
Files selected for processing (31)
  • app/Application/UseCases/InspectHandler.php (1 hunks)
  • app/Application/UseCases/InspectInput.php (1 hunks)
  • app/Application/UseCases/InspectOutput.php (1 hunks)
  • app/Domain/Aggregators/FileAggregator.php (1 hunks)
  • app/Domain/Aggregators/WordAggregator.php (1 hunks)
  • app/Domain/Entities/FileEntity.php (1 hunks)
  • app/Domain/Entities/WordEntity.php (1 hunks)
  • app/Domain/Ports/AnalyzeService.php (1 hunks)
  • app/Domain/Ports/FileService.php (1 hunks)
  • app/Domain/ValueObjects/Path.php (1 hunks)
  • app/Infrastructure/Analyze/Adapters/AnalyzeServiceAdapter.php (1 hunks)
  • app/Infrastructure/Analyze/Mappers/PhpParserWordMapper.php (1 hunks)
  • app/Infrastructure/Analyze/Nodes/NodeExtractor.php (1 hunks)
  • app/Infrastructure/Analyze/Nodes/NodeValidator.php (1 hunks)
  • app/Infrastructure/Analyze/Visitors/ClassVisitor.php (2 hunks)
  • app/Infrastructure/File/Adapters/FileServiceAdapter.php (1 hunks)
  • app/Infrastructure/File/Mappers/FileFinderMapper.php (1 hunks)
  • app/Presenter/Commands/InspectCommand.php (1 hunks)
  • app/Presenter/Commands/InspectCommandInput.php (1 hunks)
  • app/Presenter/Commands/InspectCommandOutput.php (1 hunks)
  • app/Providers/AppServiceProvider.php (2 hunks)
  • composer.json (2 hunks)
  • config/commands.php (1 hunks)
  • tests/Builders/FileAggregatorBuilder.php (1 hunks)
  • tests/Builders/builders.php (1 hunks)
  • tests/Builders/stubs/Foo.php (1 hunks)
  • tests/Unit/Application/InspectTestCase.php (1 hunks)
  • tests/Unit/Domain/Aggregators/WordAggregatorTest.php (1 hunks)
  • tests/Unit/Domain/Entities/WordEntityTest.php (1 hunks)
  • tests/Unit/Infrastructure/Nodes/NodeExtractorTest.php (1 hunks)
  • tests/Unit/Infrastructure/Nodes/NodeValidatorTest.php (1 hunks)
Files skipped from review due to trivial changes (9)
  • app/Application/UseCases/InspectInput.php
  • app/Domain/Aggregators/FileAggregator.php
  • app/Domain/Aggregators/WordAggregator.php
  • app/Domain/Entities/FileEntity.php
  • app/Domain/Entities/WordEntity.php
  • app/Domain/Ports/FileService.php
  • app/Infrastructure/Analyze/Nodes/NodeExtractor.php
  • config/commands.php
  • tests/Unit/Domain/Aggregators/WordAggregatorTest.php
Additional comments not posted (42)
tests/Builders/builders.php (1)

5-7: Function fileAggregator implementation looks good.

This function correctly creates and returns an instance of FileAggregatorBuilder.

app/Infrastructure/Analyze/Nodes/NodeValidator.php (1)

Line range hint 7-13: Static methods for node type checking are correctly implemented.

The methods isAVariable and isAMethod use appropriate instanceof checks and are well-implemented for their intended purpose.

app/Domain/Ports/AnalyzeService.php (1)

10-15: Method getWords is well-documented and appropriately designed.

The documentation clearly describes the method's functionality and its parameters. The use of FileAggregator and WordAggregator is appropriate and aligns with the method's purpose.

app/Presenter/Commands/InspectCommandInput.php (1)

8-23: Class InspectCommandInput is well-implemented and follows good practices.

The class correctly implements the InspectInput interface, uses type safety with the Path class, and properly encapsulates its properties.

app/Infrastructure/Analyze/Mappers/PhpParserWordMapper.php (1)

8-27: Class PhpParserWordMapper is correctly implemented and effectively uses WordAggregator.

The methods map and aggregate are well-implemented, effectively adding words to and retrieving words from the WordAggregator.

app/Infrastructure/File/Adapters/FileServiceAdapter.php (1)

13-15: Constructor correctly initializes dependencies.

app/Infrastructure/Analyze/Visitors/ClassVisitor.php (2)

7-7: Constructor correctly initializes control flag for node parsing.


24-24: Method correctly processes nodes and accumulates words.

tests/Builders/FileAggregatorBuilder.php (3)

12-15: Constructor correctly initializes a new FileAggregator.


17-22: Method correctly adds a file entity and supports method chaining.


24-27: Method correctly builds and returns the FileAggregator.

app/Infrastructure/File/Mappers/FileFinderMapper.php (2)

11-14: Constructor correctly initializes a FileAggregator for accumulating file entities.


16-26: Method correctly maps files to FileAggregator using a clear and efficient loop structure.

app/Providers/AppServiceProvider.php (1)

35-36: Service bindings are correctly configured for FileService and AnalyzeService.

tests/Unit/Domain/Entities/WordEntityTest.php (3)

12-18: Test correctly asserts that words are transformed to lowercase.


20-26: Test correctly asserts that common words are not ignored.


29-43: Test correctly uses a data provider to assert that specific words can be ignored.

app/Application/UseCases/InspectHandler.php (2)

13-17: Constructor correctly initializes services needed for the inspection process.


19-42: Method correctly orchestrates the inspection process and handles exceptions appropriately.

app/Presenter/Commands/InspectCommand.php (1)

31-42: Method correctly sets up and executes the inspection command.

tests/Unit/Infrastructure/Nodes/NodeValidatorTest.php (4)

9-9: Namespace update aligns with the new architecture.


Line range hint 13-21: Test method correctly checks if a node is a variable.


Line range hint 23-31: Test method correctly checks if a node is a method.


Line range hint 33-41: Test method effectively handles unexpected node types, enhancing robustness.

app/Presenter/Commands/InspectCommandOutput.php (5)

15-21: Constructor correctly initializes dependencies for rendering views and HTML.


23-26: Method effectively uses helper function to display greeting message.


28-35: Method efficiently handles presentation logic by separating concerns of data manipulation and rendering.


37-40: Error handling method correctly utilizes helper function to display errors.


42-52: Private methods for HTML handling are well encapsulated and utilize appropriate components.

composer.json (2)

22-22: Updated dependencies reflect the new requirements for the project.


39-41: Addition of development-specific file to autoload configuration enhances development experience.

tests/Unit/Infrastructure/Nodes/NodeExtractorTest.php (4)

8-8: Namespace update aligns with the new architecture.


Line range hint 10-26: Test method effectively uses data providers to test variable name splitting functionality.


Line range hint 28-44: Test method correctly checks if a method name can be split into words.


Line range hint 46-62: Test method effectively handles complex cases of nested variable names.

app/Infrastructure/Analyze/Adapters/AnalyzeServiceAdapter.php (4)

14-19: Constructor correctly initializes dependencies for parsing and mapping words.


21-30: Method efficiently handles word aggregation by separating concerns of file handling and aggregation logic.


32-41: Method effectively uses visitor pattern to process files and extract words.


43-59: Private methods for handling visitors are well encapsulated and utilize appropriate components.

tests/Unit/Application/InspectTestCase.php (3)

17-30: Setup method correctly initializes mocks and dependencies for testing.


32-40: Test method effectively simulates and tests the inspection use case for counting words.


42-87: Private helper methods are well-structured and contribute to a clear and maintainable test setup.

tests/Builders/stubs/Foo.php Show resolved Hide resolved
app/Application/UseCases/InspectOutput.php Show resolved Hide resolved
app/Domain/ValueObjects/Path.php Show resolved Hide resolved
Comment on lines +17 to +28
public function all(Path $path): FileAggregator
{
$finder = new FileFinder(
basePath: getcwd(),
);

$files = $finder->getFiles(
$path->value(),
);

return $this->mapper->map($files);
}
Copy link

@coderabbitai coderabbitai bot May 12, 2024

Choose a reason for hiding this comment

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

Method correctly retrieves and maps files. Consider making the base path configurable for greater flexibility.

public function all(Path $path, string $basePath = null): FileAggregator
{
    $basePath = $basePath ?? getcwd();
    $finder = new FileFinder(basePath: $basePath);
    $files = $finder->getFiles($path->value());
    return $this->mapper->map($files);
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

YAGNI

Copy link

Choose a reason for hiding this comment

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

@DeGraciaMathieu, I understand and respect the "YAGNI" principle you're applying. Keeping the code simple until a need is clearly identified is a sound strategy, especially in projects where requirements are evolving.

The suggestion to make the base path configurable was aimed at enhancing flexibility, particularly for different deployment environments or testing scenarios. However, if the current setup meets the project's needs without this flexibility, it makes sense to keep things straightforward as you suggested.

Should the need for this feature arise in the future, it can be revisited. Thank you for your input, and please let me know if there's anything else I can assist with!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between b85224c and 8c000c2.
Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
Files selected for processing (31)
  • app/Application/UseCases/InspectHandler.php (1 hunks)
  • app/Application/UseCases/InspectInput.php (1 hunks)
  • app/Application/UseCases/InspectOutput.php (1 hunks)
  • app/Domain/Aggregators/FileAggregator.php (1 hunks)
  • app/Domain/Aggregators/WordAggregator.php (1 hunks)
  • app/Domain/Entities/FileEntity.php (1 hunks)
  • app/Domain/Entities/WordEntity.php (1 hunks)
  • app/Domain/Ports/AnalyzeService.php (1 hunks)
  • app/Domain/Ports/FileService.php (1 hunks)
  • app/Domain/ValueObjects/Path.php (1 hunks)
  • app/Infrastructure/Analyze/Adapters/AnalyzeServiceAdapter.php (1 hunks)
  • app/Infrastructure/Analyze/Mappers/PhpParserWordMapper.php (1 hunks)
  • app/Infrastructure/Analyze/Nodes/NodeExtractor.php (1 hunks)
  • app/Infrastructure/Analyze/Nodes/NodeValidator.php (1 hunks)
  • app/Infrastructure/Analyze/Visitors/ClassVisitor.php (2 hunks)
  • app/Infrastructure/File/Adapters/FileServiceAdapter.php (1 hunks)
  • app/Infrastructure/File/Mappers/FileFinderMapper.php (1 hunks)
  • app/Presenter/Commands/InspectCommand.php (1 hunks)
  • app/Presenter/Commands/InspectCommandInput.php (1 hunks)
  • app/Presenter/Commands/InspectCommandOutput.php (1 hunks)
  • app/Providers/AppServiceProvider.php (2 hunks)
  • composer.json (2 hunks)
  • config/commands.php (1 hunks)
  • tests/Builders/FileAggregatorBuilder.php (1 hunks)
  • tests/Builders/builders.php (1 hunks)
  • tests/Builders/stubs/Foo.php (1 hunks)
  • tests/Unit/Application/InspectTestCase.php (1 hunks)
  • tests/Unit/Domain/Aggregators/WordAggregatorTest.php (1 hunks)
  • tests/Unit/Domain/Entities/WordEntityTest.php (1 hunks)
  • tests/Unit/Infrastructure/Nodes/NodeExtractorTest.php (1 hunks)
  • tests/Unit/Infrastructure/Nodes/NodeValidatorTest.php (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/Builders/builders.php
Files skipped from review as they are similar to previous changes (30)
  • app/Application/UseCases/InspectHandler.php
  • app/Application/UseCases/InspectInput.php
  • app/Application/UseCases/InspectOutput.php
  • app/Domain/Aggregators/FileAggregator.php
  • app/Domain/Aggregators/WordAggregator.php
  • app/Domain/Entities/FileEntity.php
  • app/Domain/Entities/WordEntity.php
  • app/Domain/Ports/AnalyzeService.php
  • app/Domain/Ports/FileService.php
  • app/Domain/ValueObjects/Path.php
  • app/Infrastructure/Analyze/Adapters/AnalyzeServiceAdapter.php
  • app/Infrastructure/Analyze/Mappers/PhpParserWordMapper.php
  • app/Infrastructure/Analyze/Nodes/NodeExtractor.php
  • app/Infrastructure/Analyze/Nodes/NodeValidator.php
  • app/Infrastructure/Analyze/Visitors/ClassVisitor.php
  • app/Infrastructure/File/Adapters/FileServiceAdapter.php
  • app/Infrastructure/File/Mappers/FileFinderMapper.php
  • app/Presenter/Commands/InspectCommand.php
  • app/Presenter/Commands/InspectCommandInput.php
  • app/Presenter/Commands/InspectCommandOutput.php
  • app/Providers/AppServiceProvider.php
  • composer.json
  • config/commands.php
  • tests/Builders/FileAggregatorBuilder.php
  • tests/Builders/stubs/Foo.php
  • tests/Unit/Application/InspectTestCase.php
  • tests/Unit/Domain/Aggregators/WordAggregatorTest.php
  • tests/Unit/Domain/Entities/WordEntityTest.php
  • tests/Unit/Infrastructure/Nodes/NodeExtractorTest.php
  • tests/Unit/Infrastructure/Nodes/NodeValidatorTest.php

Copy link

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@DeGraciaMathieu DeGraciaMathieu merged commit 5cd9b62 into master May 12, 2024
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.

1 participant