Skip to content

Commit

Permalink
fix(php): handle comments in const declaration (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski authored Feb 12, 2024
1 parent 55532e6 commit a40d59a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions internal/languages/php/.snapshots/TestConst--main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ low:
title: ""
description: ""
documentation_url: ""
line_number: 7
line_number: 9
full_filename: main.php
filename: main.php
source:
location:
start: 7
end: 7
start: 9
end: 9
column:
start: 10
end: 38
sink:
location:
start: 7
end: 7
start: 9
end: 9
column:
start: 10
end: 38
content: hash( self::ALGO, $content )
parent_line_number: 7
parent_line_number: 9
snippet: hash( self::ALGO, $content )
fingerprint: b1e6825cdfdbf302da0f7c9887efd995_0
old_fingerprint: b1e6825cdfdbf302da0f7c9887efd995_0
Expand Down
10 changes: 7 additions & 3 deletions internal/languages/php/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ func (analyzer *analyzer) analyzeSubscript(node *sitter.Node, visitChildren func
}

func (analyzer *analyzer) analyzeConstDeclaration(node *sitter.Node, visitChildren func() error) error {
child := node.NamedChild(0)
var child *sitter.Node

if child.Type() == "visibility_modifier" {
child = node.NamedChild(1)
for i := 0; i < int(node.ChildCount()); i++ {
child = node.NamedChild(i)

if child.Type() == "const_element" {
break
}
}

left := child.NamedChild(0)
Expand Down
2 changes: 2 additions & 0 deletions internal/languages/php/testdata/md/main.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
class ContentsHasher {
private const ALGO = 'md4';
private const Type /* comment */ FOO = 'md4';
private const /** @noinspection PhpUnusedPrivateFieldInspection */ FLD_FLAGS = 4;

public static function getFileContentsHash( $content ) {

Expand Down

0 comments on commit a40d59a

Please sign in to comment.