Skip to content

Commit fdc7f74

Browse files
committed
apply phpcbf
1 parent 3a49301 commit fdc7f74

File tree

3 files changed

+60
-52
lines changed

3 files changed

+60
-52
lines changed

src/Rules/ResourceOperationMethodCallRule.php

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,47 @@
1010
use PHPStan\Rules\RuleErrorBuilder;
1111
use Sfp\ResourceOperations\ResourceOperations;
1212

13+
use function in_array;
14+
use function sprintf;
15+
use function strtolower;
16+
1317
/**
1418
* @implements Rule<Node\Expr\MethodCall>
1519
*/
1620
final class ResourceOperationMethodCallRule implements Rule
1721
{
18-
public function getNodeType(): string
19-
{
20-
return Node\Expr\MethodCall::class;
21-
}
22-
23-
public function processNode(Node $node, Scope $scope): array
24-
{
25-
if (! $node->name instanceof Node\Identifier) {
26-
// @codeCoverageIgnoreStart
27-
return []; // @codeCoverageIgnoreEnd
28-
}
29-
30-
if ($scope->getFunctionName() !== '__construct') {
31-
return [];
32-
}
33-
34-
$calledOnType = $scope->getType($node->var);
35-
36-
$methodNames = [];
37-
foreach ($calledOnType->getObjectClassNames() as $objectClassName) {
38-
$methodNames [] = $objectClassName . '::' .strtolower($node->name->name);
39-
}
40-
41-
$errors = [];
42-
foreach ($methodNames as $methodName) {
43-
if (in_array($methodName, ResourceOperations::getMethods(), true)) {
44-
$errors[] = RuleErrorBuilder::message(
45-
sprintf("Don't resource operation inside constructor. Method %s() is called.", $methodName)
46-
)->identifier('sfp-dont-operation.resourceOperationMethodCall')->build();
47-
}
48-
}
49-
50-
return $errors;
51-
}
22+
public function getNodeType(): string
23+
{
24+
return Node\Expr\MethodCall::class;
25+
}
26+
27+
public function processNode(Node $node, Scope $scope): array
28+
{
29+
if (! $node->name instanceof Node\Identifier) {
30+
// @codeCoverageIgnoreStart
31+
return []; // @codeCoverageIgnoreEnd
32+
}
33+
34+
if ($scope->getFunctionName() !== '__construct') {
35+
return [];
36+
}
37+
38+
$calledOnType = $scope->getType($node->var);
39+
40+
$methodNames = [];
41+
foreach ($calledOnType->getObjectClassNames() as $objectClassName) {
42+
$methodNames [] = $objectClassName . '::' . strtolower($node->name->name);
43+
}
44+
45+
$errors = [];
46+
foreach ($methodNames as $methodName) {
47+
if (in_array($methodName, ResourceOperations::getMethods(), true)) {
48+
$errors[] = RuleErrorBuilder::message(
49+
sprintf("Don't resource operation inside constructor. Method %s() is called.", $methodName)
50+
)->identifier('sfp-dont-operation.resourceOperationMethodCall')->build();
51+
}
52+
}
53+
54+
return $errors;
55+
}
5256
}
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace SfpTest\PHPStan\DontOperationInsideConstructor\Rules;
46

57
use PHPStan\Rules\Rule;
@@ -11,18 +13,18 @@
1113
*/
1214
class ResourceOperationMethodCallRuleTest extends RuleTestCase
1315
{
14-
public function getRule(): Rule
15-
{
16-
return new ResourceOperationMethodCallRule();
17-
}
16+
public function getRule(): Rule
17+
{
18+
return new ResourceOperationMethodCallRule();
19+
}
1820

19-
public function testProcess(): void
20-
{
21-
$this->analyse([__DIR__ . '/data/resourceOperationMethodCall.php'], [
22-
[
23-
"Don't resource operation inside constructor. Method SplFileInfo::openfile() is called.",
24-
8
25-
]
26-
]);
27-
}
21+
public function testProcess(): void
22+
{
23+
$this->analyse([__DIR__ . '/data/resourceOperationMethodCall.php'], [
24+
[
25+
"Don't resource operation inside constructor. Method SplFileInfo::openfile() is called.",
26+
8,
27+
],
28+
]);
29+
}
2830
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
class Test
46
{
5-
public function __construct()
6-
{
7-
$fileInfo = new SplFileInfo('test');
8-
$fileInfo->openFile('r');
9-
}
7+
public function __construct()
8+
{
9+
$fileInfo = new SplFileInfo('test');
10+
$fileInfo->openFile('r');
11+
}
1012
}

0 commit comments

Comments
 (0)