Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add scanning using symbols #89

Merged
merged 30 commits into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
47821b2
Add Symbol and Dependency implementation
Jun 12, 2020
71daee8
Add NamespaceSymbol for PSR-0/4 autoload configurations
Jun 12, 2020
c4c34d1
Add symbol loader
Jun 12, 2020
c404254
Add symbol parsing
Jun 12, 2020
a1791cb
Reduce list of symbols down to one
Jun 12, 2020
49e6193
Fix issue with yield from already processed generator
Jun 23, 2020
2cc358f
Use SymbolList contains
Jul 3, 2020
975c946
Extract dependencies
Jul 29, 2020
c7fc8b7
Add experimental option
Jul 31, 2020
3fb0c0c
Add PackageDecorator
Jul 31, 2020
b75f151
Cleanup imports
Jul 31, 2020
e84455a
Further reduce the amount of symbols
Jul 31, 2020
8545e4f
Rename parser strategy method
Aug 1, 2020
7d5d3ac
Extract usage parsing into seperate use case
Aug 1, 2020
b77c1da
Extract loading required dependencies into use case
Aug 1, 2020
856fe42
Add event dispatcher
Aug 1, 2020
cbb98c5
Add test for used symbol collection use case
Aug 1, 2020
84dba4c
Ignore specific files from finder
Aug 10, 2020
d019bcd
Add a depedency collection to partition used from unused dependencies
Sep 15, 2020
daac163
Lint code
Sep 15, 2020
4d506ef
Add dependency collection logic
Sep 15, 2020
2470625
Linting
Sep 15, 2020
f39364e
Fix issue with non existing .gitignore
Sep 16, 2020
5d26cb6
Fix issue for projects without psr autoloading
Sep 16, 2020
40a460a
Lint
Sep 16, 2020
308f9ef
Solve implementation with reworked strategies
Sep 16, 2020
d131150
Fix issue with FileSymbolLoader not using classmap paths
Sep 18, 2020
b0facb7
Consolidate UsedSymbolLoader with FileSymbolLoader
Sep 23, 2020
35917f7
Reset symbol collector after yielding all symbols
Sep 30, 2020
39d6db5
Remove basedir from file provider
Sep 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .docker/php7.3/Dockerfile
@@ -1,4 +1,4 @@
FROM php:7.3-cli-buster
FROM php:7.3-cli

RUN apt-get update \
&& apt install -y \
Expand Down
2 changes: 1 addition & 1 deletion .docker/php7.4/Dockerfile
@@ -1,4 +1,4 @@
FROM php:7.4-cli-buster
FROM php:7.4-cli

RUN apt-get update \
&& apt install -y \
Expand Down
11 changes: 10 additions & 1 deletion Makefile
@@ -1,4 +1,4 @@
CONTAINER=composer-unused-7.3
CONTAINER=composer-unused-7.4

up:
docker-compose up -d
Expand All @@ -12,6 +12,12 @@ install:
update:
docker exec -it $(CONTAINER) composer update

require:
docker exec -it $(CONTAINER) composer require $(filter-out $@, $(MAKECMDGOALS))

remove:
docker exec -it $(CONTAINER) composer remove $(filter-out $@, $(MAKECMDGOALS))

check: csfix cs phpunit analyse

phpunit:
Expand All @@ -28,3 +34,6 @@ csfix:

ssh:
docker exec -it $(CONTAINER) /bin/bash

