Skip to content

Commit

Permalink
Add IsTrait and IsNotTrait selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwriter authored Sep 29, 2024
1 parent 4c29e33 commit 737c6de
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
17 changes: 12 additions & 5 deletions docs/documentation/selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,27 @@ Select all interfaces.
## Selector::appliesAttribute()
Select classes that applies the given attribute.

## Selector::isEnum()
Select all enums.

## Selector::isAbstract()
Select all abstract classes.

## Selector::isAttribute()
Select all attribute classes.

## Selector::isEnum()
Select all enums.

## Selector::isFinal()
Select all final classes.

## Selector::isReadonly()
Select all readonly classes.

## Selector::isAttribute()
Select all attribute classes.
## Selector::isTrait()
Select all traits.

## Selector::isNotTrait()
Select all classes that are not traits.


<br />

Expand Down
2 changes: 1 addition & 1 deletion src/Selector/IsNotFinal.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class IsNotFinal implements SelectorInterface
{
public function getName(): string
{
return '-all final classes-';
return '-non final classes-';
}

public function matches(ClassReflection $classReflection): bool
Expand Down
18 changes: 18 additions & 0 deletions src/Selector/IsNotTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace PHPat\Selector;

use PHPStan\Reflection\ClassReflection;

final class IsNotTrait implements SelectorInterface
{
public function getName(): string
{
return '-non trait classes-';
}

public function matches(ClassReflection $classReflection): bool
{
return !$classReflection->isTrait();
}
}
18 changes: 18 additions & 0 deletions src/Selector/IsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace PHPat\Selector;

use PHPStan\Reflection\ClassReflection;

final class IsTrait implements SelectorInterface
{
public function getName(): string
{
return '-all traits-';
}

public function matches(ClassReflection $classReflection): bool
{
return $classReflection->isTrait();
}
}
10 changes: 10 additions & 0 deletions src/Selector/SelectorPrimitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public static function isFinal(): IsFinal
return new IsFinal();
}

public static function isTrait(): IsTrait
{
return new IsTrait();
}

public static function isNotTrait(): IsNotTrait
{
return new IsNotTrait();
}

/**
* @deprecated
* @see Selector::isReadonly()
Expand Down

0 comments on commit 737c6de

Please sign in to comment.