Skip to content

Commit

Permalink
fix composer
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Mar 29, 2023
1 parent bd4a86b commit 6d53d7f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 30 deletions.
6 changes: 1 addition & 5 deletions pkg/fanal/analyzer/language/php/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ func (a composerAnalyzer) Version() int {
}

func (a composerAnalyzer) parseComposerLock(path string, r dio.ReadSeekerAt) (*types.Application, error) {
libs, deps, err := a.lockParser.Parse(r)
if err != nil {
return nil, xerrors.Errorf("unable to parse composer.lock: %w", err)
}
return language.ToApplication(types.Composer, path, "", libs, deps), nil
return language.Parse(types.Composer, path, r, a.lockParser)
}

func (a composerAnalyzer) mergeComposerJson(fsys fs.FS, dir string, app *types.Application) error {
Expand Down
70 changes: 45 additions & 25 deletions pkg/fanal/analyzer/language/php/composer/composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,31 @@ func Test_composerAnalyzer_PostAnalyze(t *testing.T) {
FilePath: "composer.lock",
Libraries: []types.Package{
{
ID: "pear/[email protected]",
Name: "pear/log",
Version: "1.13.3",
Indirect: false,
Licenses: []string{"MIT"},
Locations: []types.Location{{StartLine: 9, EndLine: 68}},
ID: "pear/[email protected]",
Name: "pear/log",
Version: "1.13.3",
Indirect: false,
Licenses: []string{"MIT"},
Locations: []types.Location{
{
StartLine: 9,
EndLine: 68,
},
},
DependsOn: []string{"pear/[email protected]"},
},
{
ID: "pear/[email protected]",
Name: "pear/pear_exception",
Version: "v1.0.2",
Indirect: true,
Licenses: []string{"BSD-2-Clause"},
Locations: []types.Location{{StartLine: 69, EndLine: 127}},
ID: "pear/[email protected]",
Name: "pear/pear_exception",
Version: "v1.0.2",
Indirect: true,
Licenses: []string{"BSD-2-Clause"},
Locations: []types.Location{
{
StartLine: 69,
EndLine: 127,
},
},
},
},
},
Expand All @@ -58,21 +68,31 @@ func Test_composerAnalyzer_PostAnalyze(t *testing.T) {
FilePath: "composer.lock",
Libraries: []types.Package{
{
ID: "pear/[email protected]",
Name: "pear/log",
Version: "1.13.3",
Indirect: false,
Licenses: []string{"MIT"},
Locations: []types.Location{{StartLine: 9, EndLine: 68}},
ID: "pear/[email protected]",
Name: "pear/log",
Version: "1.13.3",
Indirect: false,
Licenses: []string{"MIT"},
Locations: []types.Location{
{
StartLine: 9,
EndLine: 68,
},
},
DependsOn: []string{"pear/[email protected]"},
},
{
ID: "pear/[email protected]",
Name: "pear/pear_exception",
Version: "v1.0.2",
Indirect: false,
Licenses: []string{"BSD-2-Clause"},
Locations: []types.Location{{StartLine: 69, EndLine: 127}},
ID: "pear/[email protected]",
Name: "pear/pear_exception",
Version: "v1.0.2",
Indirect: false,
Licenses: []string{"BSD-2-Clause"},
Locations: []types.Location{
{
StartLine: 69,
EndLine: 127,
},
},
},
},
},
Expand All @@ -82,7 +102,7 @@ func Test_composerAnalyzer_PostAnalyze(t *testing.T) {
{
name: "broken composer.lock",
dir: "testdata/sad",
wantErr: "unable to parse composer.lock",
wantErr: "failed to parse composer.lock",
},
}

Expand Down

0 comments on commit 6d53d7f

Please sign in to comment.