Skip to content

Commit 73d781d

Browse files
committed
Function file must be loaded manually to fucntion_exists to work
1 parent a64c9e3 commit 73d781d

File tree

13 files changed

+113
-34
lines changed

13 files changed

+113
-34
lines changed

.github/workflows/code_analysis.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ jobs:
3232
name: 'Tests'
3333
run: vendor/bin/phpunit
3434

35+
-
36+
name: 'Dependency Analysis'
37+
run: vendor/bin/composer-dependency-analyser
38+
3539
-
3640
name: 'Check Active Classes'
3741
run: vendor/bin/class-leak check src --ansi --skip-type="\Symplify\PhpConfigPrinter\Contract\Converter\ServiceOptionsKeyYamlToPhpFactoryInterface" --skip-type="\Symplify\PhpConfigPrinter\Contract\RoutingCaseConverterInterface" --skip-type="\Symplify\PhpConfigPrinter\Contract\CaseConverterInterface"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
composer.lock
33

44
.phpunit.cache
5+
6+
# symfony kernel cache dir
7+
/var

composer-dependency-analyser.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
6+
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;
7+
8+
// include ref() function
9+
// require __DIR__ . '/vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php';
10+
11+
$configuration = new Configuration();
12+
13+
// can be used conditionally, based on project context
14+
$configuration->ignoreErrorsOnPackage('myclabs/php-enum', [ErrorType::DEV_DEPENDENCY_IN_PROD]);
15+
16+
return $configuration;

composer.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44
"license": "MIT",
55
"require": {
66
"php": ">=8.2",
7-
"nette/utils": "^3.2",
8-
"nikic/php-parser": "^5.3",
9-
"symfony/yaml": "^6.4"
7+
"ext-ctype": "*",
8+
"nette/utils": "^4.0",
9+
"nikic/php-parser": "^5.5",
10+
"symfony/dependency-injection": "^6.4|^7.3",
11+
"symfony/service-contracts": "^3.6",
12+
"symfony/yaml": "^6.4",
13+
"webmozart/assert": "^1.11"
1014
},
1115
"require-dev": {
16+
"symfony/config": "^6.4|^7.3",
17+
"symfony/http-kernel": "^6.4|^7.3",
1218
"myclabs/php-enum": "^1.8",
19+
"phpecs/phpecs": "^2.1",
1320
"phpstan/extension-installer": "^1.4",
1421
"phpstan/phpstan": "^2.1",
15-
"phpunit/phpunit": "^10.5",
16-
"rector/rector": "^2.0",
17-
"phpecs/phpecs": "^2.0",
18-
"symplify/easy-testing": "^11.1",
22+
"phpunit/phpunit": "^11.5",
23+
"rector/rector": "^2.1",
24+
"shipmonk/composer-dependency-analyser": "^1.8",
1925
"symplify/phpstan-extensions": "^12.0",
2026
"tomasvotruba/class-leak": "^2.0"
2127
},

config/config.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
__DIR__ . '/../src/RoutingCaseConverter'
3838
)->tag(RoutingCaseConverterInterface::class);
3939

40-
4140
$services->load(
4241
'Symplify\\PhpConfigPrinter\\ServiceOptionConverter\\',
4342
__DIR__ . '/../src/ServiceOptionConverter'

ecs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
return ECSConfig::configure()
88
->withPaths([
9+
__DIR__ . '/config',
910
__DIR__ . '/src',
1011
__DIR__ . '/tests',
1112
])

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ parameters:
2222

2323
# unclear what to do
2424
- '#Parameter \#1 \$items of class PhpParser\\Node\\Expr\\Array_ constructor expects array<PhpParser\\Node\\ArrayItem>, array<PhpParser\\Node\\Arg> given#'
25+
26+
# runs also on older PHP versions, like 7.4+
27+
-
28+
message: '#Right side of && is always true#'
29+
path: src/NodeFactory/ArgsNodeFactory.php

rector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@
2424

2525
// old value is needed
2626
\Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector::class,
27-
2827
]);

src/Naming/ReferenceFunctionNameResolver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ final class ReferenceFunctionNameResolver
1717
*/
1818
public static function resolve(): string
1919
{
20+
$symfonyFunctionsFile = getcwd() . '/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php';
21+
22+
if (file_exists($symfonyFunctionsFile)) {
23+
// this file must be included manually, as composer will only load it once function called
24+
require_once $symfonyFunctionsFile;
25+
}
26+
2027
if (function_exists(FunctionName::REF)) {
2128
return FunctionName::REF;
2229
}

tests/AbstractTestCase.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PhpConfigPrinter\Tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symplify\PhpConfigPrinter\Tests\HttpKernel\TestKernel;
9+
10+
abstract class AbstractTestCase extends TestCase
11+
{
12+
private \Symfony\Component\DependencyInjection\ContainerInterface $container;
13+
14+
protected function setUp(): void
15+
{
16+
$kernel = new TestKernel('test', true);
17+
$kernel->boot();
18+
19+
$this->container = $kernel->getContainer();
20+
}
21+
22+
/**
23+
* @template TType as object
24+
*
25+
* @param class-string<TType> $type
26+
* @return TType
27+
*/
28+
public function getService(string $type): object
29+
{
30+
if (! $this->container->has($type)) {
31+
throw new \RuntimeException(sprintf('Service "%s" not found in container.', $type));
32+
}
33+
34+
return $this->container->get($type);
35+
}
36+
}

0 commit comments

Comments
 (0)