Skip to content

Commit

Permalink
property call implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Feb 25, 2025
1 parent 17b226f commit 01cac99
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
17 changes: 9 additions & 8 deletions src/linter/block_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,6 @@ func (b *blockLinter) checkClass(class *ir.ClassStmt) {
case *ir.ClassMethodStmt:
members = append(members, classMethod)
b.walker.CheckParamNullability(value.Params)
case *ir.PropertyListStmt:
for _, element := range value.Doc.Parsed {
if element.Name() == "deprecated" {
b.report(stmt, LevelNotice, "deprecated", "Has deprecated field in class %s", class.ClassName.Value)
}
}
members = append(members, classOtherMember)
default:
members = append(members, classOtherMember)
}
Expand Down Expand Up @@ -566,7 +559,7 @@ func (b *blockLinter) checkNew(e *ir.NewExpr) {

if class.IsDeprecated() {
if class.WithDeprecationNote() {
b.report(e, LevelNotice, "deprecated", "Try to create instance of the class %s (%s)", class.Name, class.DeprecationInfo)
b.report(e, LevelNotice, "deprecated", "Try to create instance of the class %s that was marked as deprecated (%s)", class.Name, class.DeprecationInfo)
} else {
b.report(e, LevelNotice, "deprecatedUntagged", "Try to create instance %s class that was marked as deprecated", class.Name)
}
Expand Down Expand Up @@ -1414,6 +1407,14 @@ func (b *blockLinter) checkPropertyFetch(e *ir.PropertyFetchExpr) {
if fetch.isFound && !fetch.isMagic && !canAccess(b.classParseState(), fetch.className, fetch.info.AccessLevel) {
b.report(e.Property, LevelError, "accessLevel", "Cannot access %s property %s->%s", fetch.info.AccessLevel, fetch.className, fetch.propertyNode.Value)
}

if fetch.info.IsDeprecated() {
if fetch.info.WithDeprecationNote() {
b.report(e, LevelNotice, "deprecated", "Try to call property %s that was marked as deprecated (%s) in the class %s", fetch.propertyNode.Value, fetch.info.DeprecationInfo, fetch.className)
} else {
b.report(e, LevelNotice, "deprecatedUntagged", "Try to call property %s that was marked as deprecated in the class %s", fetch.propertyNode.Value, fetch.className)
}
}
}

func (b *blockLinter) checkStaticPropertyFetch(e *ir.StaticPropertyFetchExpr) {
Expand Down
2 changes: 1 addition & 1 deletion src/linter/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ g();`,

{
Name: "deprecatedUntagged",
Default: false,
Default: true,
Quickfix: false,
Comment: "Report usages of deprecated symbols if the `@deprecated` tag has no description (see `deprecated` check).",
Before: `/**
Expand Down
29 changes: 21 additions & 8 deletions src/linter/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,19 +898,26 @@ func (d *rootWalker) handleClassDoc(doc classPHPDocParseResult, cl *meta.ClassIn
}
}

func (d *rootWalker) parsePHPDocVar(doc phpdoc.Comment) (typesMap types.Map) {
for _, part := range doc.Parsed {
part, ok := part.(*phpdoc.TypeVarCommentPart)
func (d *rootWalker) parsePHPDocVar(doc phpdoc.Comment) (typesMap types.Map, deprecationInfo meta.DeprecationInfo) {
for _, partDoc := range doc.Parsed {
part, ok := partDoc.(*phpdoc.TypeVarCommentPart)
if ok && part.Name() == "var" {
converted := phpdoctypes.ToRealType(d.ctx.typeNormalizer.ClassFQNProvider(), d.config.KPHP, part.Type)
moveShapesToContext(&d.ctx, converted.Shapes)
d.handleClosuresFromDoc(converted.Closures)

typesMap = types.NewMapWithNormalization(d.ctx.typeNormalizer, converted.Types)
}

rawPart, rawOk := partDoc.(*phpdoc.RawCommentPart)

if rawOk && rawPart.Name() == "deprecated" {
deprecationInfo.Deprecated = true
deprecationInfo.Reason = rawPart.ParamsText
}
}

return typesMap
return typesMap, deprecationInfo
}

func (d *rootWalker) enterPropertyList(pl *ir.PropertyListStmt) bool {
Expand All @@ -932,9 +939,14 @@ func (d *rootWalker) enterPropertyList(pl *ir.PropertyListStmt) bool {
}
}

phpDocType := d.parsePHPDocVar(pl.Doc)
phpDocType, deprecationInfo := d.parsePHPDocVar(pl.Doc)
typeHintType, _ := d.parseTypeHintNode(pl.Type)

deprecation, ok := attributes.Deprecated(pl.AttrGroups, d.ctx.st)
if ok {
deprecationInfo.Append(deprecation)
}

for _, pNode := range pl.Properties {
prop := pNode.(*ir.PropertyStmt)

Expand All @@ -955,9 +967,10 @@ func (d *rootWalker) enterPropertyList(pl *ir.PropertyListStmt) bool {

// TODO: handle duplicate property
cl.Properties[nm] = meta.PropertyInfo{
Pos: d.getElementPos(prop),
Typ: propTypes.Immutable(),
AccessLevel: accessLevel,
Pos: d.getElementPos(prop),
Typ: propTypes.Immutable(),
AccessLevel: accessLevel,
DeprecationInfo: deprecationInfo,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/linter/root_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *rootChecker) CheckPropertyList(pl *ir.PropertyListStmt) bool {
r.walker.Report(pl, LevelNotice, "implicitModifiers", "Specify the access modifier for %s explicitly", target)
}

docblockType := r.walker.parsePHPDocVar(pl.Doc)
docblockType, _ := r.walker.parsePHPDocVar(pl.Doc)

r.CheckCommentMisspellings(pl, pl.Doc.Raw)
r.CheckPHPDocVar(pl, pl.Doc, docblockType)
Expand Down

0 comments on commit 01cac99

Please sign in to comment.