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

suggest php as dependency if extension is one of the core-extensions #103

Merged
merged 5 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [unreleased]
### Added
- add symbol counts to check command for verbose output
- suggest `php` as extension if it's a core extension

### Changed

Expand Down
Empty file modified bin/composer-require-checker
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"mikey179/vfsStream": "^1.6",
"mikey179/vfsstream": "^1.6",
"phpstan/phpstan": "^0.10.3"
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion src/ComposerRequireChecker/Cli/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("The following unknown symbols were found:");
$table = new Table($output);
$table->setHeaders(['unknown symbol', 'guessed dependency']);
$guesser = new DependencyGuesser();
$guesser = new DependencyGuesser($options);
foreach ($unknownSymbols as $unknownSymbol) {
$guessedDependencies = [];
foreach ($guesser($unknownSymbol) as $guessedDependency) {
Expand Down
2 changes: 1 addition & 1 deletion src/ComposerRequireChecker/Cli/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getSymbolWhitelist(): array
}

/**
* @return array
* @return string[]
*/
public function getPhpCoreExtensions(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ComposerRequireChecker\DependencyGuesser;

use ComposerRequireChecker\Cli\Options;

class DependencyGuesser
{

Expand All @@ -10,9 +12,9 @@ class DependencyGuesser
*/
private $guessers = [];

public function __construct()
public function __construct(?Options $options = null)
{
$this->guessers[] = new GuessFromLoadedExtensions();
$this->guessers[] = new GuessFromLoadedExtensions($options);
}

public function __invoke($symbolName): \Generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@

namespace ComposerRequireChecker\DependencyGuesser;

use ComposerRequireChecker\Cli\Options;
use ComposerRequireChecker\DefinedSymbolsLocator\LocateDefinedSymbolsFromExtensions;

class GuessFromLoadedExtensions implements GuesserInterface
{
private $loadedExtensions;

public function __construct()
/**
* @var string[]|null
*/
private $coreExtensions;

public function __construct(?Options $options = null)
{
$this->loadedExtensions = get_loaded_extensions();
if ($options instanceof Options) {
$this->coreExtensions = $options->getPhpCoreExtensions();
}
}

public function __invoke(string $symbolName): \Generator
Expand All @@ -19,6 +28,10 @@ public function __invoke(string $symbolName): \Generator
foreach ($this->loadedExtensions as $extensionName) {
$extensionSymbols = $definedSymbolsFromExtensions([$extensionName]);
if (in_array($symbolName, $extensionSymbols)) {
if ($this->coreExtensions && in_array($extensionName, $this->coreExtensions)) {
yield 'php';
}

yield 'ext-' . $extensionName;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ComposerRequireCheckerTest\DependencyGuesser;

use ComposerRequireChecker\Cli\Options;
use ComposerRequireChecker\DependencyGuesser\DependencyGuesser;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -33,4 +34,13 @@ public function testDoesNotSuggestAnything()
$result = $this->guesser->__invoke('an_hopefully_unique_unknown_symbol');
$this->assertFalse($result->valid());
}

public function testCoreExtensionsResolvesToPHP()
{
$options = new Options(['php-core-extensions' => ['SPL', 'something-else']]);
$this->guesser = new DependencyGuesser($options);
$result = $this->guesser->__invoke('RecursiveDirectoryIterator');
$this->assertNotEmpty($result);
$this->assertContains('php', $result);
}
}