Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/php-version
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Jun 16, 2024
2 parents 31f40bb + fbbcac0 commit 41c7be3
Show file tree
Hide file tree
Showing 31 changed files with 700 additions and 242 deletions.
14 changes: 0 additions & 14 deletions docs/limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
- [Composer Autoloader](#composer-autoloader)
- [Composer Plugins](#composer-plugins)
- [PSR-0 Partial support](#psr-0-partial-support)
- [Files autoloading](#files-autoloading)
- [Exposing/Excluding traits](#exposingexcluding-traits)
- [Exposing/Excluding enums](#exposingexcluding-enums)
- [Declaring a custom namespaced function `function_exists()`](#declaring-a-custom-namespaced-function-function_exists)
Expand Down Expand Up @@ -238,19 +237,6 @@ transforming it to PSR-4, i.e. in the case above:
If this works for the classes under `src/JsonMapper/`, it will not for `JsonMapper.php`.


### Files autoloading

Currently, scoping autoloaded files, i.e. files registered to Composer via the
[`autoload.files`][autoload-files] setting only half work. Indeed, the scoping
itself works, but if your scoped code happen to try to load another Composer
based project with the same file, it will not. The problem identified is that
the Composer autoloader uses hash to know if a file has been loaded or not already.
Unfortunately, this hash is defined by the package and file name, which means
the scoped file and non-scoped file will have the same hash resulting in errors.

This is a limitation that should be fixable, check [#298] for the progress.


### Exposing/Excluding traits

There is currently no way to expose or exclude a trait. Since there is no
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ parameters:
path: 'src/PhpParser/NodeVisitor/Resolver/OriginalNameResolver.php'
- message: '#NamespaceManipulator::getOriginalName\(\) should return#'
path: 'src/PhpParser/NodeVisitor/NamespaceStmt/NamespaceManipulator.php'
- message: '#DummyScoperFactory extends @final#'
path: 'tests/Console/Command/DummyScoperFactory.php'
- message: '#Anonymous function should return string but returns array#'
path: 'tests/Console/Command/AddPrefixCommandIntegrationTest.php'
- message: '#AddPrefixCommandIntegrationTest\:\:getNormalizeDisplay\(\) should return string but returns array#'
Expand Down Expand Up @@ -63,3 +61,5 @@ parameters:
# Fixed in https://github.com/nikic/PHP-Parser/pull/1003
- message: '#Standard constructor expects array#'
path: 'src/Container.php'
- message: '#Standard constructor expects array#'
path: 'src/PhpParser/Printer/StandardPrinterFactory.php'
21 changes: 7 additions & 14 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

namespace Humbug\PhpScoper\Configuration;

use Humbug\PhpScoper\Configuration\Throwable\InvalidConfigurationValue;
use Humbug\PhpScoper\Patcher\Patcher;
use InvalidArgumentException;
use PhpParser\PhpVersion;
use function Safe\preg_match;
use function sprintf;

final class Configuration
{
Expand All @@ -39,6 +38,8 @@ final class Configuration
* @param array<string, array{string, string}> $excludedFilesWithContents Array of tuple
* with the first argument being the file path and
* the second its contents
*
* @throws InvalidConfigurationValue
*/
public function __construct(
private ?string $path,
Expand Down Expand Up @@ -73,6 +74,8 @@ public function getOutputDir(): ?string

/**
* @param non-empty-string $prefix
*
* @throws InvalidConfigurationValue
*/
public function withPrefix(string $prefix): self
{
Expand Down Expand Up @@ -161,21 +164,11 @@ public function getPhpVersion(): ?PhpVersion
private static function validatePrefix(string $prefix): void
{
if (1 !== preg_match(self::PREFIX_PATTERN, $prefix)) {
throw new InvalidArgumentException(
sprintf(
'The prefix needs to be composed solely of letters, digits and backslashes (as namespace separators). Got "%s"',
$prefix,
),
);
throw InvalidConfigurationValue::forInvalidPrefixPattern($prefix);
}

if (preg_match('/\\\{2,}/', $prefix)) {
throw new InvalidArgumentException(
sprintf(
'Invalid namespace separator sequence. Got "%s"',
$prefix,
),
);
throw InvalidConfigurationValue::forInvalidNamespaceSeparator($prefix);
}
}
}
Loading

0 comments on commit 41c7be3

Please sign in to comment.