Skip to content

Discover providers from the project itself.#84

Open
sukei wants to merge 1 commit into
xefi:mainfrom
sukei:feature/provider-discovery
Open

Discover providers from the project itself.#84
sukei wants to merge 1 commit into
xefi:mainfrom
sukei:feature/provider-discovery

Conversation

@sukei

@sukei sukei commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The auto-discovery feature of installed packages is nice, however it fails to discover project-local providers and extensions. This PR address this issue by reading the project composer.json file too.

Summary by CodeRabbit

  • New Features

    • Manifest generation now includes configuration from the project’s root composer.json when extra.faker is present.
    • Project-level configuration can now be reflected under a default package entry when no package-specific source is available.
  • Bug Fixes

    • Manifests now rebuild when the root composer.json changes, reducing stale configuration issues.
    • Improved rebuild checks for manifest freshness to better keep generated output in sync.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Modifies manifest recompilation checks in ContainerMixinManifest and PackageManifest to also account for the project's root composer.json, adds extraction of root-level extra.faker configuration in PackageManifest, adjusts argument order in a Method tag call, and adds a test support composer.json fixture.

Changes

Manifest Root composer.json Handling

Layer / File(s) Summary
PackageManifest root composer.json integration
src/Manifests/PackageManifest.php
build() now also reads root composer.json for extra.faker and merges it into the packages map under root fallback key; shouldRecompile() now also compares against root composer.json timestamp.
ContainerMixinManifest recompilation and Method tag fix
src/Manifests/ContainerMixinManifest.php
shouldRecompile() adds a filemtime check against root composer.json; Method tag instantiation reorders parameters before returnType.
Test support fixture
tests/Support/composer.json
Adds a new composer.json fixture with package name xefi/faker-php-tests-support.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • xefi/faker-php#80: Related to the Method tag argument reordering, aligning with reflection-docblock v6 compatibility changes.

Suggested reviewers: martinsoenen

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: discovering providers from the project’s own composer.json.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/Manifests/ContainerMixinManifest.php (1)

145-147: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Same filemtime guard issue as PackageManifest::shouldRecompile().

filemtime($this->basePath.'/composer.json') will emit a PHP warning if the file doesn't exist. Apply the same is_file() guard suggested for PackageManifest::shouldRecompile().

🛡️ Proposed fix
 public function shouldRecompile(): bool
 {
     return !is_file($this->containerMixinPath) ||
         // We check here if the manifest has been generated before changing the installed.json composer file or the project composer.json
-        filemtime($this->containerMixinPath) <= filemtime($this->vendorPath.'/composer/installed.json') ||
-        filemtime($this->containerMixinPath) <= filemtime($this->basePath.'/composer.json');
+        (is_file($this->vendorPath.'/composer/installed.json') && filemtime($this->containerMixinPath) <= filemtime($this->vendorPath.'/composer/installed.json')) ||
+        (is_file($this->basePath.'/composer.json') && filemtime($this->containerMixinPath) <= filemtime($this->basePath.'/composer.json'));
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Manifests/ContainerMixinManifest.php` around lines 145 - 147, The
`ContainerMixinManifest` freshness check has the same unsafe `filemtime` usage
as `PackageManifest::shouldRecompile()`, and
`filemtime($this->basePath.'/composer.json')` can warn when the file is missing.
Update the logic around the manifest rebuild guard to use an `is_file()` check
before calling `filemtime()` for the project composer file, keeping the existing
comparison behavior in `ContainerMixinManifest` while avoiding warnings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Manifests/PackageManifest.php`:
- Around line 144-147: The shouldRecompile() logic in PackageManifest currently
calls filemtime() on composer.json without verifying the file exists, which can
trigger warnings on missing layouts. Update shouldRecompile() to mirror the
build() guard by checking is_file() before any filemtime() call on the basePath
composer.json (and any other potentially absent paths), and only compare mtimes
when the files are present.

---

Duplicate comments:
In `@src/Manifests/ContainerMixinManifest.php`:
- Around line 145-147: The `ContainerMixinManifest` freshness check has the same
unsafe `filemtime` usage as `PackageManifest::shouldRecompile()`, and
`filemtime($this->basePath.'/composer.json')` can warn when the file is missing.
Update the logic around the manifest rebuild guard to use an `is_file()` check
before calling `filemtime()` for the project composer file, keeping the existing
comparison behavior in `ContainerMixinManifest` while avoiding warnings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0bb7e42d-a324-4d6a-bce2-f9e069c8f188

📥 Commits

Reviewing files that changed from the base of the PR and between 772724b and 5611b17.

📒 Files selected for processing (3)
  • src/Manifests/ContainerMixinManifest.php
  • src/Manifests/PackageManifest.php
  • tests/Support/composer.json

Comment thread src/Manifests/PackageManifest.php
$methodName,
returnType: $reflectionMethod->hasReturnType() ? (new TypeResolver())->resolve($reflectionMethod->getReturnType()) : new Mixed_(),
parameters: $parameters,
returnType: $reflectionMethod->hasReturnType() ? (new TypeResolver())->resolve($reflectionMethod->getReturnType()) : new Mixed_(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is the point of this change please ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just a sort of the parameters by the signature order. Not a requirement, but a "CS" fix.

@@ -0,0 +1,3 @@
{
"name": "xefi/faker-php-tests-support"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add some unit tests for your feature

@martinsoenen

Copy link
Copy Markdown
Contributor

Interesting changes, thank you. I added some little feedbacks but the main thing is cool !

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