Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bcb7ffc
Refactoring & PhpParserClassifier
rustamwin Sep 22, 2023
c0af53d
Apply fixes from StyleCI
StyleCIBot Sep 22, 2023
f4c0001
Fix tests
rustamwin Sep 22, 2023
2a7d0ec
Merge remote-tracking branch 'origin/refactoring' into refactoring
rustamwin Sep 22, 2023
9cc0ec1
Apply fixes from StyleCI
StyleCIBot Sep 22, 2023
4f5a066
Fix visitor registering
rustamwin Sep 22, 2023
0185913
Minor fix
rustamwin Sep 22, 2023
947ac8a
Refactor
rustamwin Sep 22, 2023
fb2c95e
Increase code coverage
rustamwin Sep 23, 2023
38170d7
Apply fixes from StyleCI
StyleCIBot Sep 23, 2023
33017d6
Fix method visibility
rustamwin Sep 23, 2023
9d70f93
[Skip CI] Add phpdoc
rustamwin Sep 24, 2023
8f715bb
Adjust naming & add phpdocs
rustamwin Sep 28, 2023
1fd7d54
Add phpdoc & fix composer
rustamwin Sep 28, 2023
baa2ae4
Fix composer checker
rustamwin Sep 28, 2023
13f251d
Optimize visitor
rustamwin Sep 28, 2023
cc2bcb4
Ignore wrong file
rustamwin Sep 28, 2023
3fe9c9c
Apply fixes from StyleCI
StyleCIBot Sep 28, 2023
f8716a6
Fix styleci config
rustamwin Sep 28, 2023
46cf634
Minor test
rustamwin Oct 15, 2023
2db3db7
Move parser classifier into separate PR
rustamwin Oct 15, 2023
76f5f2f
Token classifier & refactor filters (#41)
rustamwin Oct 26, 2023
517c3a4
Add benchmark
rustamwin Oct 27, 2023
4b23d76
Add filters & tests
rustamwin Oct 30, 2023
4f3c784
Apply fixes from StyleCI
StyleCIBot Oct 30, 2023
c107e22
Fix psalm issues
rustamwin Oct 30, 2023
a46716f
Merge remote-tracking branch 'origin/refactoring' into refactoring
rustamwin Oct 30, 2023
22e723e
Add more tests & benchmark
rustamwin Oct 31, 2023
d043b6a
Minor fix
rustamwin Nov 1, 2023
776980f
Fix composer checker config
rustamwin Nov 1, 2023
5b23a1f
Fix composer-checker
rustamwin Nov 3, 2023
8e1896c
Merge branch 'master' into refactoring
samdark Jul 16, 2024
4054276
Apply fixes from StyleCI
StyleCIBot Jul 16, 2024
b357dac
Remove Classifier.php that was resurrected by merge
samdark Jul 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: bechmark

jobs:
phpbench:
uses: yiisoft/actions/.github/workflows/phpbench.yml@master
with:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.1', '8.2']
report: aggregate

2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.0', '8.1']
['8.1', '8.2']
2 changes: 1 addition & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.1']
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1']
['8.2']
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.2']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1']
['8.1', '8.2']
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build:

environment:
php:
version: 8.0.18
version: 8.1
ini:
xdebug.mode: coverage

Expand Down
3 changes: 3 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ finder:
exclude:
- docs
- vendor
not-name:
- wrong_file.php
- namespace.php

enabled:
- alpha_ordered_traits
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
[![Latest Stable Version](https://poser.pugx.org/yiisoft/classifier/v/stable.png)](https://packagist.org/packages/yiisoft/classifier)
[![Total Downloads](https://poser.pugx.org/yiisoft/classifier/downloads.png)](https://packagist.org/packages/yiisoft/classifier)
[![Build status](https://github.com/yiisoft/classifier/workflows/build/badge.svg)](https://github.com/yiisoft/classifier/actions?query=workflow%3Abuild)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/classifier/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/classifier/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/classifier/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/classifier/?branch=master)
[![Code Coverage](https://codecov.io/gh/yiisoft/classifier/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/classifier)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fclassifier%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/classifier/master)
[![static analysis](https://github.com/yiisoft/classifier/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/classifier/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/classifier/coverage.svg)](https://shepherd.dev/github/yiisoft/classifier)
[![psalm-level](https://shepherd.dev/github/yiisoft/classifier/level.svg)](https://shepherd.dev/github/yiisoft/classifier)

Classifier traverses file system to find classes by a certain criteria.

Expand Down
15 changes: 15 additions & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"symbol-whitelist": [
"PhpToken",
"T_PAAMAYIM_NEKUDOTAYIM",
"T_NAMESPACE",
"T_STRING",
"T_CLASS",
"T_INTERFACE",
"T_TRAIT",
"T_ENUM",
"T_NS_SEPARATOR",
"T_NEW",
"T_WHITESPACE"
]
}
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"symfony/finder": "^5.4|^6.0|^7.1"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.2",
"phpbench/phpbench": "^1.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^1.0.0",
"roave/infection-static-analysis-plugin": "^1.16",
Expand All @@ -51,6 +52,9 @@
"Yiisoft\\Classifier\\Tests\\": "tests"
}
},
"suggest": {
"ext-tokenizer": "Need for TokenizerClassifier implementation"
},
"config": {
"sort-packages": true,
"allow-plugins": {
Expand Down
12 changes: 12 additions & 0 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "tests/Benchmark",
"runner.retry_threshold": 3,
"report.outputs": {
"csv_file": {
"extends": "delimited",
"delimiter": ",",
"file": "benchmarks.csv"
}
}
}
4 changes: 4 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
__DIR__ . '/tests',
]);

$rectorConfig->skip([
__DIR__ . '/tests/Support/wrong_file.php',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

Expand Down
93 changes: 93 additions & 0 deletions src/AbstractClassifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Classifier;

use ReflectionClass;
use Symfony\Component\Finder\Finder;
use Yiisoft\Classifier\Filter\FilterInterface;

/**
* Base implementation for {@see ClassifierInterface} with common filters.
*/
abstract class AbstractClassifier implements ClassifierInterface
{
/**
* @var array<class-string|trait-string, ReflectionClass>
*/
protected static array $reflectionsCache = [];

/**
* @var FilterInterface[]
*/
private array $filters = [];
/**
* @var string[]
*/
protected array $directories;

public function __construct(string $directory, string ...$directories)
{
$this->directories = [$directory, ...array_values($directories)];
}

public function withFilter(FilterInterface ...$filter): static
{
$new = clone $this;
array_push($new->filters, ...array_values($filter));

return $new;
}

/**
* @return iterable<class-string>
*/
public function find(): iterable
{
foreach ($this->getAvailableDeclarations() as $declaration) {
if ($this->skipDeclaration($declaration)) {
continue;
}
yield $declaration;
}
}

protected function getFiles(): Finder
{
return (new Finder())
->in($this->directories)
->name('*.php')
->sortByName()
->files();
}

/**
* @param class-string|trait-string $declaration
*/
private function skipDeclaration(string $declaration): bool
{
try {
$reflectionClass = self::$reflectionsCache[$declaration] ??= new ReflectionClass($declaration);
} catch (\Throwable) {
return true;
}

if ($reflectionClass->isInternal() || $reflectionClass->isAnonymous()) {
return true;
}

foreach ($this->filters as $filter) {
if (!$filter->match($reflectionClass)) {
return true;
}
}

return false;
}

/**
* @return iterable<class-string|trait-string>
*/
abstract protected function getAvailableDeclarations(): iterable;
}
Loading