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

Ensure the whitelist feature works well on interfaces #205

Merged
merged 1 commit into from
May 13, 2018
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ e2e_013: bin/php-scoper.phar
diff src/scoper.inc.php.tpl build/set013/scoper.inc.php

.PHONY: e2e_014
e2e_014: ## Run end-to-end tests for the fixture set 014: source code case with psr-0
e2e_014: ## Run end-to-end tests for the fixture set 014: source code case with PSR-0
e2e_014: bin/php-scoper.phar
$(PHPNOGC) $(BOX) compile --working-dir fixtures/set014

php build/set014/bin/greet.phar > build/set014/output
diff fixtures/set014/expected-output build/set014/output

.PHONY: e2e_015
e2e_015: ## Run end-to-end tests for the fixture set 015: third-party code case with psr-0
e2e_015: ## Run end-to-end tests for the fixture set 015: third-party code case with PSR-0
e2e_015: bin/php-scoper.phar fixtures/set015/vendor
$(PHPNOGC) $(BOX) compile --working-dir fixtures/set015

Expand Down
9 changes: 0 additions & 9 deletions fixtures/set011/scoper.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@
* file that was distributed with this source code.
*/

use Isolated\Symfony\Component\Finder\Finder;

return [
'finders' => [
(new Finder())
->files()
->in(__DIR__)
->exclude('tests')
->notPath('scoper.inc.php')
],
'whitelist' => [
\Set011\Dictionary::class,
],
Expand Down
4 changes: 2 additions & 2 deletions fixtures/set011/src/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Set011;

abstract class Dictionary
interface Dictionary
{
/**
* @return string[]
*/
abstract public function provideWords(): array;
public function provideWords(): array;
}
2 changes: 1 addition & 1 deletion fixtures/set011/src/DirectionaryLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function ($filePath): bool {
function (array $dictionaries, string $className): array {
$class = new ReflectionClass($className);

if (false === $class->isAbstract() && $class->isSubclassOf(Dictionary::class)) {
if (false === $class->isAbstract() && $class->implementsInterface(Dictionary::class)) {
$dictionaries[] = $class->newInstanceWithoutConstructor();
}

Expand Down
2 changes: 1 addition & 1 deletion fixtures/set011/tests/SalutationDictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Set011;

final class SalutationDictionary extends Dictionary
final class SalutationDictionary implements Dictionary
{
/**
* @inheritdoc
Expand Down
30 changes: 20 additions & 10 deletions src/Autoload/ScoperAutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace Humbug\PhpScoper\Autoload;

use function array_map;

final class ScoperAutoloadGenerator
{
private $whitelist;
Expand All @@ -28,16 +30,7 @@ public function __construct(array $whitelist)

public function dump(string $prefix): string
{
$statements = array_map(
function (string $whitelist) use ($prefix): string {
return sprintf(
'class_exists(\'%s\%s\');',
$prefix,
$whitelist
);
},
$this->whitelist
);
$statements = $this->createStatements($prefix);

$statements = implode(PHP_EOL, $statements);

Expand All @@ -54,4 +47,21 @@ function (string $whitelist) use ($prefix): string {

PHP;
}

/**
* @return string[]
*/
public function createStatements(string $prefix): array
{
return array_map(
function (string $whitelistedElement) use ($prefix): string {
return sprintf(
'class_exists(\'%s\%s\');',
$prefix,
$whitelistedElement
);
},
$this->whitelist
);
}
}