Skip to content
Open
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
40 changes: 40 additions & 0 deletions compare.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env php
<?php

// usage: vendor/bin/phpstan analyse -v -c compare.phpstan.neon --error-format=prettyJson tests/Rule/data/ForbidCustomFunctionsRule/code.php | php compare.php

$errors = json_decode(file_get_contents("php://stdin"), true);

function transformMessage(string $message): string
{
$replace = [
'Calling ' => 'Method ',
'is forbidden,' => 'is forbidden.',
];

return str_replace(array_keys($replace), array_values($replace), rtrim($message, '.'));
}

$iterator = new DirectoryIterator(__DIR__ . '/tests/Rule/data/ForbidCustomFunctionsRule');

foreach ($iterator as $fileinfo) {
if (!$fileinfo->isFile() || $fileinfo->getExtension() !== 'php') {
continue;
}
$filePath = $fileinfo->getPathname();

$contents = file_get_contents($filePath);
$contentsLines = explode("\n", $contents);

foreach ($contentsLines as $line => $row) {
$newLine = preg_replace('~ ?// error.*$~', '', $row);
$contentsLines[$line] = $newLine;
}

foreach ($errors['files'][$filePath]['messages'] ?? [] as $error) {
$line = $error['line'];
$contentsLines[$line - 1] .= ' // error: ' . transformMessage($error['message']);
}

file_put_contents($filePath, implode("\n", $contentsLines));
}
43 changes: 43 additions & 0 deletions compare.phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
includes:
- vendor/spaze/phpstan-disallowed-calls/extension.neon

parameters:
customRulesetUsed: true

# those are copied from ForbidCustomFunctionsRuleTest
disallowedFunctionCalls:
-
function: 'sleep'
message: 'Description 0'

-
method: 'ForbidCustomFunctionsRule\forbidden_namespaced_function'
message: 'Description 1'

disallowedMethodCalls:
-
method: 'ForbidCustomFunctionsRule\ClassWithForbiddenAllMethods::*'
message: 'Description 2'
-
method: 'ForbidCustomFunctionsRule\ClassWithForbiddenConstructor::__construct'
message: 'Description 3'
-
method: 'ForbidCustomFunctionsRule\SomeClass::forbiddenMethod'
message: 'Description 4'

-
method: 'ForbidCustomFunctionsRule\SomeInterface::forbiddenInterfaceMethod'
message: 'Description 6'

-
method: 'ForbidCustomFunctionsRule\SomeParent::forbiddenMethodOfParent'
message: 'Description 8'

disallowedStaticCalls:
-
method: 'ForbidCustomFunctionsRule\SomeClass::forbiddenStaticMethod'
message: 'Description 5'

-
method: 'ForbidCustomFunctionsRule\SomeInterface::forbiddenInterfaceStaticMethod'
message: 'Description 7'
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"shipmonk/composer-dependency-analyser": "^1.7.0",
"shipmonk/dead-code-detector": "^0.6.0",
"shipmonk/name-collision-detector": "^2.1.1",
"slevomat/coding-standard": "^8.15.0"
"slevomat/coding-standard": "^8.15.0",
"spaze/phpstan-disallowed-calls": "^4.0"
},
"autoload": {
"psr-4": {
Expand Down
73 changes: 70 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading