Skip to content

[SCI] add GetArtifact to ComposerLockExtractor for build file analysis#185

Merged
anderruiz merged 4 commits into
mainfrom
ander/php-composer-support
Jul 6, 2026
Merged

[SCI] add GetArtifact to ComposerLockExtractor for build file analysis#185
anderruiz merged 4 commits into
mainfrom
ander/php-composer-support

Conversation

@anderruiz

Copy link
Copy Markdown
Contributor

Summary

Adds PHP Composer build file analysis support, following the same pattern established in #179 for Go modules.

  • Implements GetArtifact() on ComposerLockExtractor, reading composer.json from the same directory to extract the project name ("name" field)
  • Registers SimpleProcessor for FileTypeComposerJSON so PHP projects appear in build file trees

Note: composer.lock is always co-located with composer.json in PHP — no workspace/root-lock pattern exists (unlike Cargo), so the co-location assumption is safe for all native Composer projects.

Test plan

  • Happy path: composer.lock + composer.json with name field → correct ScannedArtifact returned
  • Missing composer.json → nil artifact returned gracefully
  • composer.json present but no name field → nil artifact returned gracefully
  • Full test suite (go test ./...) — 30+ packages, zero regressions

🤖 Generated with Claude Code

anderruiz added 2 commits July 3, 2026 15:57
…alysis

- Implement GetArtifact() on ComposerLockExtractor to satisfy ArtifactExtractor interface
- Read co-located composer.json to extract the project name field
- Return artifact with empty name when composer.json is missing or has no name field
- Add compile-time interface check for ArtifactExtractor
- Add 3 tests: happy path, missing composer.json, missing name field

Rationale: PHP Composer projects need build file analysis support so that
datadog-sbom-generator can identify project artifacts from composer.lock files.
This follows the same pattern established by the Go extractor (PR #179),
reading the manifest file (composer.json) to extract the project identity.

This commit made by [/dd:git:commit:atomic](https://github.com/DataDog/claude-marketplace/tree/main/dd/commands/git/commit/atomic.md)
- Add FileTypeComposerJSON to SimpleProcessor init() registration
- Enables BFS-based transitive dependency resolution for composer.json build files

Rationale: With ComposerLockExtractor now implementing ArtifactExtractor,
composer.json files appear as file-type SBOM components. Registering a
SimpleProcessor allows GetBuildFileTrees to resolve their relationships
using the same BFS pattern used by Go, Python, Maven, and other ecosystems.

This commit made by [/dd:git:commit:atomic](https://github.com/DataDog/claude-marketplace/tree/main/dd/commands/git/commit/atomic.md)
@anderruiz
anderruiz requested a review from a team as a code owner July 6, 2026 08:56
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 6, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 80.00%
Overall Coverage: 84.14% (-0.08%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2f29298 | Docs | Datadog PR Page | Give us feedback!

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c8121d7a8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

func (e ComposerLockExtractor) GetArtifact(f extractor.DepFile, ctx extractor.ScanContext) (*models.ScannedArtifact, error) {
artifact := &models.ScannedArtifact{
ArtifactDetail: models.ArtifactDetail{
Filename: f.Path(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Key Composer artifacts by composer.json

When composer.json exists, this still records the artifact under composer.lock. addFileDependencies keys file components and dependency edges by artifact.Filename, while GetBuildFileTrees groups Composer build files by the composer.json basename and Composer package occurrences point at composer.json after matching. In those scans the new artifact ID/property and any internal Composer dependency edges are attached to composer.lock, so the registered Composer processor cannot populate the intended composer.json build-file tree; set Filename to the resolved composerJSONPath once that file is found.

Useful? React with 👍 / 👎.

anderruiz and others added 2 commits July 6, 2026 11:05
Extract optional composer.json reading into a helper function that
returns a string instead of an error, avoiding the nilerr lint violation
where a non-nil error was checked but nil was returned.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Set Filename to the composer.json path (not composer.lock) so the build
file tree system correctly groups Composer components by the manifest.
Return nil when composer.json is absent — no artifact to report.
@anderruiz

Copy link
Copy Markdown
Contributor Author

Fixed (2f29298). Set Filename to the composer.json path so the build file tree is keyed by the manifest; return nil when composer.json is absent.

@anderruiz anderruiz changed the title feat(php): add GetArtifact to ComposerLockExtractor for build file analysis [SCI] add GetArtifact to ComposerLockExtractor for build file analysis Jul 6, 2026
@anderruiz
anderruiz merged commit ea49d6c into main Jul 6, 2026
11 of 12 checks passed
@anderruiz
anderruiz deleted the ander/php-composer-support branch July 6, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants