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

Improve containers types to use iterable objects #299

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

Conversation

xepozz
Copy link
Contributor

@xepozz xepozz commented Apr 19, 2022

Q A
Is bugfix? ✔️
New feature? ✔️
Breaks BC?
Fixed issues

Added ability to use iterable parameters.
For example, now you cannot use Generator as tags values.

@xepozz xepozz requested a review from a team April 19, 2022 19:53
@xepozz xepozz added the status:code review The pull request needs review. label Apr 19, 2022
src/Container.php Outdated Show resolved Hide resolved
src/Container.php Outdated Show resolved Hide resolved
src/Container.php Show resolved Hide resolved
src/Container.php Show resolved Hide resolved
src/Container.php Show resolved Hide resolved
src/Container.php Show resolved Hide resolved
src/Container.php Show resolved Hide resolved
src/Container.php Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Dec 2, 2022

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (8e264ff) 100.00% compared to head (0e4059d) 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #299   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       158       160    +2     
===========================================
  Files             11        11           
  Lines            460       467    +7     
===========================================
+ Hits             460       467    +7     
Impacted Files Coverage Δ
src/Container.php 100.00% <100.00%> (ø)
src/ContainerConfig.php 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@vjik vjik left a comment

Choose a reason for hiding this comment

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

Overall good. One change is needed to satisfy psalm.

src/ContainerConfigInterface.php Outdated Show resolved Hide resolved
Co-authored-by: Sergei Predvoditelev <[email protected]>
@samdark
Copy link
Member

samdark commented Dec 5, 2022

@xepozz need a line for CHANGELOG. Also, it looks like BC-breaking change.

@xepozz
Copy link
Contributor Author

xepozz commented Jul 1, 2023

@xepozz need a line for CHANGELOG. Also, it looks like BC-breaking change.

Done. I can keep it for 2.0

CHANGELOG.md Outdated Show resolved Hide resolved
}

public function dataInvalidTags(): array
{
return [
[
'/^Invalid tags configuration: tag should be string, 42 given\.$/',
'Invalid tags configuration: tag should be string, array given.',
Copy link
Member

Choose a reason for hiding this comment

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

That does not look right. The problem here is 42, right?


$id = (string) $id;
Copy link
Member

Choose a reason for hiding this comment

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

Not need type-casting. Above check that $id is string.

@@ -323,10 +325,12 @@ private function validateDefinition(mixed $definition, ?string $id = null): void
/**
* @throws InvalidConfigException
*/
private function validateMeta(array $meta): void
private function validateMeta(iterable $meta): void
Copy link
Member

Choose a reason for hiding this comment

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

validateMeta always receive array. Not need iterable.

foreach ($meta as $key => $value) {
$key = (string)$key;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$key = (string)$key;

Not need.

}

$tags = $this->tags[$tag];
$tags = $tags instanceof Traversable ? iterator_to_array($tags, true) : $tags;
Copy link
Member

Choose a reason for hiding this comment

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

Better convert iterable to array before foreach

@@ -58,5 +58,5 @@ public function getDefinitions(): array;
* @return array Extensions for the container services. Each array key is the name of the service to be modified
* and a corresponding value is callable doing the job.
*/
public function getExtensions(): array;
public function getExtensions(): iterable;
Copy link
Member

Choose a reason for hiding this comment

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

Need fix phpdoc.

@@ -42,7 +42,7 @@ interface ServiceProviderInterface
* @return array Definitions for the container. Each array key is the name of the service (usually it is
* an interface name), and a corresponding value is a service definition.
*/
public function getDefinitions(): array;
public function getDefinitions(): iterable;
Copy link
Member

Choose a reason for hiding this comment

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

Need fix phpdoc.

{
if ($this->validate) {
foreach ($tags as $tag => $services) {
if (!is_string($tag)) {
throw new InvalidConfigException(
sprintf(
'Invalid tags configuration: tag should be string, %s given.',
$tag
get_debug_type($services)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
get_debug_type($services)
get_debug_type($tag)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:code review The pull request needs review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants