MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / ParseComposerJsonWithLock

Function ParseComposerJsonWithLock

opensca/sca/php/composer.go:47–99  ·  view source on GitHub ↗
(json *ComposerJson, lock *ComposerLock)

Source from the content-addressed store, hash-verified

45}
46
47func ParseComposerJsonWithLock(json *ComposerJson, lock *ComposerLock) *model.DepGraph {
48
49 root := &model.DepGraph{Name: json.Name, Path: json.File.Relpath()}
50 root.AppendLicense(json.License)
51
52 _dep := model.NewDepGraphMap(nil, func(s ...string) *model.DepGraph { return &model.DepGraph{Name: s[0]} }).LoadOrStore
53
54 // 第一次遍历记录依赖信息
55 for _, pkg := range lock.Packages {
56 dep := _dep(pkg.Name)
57 dep.Version = pkg.Version
58 for _, lic := range pkg.License {
59 dep.AppendLicense(lic)
60 }
61 }
62 for _, pkg := range lock.PackagesDev {
63 dep := _dep(pkg.Name)
64 dep.Version = pkg.Version
65 dep.Develop = true
66 for _, lic := range pkg.License {
67 dep.AppendLicense(lic)
68 }
69 }
70
71 // 第二次遍历记录依赖关系
72 for _, pkg := range append(lock.Packages, lock.PackagesDev...) {
73 dep := _dep(pkg.Name)
74 for name := range pkg.Require {
75 if skip(name) {
76 continue
77 }
78 dep.AppendChild(_dep(name))
79 }
80 }
81
82 // 记录直接依赖
83 names := []string{}
84 for name := range json.Require {
85 names = append(names, name)
86 }
87 for name := range json.RequireDev {
88 names = append(names, name)
89 }
90 sort.Strings(names)
91 for _, name := range names {
92 if skip(name) {
93 continue
94 }
95 root.AppendChild(_dep(name))
96 }
97
98 return root
99}
100
101func ParseComposerJsonWithOrigin(json *ComposerJson) *model.DepGraph {
102

Callers 1

ScaMethod · 0.85

Calls 5

AppendLicenseMethod · 0.95
AppendChildMethod · 0.95
NewDepGraphMapFunction · 0.92
skipFunction · 0.85
RelpathMethod · 0.80

Tested by

no test coverage detected