Skip to content

Commit da53a35

Browse files
committed
feat(php): Implement PHP analyser
1 parent 4149700 commit da53a35

File tree

23 files changed

+592
-336
lines changed

23 files changed

+592
-336
lines changed

analyzers/analyzer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/fossas/fossa-cli/analyzers/golang"
99
"github.com/fossas/fossa-cli/analyzers/gradle"
1010
"github.com/fossas/fossa-cli/analyzers/nodejs"
11+
"github.com/fossas/fossa-cli/analyzers/php"
1112
"github.com/fossas/fossa-cli/analyzers/python"
1213
"github.com/fossas/fossa-cli/analyzers/ruby"
1314

@@ -48,7 +49,7 @@ func New(key pkg.Type, options map[string]interface{}) (Analyzer, error) {
4849
case pkg.Cocoapods:
4950
return nil, ErrAnalyzerNotImplemented
5051
case pkg.Composer:
51-
return nil, ErrAnalyzerNotImplemented
52+
return php.New(options)
5253
case pkg.Go:
5354
return golang.New(options)
5455
case pkg.Gradle:

analyzers/bower/bower.go

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ type Analyzer struct {
2828
Options Options
2929
}
3030

31+
// TODO: strategies:
32+
// - bower list
33+
// - read components
34+
// - read manifest
35+
3136
type Options struct {
3237
Strategy string `mapstructure:"strategy"`
3338
ComponentsDir string `mapstructure:"components"`

analyzers/bower/tool.go

-1
This file was deleted.

analyzers/golang/revision.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (a *Analyzer) RevisionContextualLookup(project Project, gopkg gocmd.Package
132132
// with) the project, or otherwise don't have revisions.
133133
func (a *Analyzer) UnresolvedOK(project Project, gopkg gocmd.Package) bool {
134134
withinDir :=
135-
strings.HasPrefix(gopkg.Dir, project.Dir) && strings.Index(gopkg.Dir, "/vendor/") == -1
135+
strings.HasPrefix(gopkg.Dir, project.Dir) && !strings.Contains(gopkg.Dir, "/vendor/")
136136

137137
allowedPrefixes := strings.Split(a.Options.AllowUnresolvedPrefix, " ")
138138
hasAllowedPrefix := false

analyzers/golang/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Unvendor(importpath string) string {
5252
// if none exists.
5353
func VendorParent(dirname string) string {
5454
separator := filepath.FromSlash("/vendor/")
55-
if strings.Index(dirname, separator) == -1 {
55+
if !strings.Contains(dirname, separator) {
5656
return "."
5757
}
5858
sections := strings.Split(dirname, separator)

analyzers/gradle/gradle.go

+10-15
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,11 @@ func (a *Analyzer) Discover(dir string) ([]module.Module, error) {
9090
return err
9191
}
9292
for _, project := range projects {
93-
// TODO: this won't work until v2 configuration files are implemented.
94-
// modules = append(modules, module.Module{
95-
// Name: name,
96-
// Type: pkg.Gradle,
97-
// BuildTarget: project + ":compile",
98-
// Dir: dir,
99-
// })
10093
modules = append(modules, module.Module{
101-
Name: name,
94+
Name: filepath.Join(name, project),
10295
Type: pkg.Gradle,
10396
BuildTarget: dir,
97+
Dir: dir,
10498
Options: map[string]interface{}{
10599
"project": project,
106100
},
@@ -138,30 +132,31 @@ func (a *Analyzer) Analyze(m module.Module) (module.Module, error) {
138132
Dir: m.Dir,
139133
Online: a.Options.Online,
140134
}
135+
var imports []gradle.Dependency
141136
var deps map[gradle.Dependency][]gradle.Dependency
142137
var err error
143138
if a.Options.Task != "" {
144-
deps, err = g.DependenciesTask(strings.Split(a.Options.Task, " ")...)
139+
imports, deps, err = g.DependenciesTask(strings.Split(a.Options.Task, " ")...)
145140
if err != nil {
146141
return m, err
147142
}
148143
} else if a.Options.Project != "" {
149-
deps, err = g.Dependencies(a.Options.Project, a.Options.Configuration)
144+
imports, deps, err = g.Dependencies(a.Options.Project, a.Options.Configuration)
150145
if err != nil {
151146
return m, err
152147
}
153148
} else {
154149
targets := strings.Split(m.BuildTarget, ":")
155-
deps, err = g.Dependencies(targets[0], targets[1])
150+
imports, deps, err = g.Dependencies(targets[0], targets[1])
156151
if err != nil {
157152
return m, err
158153
}
159154
}
160155

161156
// Set direct dependencies.
162-
var imports []pkg.Import
163-
for _, dep := range deps[gradle.Root] {
164-
imports = append(imports, pkg.Import{
157+
var i []pkg.Import
158+
for _, dep := range imports {
159+
i = append(i, pkg.Import{
165160
Target: dep.Target,
166161
Resolved: pkg.ID{
167162
Type: pkg.Gradle,
@@ -200,7 +195,7 @@ func (a *Analyzer) Analyze(m module.Module) (module.Module, error) {
200195
}
201196
}
202197

203-
m.Imports = imports
198+
m.Imports = i
204199
m.Deps = graph
205200
return m, nil
206201
}

analyzers/maven/maven.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (builder *MavenBuilder) IsBuilt(m module.Module, allowUnresolved bool) (boo
201201
Argv: []string{"dependency:list", "-B"},
202202
})
203203
if err != nil {
204-
if strings.Index(output, "Could not find artifact") != -1 {
204+
if strings.Contains(output, "Could not find artifact") {
205205
return false, nil
206206
}
207207
return false, err

analyzers/nodejs/nodejs.go

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ func (a *Analyzer) Analyze(m module.Module) (module.Module, error) {
255255
return m, nil
256256
}
257257

258+
// TODO: implement this generically in package graph (Bower also has an
259+
// implementation)
258260
func recurseDeps(pkgMap map[pkg.ID]pkg.Package, p npm.Output) {
259261
for name, dep := range p.Dependencies {
260262
// Construct ID.

analyzers/php/composer.go

-252
This file was deleted.

0 commit comments

Comments
 (0)