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

Return match results as objects #24

Merged
merged 15 commits into from
Oct 10, 2023
Merged

Return match results as objects #24

merged 15 commits into from
Oct 10, 2023

Conversation

untone-survive
Copy link
Contributor

@untone-survive untone-survive commented Oct 9, 2023

Previously matches for technologies were returned as associative array. So we had to depend on keys of those arrays, which could be present or not.

This PR introduces MatchResultInterface which allows to get all the required info:

interface MatchResultInterface
{
    public function getMatcher(): string;
    public function getPath(): string;
    public function getVersion(): ?string;
    public function getApplication(): ?string;
}

Every matcher has it's own math result object (i.e. WordpressMatchResult, JoomlaMatchResult, SymfonyMatchResult) which allows further checks to be implemented in code using instanceof etc.

Default implementation of MatchResultInterface now has the built-in path normalizer which was previously used only in UpLevelMatcherTrait.

Also separate EmptyMatchResult is introduced to represent the empty search. Previously empty array was used for that.

All matchers, CLI command and tests were rewritten to reflect the changes.


class YiiMatcher implements WappMatcherInterface
class YiiMatcher implements MatcherInterface
Copy link

Choose a reason for hiding this comment

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

Yii

'path' => $path,
'version' => $version,
];
return new Yii($path, $this->detectVersion($fs, $path));
Copy link

Choose a reason for hiding this comment

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

MatchResult\Yii

Copy link

Choose a reason for hiding this comment

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

Or you can use an alias

}
}


Copy link

Choose a reason for hiding this comment

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

extra line

return $this->application;
}

public function jsonSerialize(): array
Copy link

Choose a reason for hiding this comment

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

It looks like this name doesn't fit the aim of this function because of the return type (array).
JSON is string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its required to be this way for \JsonSerializable interface

@untone-survive untone-survive merged commit b959afe into main Oct 10, 2023
2 checks passed
@untone-survive untone-survive deleted the oop-style branch October 10, 2023 05:29
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.

2 participants