%:
@true
23 changes: 12 additions & 11 deletions composer.json
Expand Up @@ -23,18 +23,19 @@
"composer/composer": "^1.1 || ^2.0@dev",
"nikic/php-parser": "^4.2",
"psr/container": "^1.0",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.1",
"symfony/finder": "^4.2 || ^5.0"
},
"require-dev": {
"ext-ds": "*",
"ext-zend-opcache": "*",
"jangregor/phpstan-prophecy": "^0.6.2",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^0.12.14",
"phpunit/phpunit": "^9.0.1",
"phpspec/prophecy-phpunit": "^2.0.1",
"phpstan/phpstan": "^0.12.34",
"phpunit/phpunit": "^9.2.6",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.5.5"
},
"config": {
"preferred-install": "dist",
Expand All @@ -57,27 +58,27 @@
"Icanhazstring\\Composer\\Test\\Unused\\Unit\\": "tests/Unit"
}
},
"bin": [
"bin/composer-unused"
],
"scripts": {
"analyse": "phpstan analyse --no-progress",
"check": [
"@cs-check",
"@analyse",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"cs-check": "phpcs --parallel=50",
"cs-fix": "phpcbf --parallel=50",
"test": "phpunit"
},
"scripts-descriptions": {
"analyse": "Use \"phpstan\" to the analyse static code. See phpstan.neon",
"check": "Check the coding covention and run the tests",
"cs-check": "Use \"phpcs\" to check the coding convention. See phpcs.xml",
"cs-fix": "Use \"phpcbf\" to fix the coding convention. See phpcs.xml",
"test": "Use \"phpunit\" to run the tests. See phpunit.xml",
"check": "Check the coding covention and run the tests"
"test": "Use \"phpunit\" to run the tests. See phpunit.xml"
},
"bin": [
"bin/composer-unused"
],
"support": {
"issues": "https://github.com/composer-unused/composer-unused/issues",
"source": "https://github.com/composer-unused/composer-unused"
Expand Down
38 changes: 35 additions & 3 deletions config/service_manager.php
Expand Up @@ -4,8 +4,14 @@

use Icanhazstring\Composer\Unused\Command\Factory\UnusedCommandFactory;
use Icanhazstring\Composer\Unused\Command\UnusedCommand;
use Icanhazstring\Composer\Unused\Di\InvokableFactory;
use Icanhazstring\Composer\Unused\Error\ErrorHandlerInterface;
use Icanhazstring\Composer\Unused\Error\Factory\ErrorHandlerFactory;
use Icanhazstring\Composer\Unused\Event\Factory\EventDispatcherFactory;
use Icanhazstring\Composer\Unused\Event\Listener\Factory\RuntimeListenerProviderFactory;
use Icanhazstring\Composer\Unused\Event\Listener\RuntimeListenerProvider;
use Icanhazstring\Composer\Unused\Event\ListenerEventTypeResolver;
use Icanhazstring\Composer\Unused\File\FileContentProvider;
use Icanhazstring\Composer\Unused\Loader\Factory\LoaderBuilderFactory;
use Icanhazstring\Composer\Unused\Loader\Factory\PackageLoaderFactory;
use Icanhazstring\Composer\Unused\Loader\Factory\UsageLoaderFactory;
Expand All @@ -17,14 +23,25 @@
use Icanhazstring\Composer\Unused\Log\LogHandlerInterface;
use Icanhazstring\Composer\Unused\Parser\PHP\Factory\NodeVisitorFactory;
use Icanhazstring\Composer\Unused\Parser\PHP\Factory\PHPUsageParserFactory;
use Icanhazstring\Composer\Unused\Parser\PHP\NodeVisitor;
use Icanhazstring\Composer\Unused\Parser\PHP\ForeignSymbolCollector;
use Icanhazstring\Composer\Unused\Parser\PHP\NamespaceNodeVisitor;
use Icanhazstring\Composer\Unused\Parser\PHP\PHPUsageParser;
use Icanhazstring\Composer\Unused\Parser\PHP\UsedSymbolCollector;
use Icanhazstring\Composer\Unused\Subject\Factory\PackageSubjectFactory;
use Icanhazstring\Composer\Unused\Symbol\Loader\ExtensionSymbolLoader;
use Icanhazstring\Composer\Unused\Symbol\Loader\PsrSymbolLoader;
use Icanhazstring\Composer\Unused\Symbol\Provider\Factory\FileSymbolProviderFactory;
use Icanhazstring\Composer\Unused\Symbol\Provider\FileSymbolProvider;
use Icanhazstring\Composer\Unused\UseCase\CollectRequiredDependenciesUseCase;
use Icanhazstring\Composer\Unused\UseCase\CollectUsedSymbolsUseCase;
use Icanhazstring\Composer\Unused\UseCase\Factory\CollectRequiredDependenciesUseCaseFactory;
use Icanhazstring\Composer\Unused\UseCase\Factory\CollectUsedSymbolsUseCaseFactory;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;

return [
'factories' => [
NodeVisitor::class => NodeVisitorFactory::class,
NamespaceNodeVisitor::class => NodeVisitorFactory::class,
UsageLoader::class => UsageLoaderFactory::class,
PackageLoader::class => PackageLoaderFactory::class,
PackageSubjectFactory::class => static function () {
Expand All @@ -35,6 +52,21 @@
LoggerInterface::class => DebugLoggerFactory::class,
LogHandlerInterface::class => FileHandlerFactory::class,
LoaderBuilder::class => LoaderBuilderFactory::class,
PHPUsageParser::class => PHPUsageParserFactory::class
PHPUsageParser::class => PHPUsageParserFactory::class,

// 0.8 dependencies
ExtensionSymbolLoader::class => InvokableFactory::class,
PsrSymbolLoader::class => InvokableFactory::class,
FileSymbolProvider::class => FileSymbolProviderFactory::class,
FileContentProvider::class => InvokableFactory::class,
ForeignSymbolCollector::class => InvokableFactory::class,
UsedSymbolCollector::class => InvokableFactory::class,
CollectUsedSymbolsUseCase::class => CollectUsedSymbolsUseCaseFactory::class,
CollectRequiredDependenciesUseCase::class => CollectRequiredDependenciesUseCaseFactory::class,

ListenerEventTypeResolver::class => InvokableFactory::class,
RuntimeListenerProvider::class => RuntimeListenerProviderFactory::class,
EventDispatcherInterface::class => EventDispatcherFactory::class,

]
];
6 changes: 5 additions & 1 deletion src/Command/Factory/UnusedCommandFactory.php
Expand Up @@ -8,6 +8,8 @@
use Icanhazstring\Composer\Unused\Error\ErrorHandlerInterface;
use Icanhazstring\Composer\Unused\Loader\LoaderBuilder;
use Icanhazstring\Composer\Unused\Output\SymfonyStyleFactory;
use Icanhazstring\Composer\Unused\UseCase\CollectRequiredDependenciesUseCase;
use Icanhazstring\Composer\Unused\UseCase\CollectUsedSymbolsUseCase;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

Expand All @@ -19,7 +21,9 @@ public function __invoke(ContainerInterface $container): UnusedCommand
$container->get(ErrorHandlerInterface::class),
new SymfonyStyleFactory(),
$container->get(LoaderBuilder::class),
$container->get(LoggerInterface::class)
$container->get(LoggerInterface::class),
$container->get(CollectUsedSymbolsUseCase::class),
$container->get(CollectRequiredDependenciesUseCase::class)
);
}
}