Skip to content

Commit

Permalink
fix(ci): use sprintf native function
Browse files Browse the repository at this point in the history
  • Loading branch information
brociani committed Aug 1, 2024
1 parent 65a5752 commit bac985a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.3', '7.4', '8.0' ]
php: [ '7.3', '7.4', '8.0', '8.1' ]
steps:
- uses: actions/checkout@v2
- name: Setup PHP with tools
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'constant_case' => true,
'lowercase_keywords' => true,
'class_attributes_separation' => ['elements' => ['method' => 'one']],
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'native_function_invocation' => ['include' => ['@compiler_optimized', 'sprintf']],
'no_alias_functions' => true,
'no_closing_tag' => true,
'no_extra_blank_lines' => [
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ CHANGELOG

master
------
* Add support of PHP 8.1
* force usage of native sprintf function
* add php cs fixer rule native_function_invocation on sprintf

v1.1.0
------
* Added rule to ban shell execution via backticks
* Added rule to ban print statements
* Allow Composer plugin ergebnis/composer-normalize
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"homepage": "https://github.com/ekino/phpstan-banned-code",
"require": {
"php": "^7.3 || ^8.0",
"php": "^7.3 || ^8.0 || ^8.1",
"phpstan/phpstan": "^1.0"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/BannedNodesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ public function processNode(Node $node, Scope $scope): array
$function = $node->name->toString();

if (\in_array($function, $this->bannedFunctions)) {
return [sprintf('Should not use function "%s", please change the code.', $function)];
return [\sprintf('Should not use function "%s", please change the code.', $function)];
}

return [];
}

return [sprintf('Should not use node with type "%s", please change the code.', $type)];
return [\sprintf('Should not use node with type "%s", please change the code.', $type)];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/BannedUseTestRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public function processNode(Node $node, Scope $scope): array
}

if (!$node instanceof Use_) {
throw new \InvalidArgumentException(sprintf('$node must be an instance of %s, %s given', Use_::class, \get_class($node)));
throw new \InvalidArgumentException(\sprintf('$node must be an instance of %s, %s given', Use_::class, \get_class($node)));
}

$errors = [];

foreach ($node->uses as $use) {
if (preg_match('#^Tests#', $use->name->toString())) {
$errors[] = sprintf('Should not use %s in the non-test file %s', $use->name->toString(), $scope->getFile());
$errors[] = \sprintf('Should not use %s in the non-test file %s', $use->name->toString(), $scope->getFile());
}
}

Expand Down

0 comments on commit bac985a

Please sign in to comment.