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

Add attributes support & improve MatchingResult #196

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

rustamwin
Copy link
Member

@rustamwin rustamwin commented Mar 28, 2023

Q A
Is bugfix? ✔️/❌
New feature? ✔️
Breaks BC? ✔️
Fixed issues comma-separated list of tickets # fixed by the PR, if any

ℹ️ yiisoft/demo#589

@what-the-diff
Copy link

what-the-diff bot commented Mar 28, 2023

PR Summary

  • 🚀 Optimized Middleware Handling
    Improved the way middlewares are managed in the Group class to avoid building them multiple times when they don't change, boosting efficiency.
  • 🧹 Code Clean-up
    Removed unused classes and fixed some typos for better readability and maintenance.
  • 🛠️ Refactoring
    Refactored various methods, attributes, and typehints for improved consistency, readability, and functionality.
  • Improved Testing
    Enhanced the tests for the Group and RouteCollection classes, and fixed the bug in the RouteCollectionTest.
  • 💡 Convenience Enhancements
    Added the withMiddlewares method to the DispatcherInterface for easier usage in certain cases.

@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (04be2f6) 78.66% compared to head (5be62b4) 83.72%.

❗ Current head 5be62b4 differs from pull request most recent head 63467dc. Consider uploading reports for the commit 63467dc to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #196      +/-   ##
============================================
+ Coverage     78.66%   83.72%   +5.05%     
- Complexity      188      228      +40     
============================================
  Files            13       23      +10     
  Lines           586      762     +176     
============================================
+ Hits            461      638     +177     
+ Misses          125      124       -1     
Files Coverage Δ
src/Attribute/Delete.php 100.00% <100.00%> (ø)
src/Attribute/Get.php 100.00% <100.00%> (ø)
src/Attribute/Head.php 100.00% <100.00%> (ø)
src/Attribute/Options.php 100.00% <100.00%> (ø)
src/Attribute/Patch.php 100.00% <100.00%> (ø)
src/Attribute/Post.php 100.00% <100.00%> (ø)
src/Attribute/Put.php 100.00% <100.00%> (ø)
src/Attribute/Route.php 100.00% <100.00%> (ø)
src/Group.php 100.00% <100.00%> (ø)
src/MatchingResult.php 100.00% <ø> (ø)
... and 6 more

... and 1 file with indirect coverage changes

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

@rustamwin rustamwin changed the title Add attributes support Add attributes support & improve MatchingResult Mar 28, 2023
src/MatchingResult.php Outdated Show resolved Hide resolved
@samdark samdark mentioned this pull request Apr 2, 2023
@rustamwin rustamwin added status:code review The pull request needs review. and removed status:under development Someone is working on a pull request. labels Jun 15, 2023
@rustamwin rustamwin requested a review from a team June 15, 2023 14:40
src/Route.php Outdated Show resolved Hide resolved
src/Attribute/Delete.php Outdated Show resolved Hide resolved
src/Group.php Show resolved Hide resolved
src/Route.php Outdated Show resolved Hide resolved
src/RouteAttributesRegistrarInterface.php Outdated Show resolved Hide resolved
@vjik vjik added status:under development Someone is working on a pull request. and removed status:code review The pull request needs review. labels Jun 16, 2023
This was linked to issues Sep 16, 2023
xepozz and others added 4 commits October 9, 2023 21:08
* Add routes via resource + attributes

* Apply fixes from StyleCI

* Apply Rector changes (CI)

* Fix psalm

* Add missing file

* Apply fixes from StyleCI

* Rename Resource to Provider, add more tests

* Apply fixes from StyleCI

* Increase coverage

* Apply fixes from StyleCI

* Use variadic

---------

Co-authored-by: StyleCI Bot <[email protected]>
Co-authored-by: rustamwin <[email protected]>
@rustamwin rustamwin added status:code review The pull request needs review. and removed status:under development Someone is working on a pull request. labels Oct 15, 2023
->middleware(TestMiddleware1::class)
->action(static fn () => new Response(200));

$builtMiddlewares = $route->getData('builtMiddlewares');
Copy link
Member

Choose a reason for hiding this comment

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

Due to the PR is going to raise the major version of package let's remove getData to regular getter?

Copy link
Member

Choose a reason for hiding this comment

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

Due to the PR is going to raise the major version of package let's remove getData to regular getter?

Rename getData() to get() or create separate getters?

Copy link
Member

Choose a reason for hiding this comment

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

The second option

Copy link
Member

Choose a reason for hiding this comment

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

This is very non-comfortable when configre routes. IDE suggestions will get in the way in application, but getters in most cases need into packages only.

MiddlewareDispatcher $dispatcher = null
): self {
return new self($prefix, $dispatcher);
public static function create(?string $prefix = null): self
Copy link
Member

Choose a reason for hiding this comment

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

How about to eliminate this?

Copy link
Member

Choose a reason for hiding this comment

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

Create group via new Group is non-comfortable in application configuration.

Copy link
Member

Choose a reason for hiding this comment

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

Most case of usage groups required chain calls.

  1. Now: Group::create('/xxx')->...
  2. Your suggestion: (new Group('/xxx'))->...

Brackets in second way is non-comfortable =)

@@ -86,6 +72,9 @@ public function methods(): array
return $this->methods;
}

/**
* @psalm-assert-if-true !null $this->route
Copy link
Member

Choose a reason for hiding this comment

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

Why is it needed?

Copy link
Member Author

@rustamwin rustamwin Oct 15, 2023

Choose a reason for hiding this comment

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

Without this assertion psalm occurs PossiblyNullReference error.

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't because there is check for null in the function body 😕

src/Route.php Outdated Show resolved Hide resolved
src/Route.php Outdated Show resolved Hide resolved
@samdark
Copy link
Member

samdark commented Oct 19, 2023

TODO: move collector to https://github.com/yiisoft/router-composer-attribute-collector

@vjik vjik added status:under development Someone is working on a pull request. and removed status:code review The pull request needs review. labels Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:under development Someone is working on a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Named arguments vs immutable methods Add attributes support
5 participants