Skip to content

Commit

Permalink
Merge branch 'imanghafoori1:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
alikhosravidev authored Dec 13, 2023
2 parents 38562d4 + c728c49 commit e799f05
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 39 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/php.yml

This file was deleted.

2 changes: 2 additions & 0 deletions src/ClassReferenceFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ClassReferenceFinder
Keywords\Semicolon::class,
Keywords\Boolean::class,
Keywords\Comma::class,
Keywords\Enum::class,
Keywords\SquareBrackets::class,
Keywords\CurlyBrackets::class,
Keywords\RoundBrackets::class,
Expand Down Expand Up @@ -203,6 +204,7 @@ private static function defineConstants()
! defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG') && define('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', -385);
! defined('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG') && define('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', -386);
! defined('T_READONLY') && define('T_READONLY', -387);
! defined('T_ENUM') && define('T_ENUM', -721);
}

public static function explode($ref): array
Expand Down
18 changes: 18 additions & 0 deletions src/Keywords/Enum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Imanghafoori\TokenAnalyzer\Keywords;

use Imanghafoori\TokenAnalyzer\ClassRefProperties;

class Enum
{
public static function is($token)
{
return $token === T_ENUM;
}

public static function body(ClassRefProperties $properties)
{
$properties->isInSideClass = true;
}
}
22 changes: 22 additions & 0 deletions tests/Php81SyntaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ public function enums()
$this->assertEquals('', $interfaces);
}

/** @test */
public function traits_enum()
{
$string = file_get_contents(__DIR__.'/stubs/used_trait_enum.stub');
$tokens = token_get_all($string);

[$output, $namespace] = ClassReferenceFinder::process($tokens);

$this->assertEquals('MyTrait', $output[0][0][1]);
$this->assertEquals('Foo\Test', $output[1][0][1]);
$this->assertEquals('A', $output[2][0][1]);
$this->assertEquals('C', $output[3][0][1]);
$this->assertEquals('B', $output[4][0][1]);
$this->assertEquals('B', $output[5][0][1]);
$this->assertEquals('A', $output[6][0][1]);
$this->assertEquals('A', $output[7][0][1]);
$this->assertEquals('A', $output[8][0][1]);
$this->assertEquals('B', $output[9][0][1]);
$this->assertEquals('C', $output[10][0][1]);
$this->assertCount(11, $output);
}

/** @test */
public function intersection_types_in_typehinted_properties()
{
Expand Down
13 changes: 13 additions & 0 deletions tests/stubs/used_trait_enum.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

enum A
{
use MyTrait { foo as protected bar; }

use Foo\Test, A, C, B {
// B::smallTalk insteadof A test comment.
B::smallTalk insteadof A;
A::bigTalk as talk;
A::mediumTalk insteadof B, C
}
}

0 comments on commit e799f05

Please sign in to comment.