Skip to content

Commit 919c819

Browse files
committed
php util bugfixes
- fixed bug where either a comment or class constant could infer the wrong class type
1 parent 0f00277 commit 919c819

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

lib/GPH.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package GPH;
33
use strict;
44
use warnings FATAL => 'all';
55

6-
our $VERSION = '1.2.0';
6+
our $VERSION = '1.2.1';
77

88
1;
99

lib/GPH/Util/Php.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ sub new {
1616

1717
sub types {
1818
my ($self, @files) = @_;
19-
my ($fh, $pattern);
19+
my ($fh, $pattern, $constant);
2020

2121
foreach my $file (@files) {
2222
chomp $file;
2323
next unless $file =~ '[/]{0,}([^/]+)\.php$';
2424
open($fh, '<', getcwd() . '/' . $file) or die "unable to open file $file : $!";
2525

2626
$pattern = "[ ]{0,}([^ ]+) " . $1 . "(?:[ :]|\$){1,}";
27+
$constant = $1 . "::class";
2728

2829
while(<$fh>) {
2930
chomp $_;
31+
next if $_ =~ /^[\* ]\*/; #ignore comments
32+
next if $_ =~ $constant;
3033
next unless $_ =~ $pattern;
3134
my $type = ($1 ne 'enum') ? $1 : $self->resolveEnum(<$fh>);
3235

t/share/Php/Bar.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace share\Php;
44

5+
/**
6+
* this comment about Bar should be ignored
7+
*/
58
abstract class Bar
69
{
710

t/share/Php/Foo.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
trigger_error(sprintf('%s should not be used, use %s instead', Foo::class, Bar::class));
4+
35
final readonly class Foo
46
{
57

0 commit comments

Comments
 (0)