Skip to content

Commit 7ece628

Browse files
committed
Add support for symfony Controllers, test get private service.
1 parent 2d46724 commit 7ece628

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Lookyman\PHPStan\Symfony\Rules;
6+
7+
use Lookyman\PHPStan\Symfony\ServiceMap;
8+
use PHPStan\Rules\Rule;
9+
10+
final class ContainerInterfacePrivateServiceRuleTest extends \PHPStan\Testing\RuleTestCase
11+
{
12+
13+
protected function getRule(): Rule
14+
{
15+
$serviceMap = new ServiceMap(__DIR__ . '/../container.xml');
16+
17+
return new ContainerInterfacePrivateServiceRule($serviceMap);
18+
}
19+
20+
public function testGetPrivateService()
21+
{
22+
$this->analyse([__DIR__ . '/data/ExampleController.php'], [
23+
[
24+
'Service "private" is private.',
25+
14,
26+
],
27+
]);
28+
}
29+
30+
}

tests/Rules/data/Controller.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace Symfony\Bundle\FrameworkBundle\Controller;
6+
7+
abstract class Controller
8+
{
9+
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Lookyman\PHPStan\Symfony\Rules\data;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
7+
include __DIR__ . '/Controller.php';
8+
9+
class ExampleController extends Controller
10+
{
11+
12+
public function getPrivateServiceAction()
13+
{
14+
$service = $this->get('private');
15+
$service->noMethod();
16+
}
17+
}

0 commit comments

Comments
 (0)