a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
39 lines
1.7 KiB
Go
39 lines
1.7 KiB
Go
package languages
|
|
|
|
import "strings"
|
|
|
|
// Eloquent static finder/query methods. A Laravel model's static call
|
|
// (`User::find(1)`, `User::where(...)`, `Post::create([...])`) dispatches to
|
|
// the query-builder inherited from Illuminate\Database\Eloquent\Model, so the
|
|
// concrete method is not declared on the model class and the call would go
|
|
// unresolved. This allowlist lets the extractor bind such a call to the model
|
|
// class node instead — a far more useful target than a name-only `find`
|
|
// match. Kept beside phpLaravelFacadesDefault as a plain table.
|
|
var phpEloquentStaticMethods = map[string]bool{
|
|
"find": true, "findOrFail": true, "findOr": true, "findMany": true,
|
|
"where": true, "whereIn": true, "whereNotIn": true, "whereHas": true,
|
|
"all": true, "get": true, "first": true, "firstOrFail": true,
|
|
"firstOrCreate": true, "firstOrNew": true, "firstWhere": true,
|
|
"create": true, "make": true, "forceCreate": true,
|
|
"updateOrCreate": true, "insert": true, "query": true, "with": true,
|
|
"orderBy": true, "latest": true, "oldest": true, "count": true,
|
|
"pluck": true, "destroy": true, "paginate": true, "exists": true,
|
|
}
|
|
|
|
// phpEloquentModelCall reports whether a `Scope::method(...)` static call is
|
|
// an Eloquent finder on a model — a PascalCase class name plus an
|
|
// allowlisted query method. Returns the bare model class name on a match.
|
|
func phpEloquentModelCall(scope, method string) (string, bool) {
|
|
if !phpEloquentStaticMethods[method] {
|
|
return "", false
|
|
}
|
|
model := strings.TrimPrefix(scope, "\\")
|
|
if i := strings.LastIndex(model, "\\"); i >= 0 {
|
|
model = model[i+1:]
|
|
}
|
|
if model == "" || model[0] < 'A' || model[0] > 'Z' {
|
|
return "", false
|
|
}
|
|
return model, true
|
|
}
|