Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
ssh_key: ${{ secrets.CLONE_SSH_KEY }}
ssh_key_pub: ${{ secrets.CLONE_SSH_KEY_PUB }}
- name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2023.3
uses: JetBrains/qodana-action@v2025.2
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
6 changes: 6 additions & 0 deletions .github/workflows/cs_sniff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ jobs:
- name: Run code style sniffer
run: vendor/bin/phpcs --standard=phpcs.xml Kununu/ tests/

- name: Run PHP CS Fixer
run: vendor/bin/php-cs-fixer check --using-cache=no --config php-cs-fixer.php

- name: Run PHPStan
run: vendor/bin/phpstan analyse

- name: Run Rector
run: vendor/bin/rector process --ansi --dry-run --config rector.php Kununu/ tests/
2 changes: 1 addition & 1 deletion Kununu/ArchitectureSniffer/ArchitectureSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testArchitecture(): iterable
$architecture,
static fn(array $group) => !array_filter(
is_array($group[Group::INCLUDES_KEY] ?? null) ? $group[Group::INCLUDES_KEY] : [],
static fn($include) => str_starts_with($include, 'App\\')
static fn($include) => str_starts_with((string) $include, 'App\\')
)
);

Expand Down
25 changes: 16 additions & 9 deletions Kununu/ArchitectureSniffer/Helper/RuleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

use Kununu\ArchitectureSniffer\Configuration\ArchitectureLibrary;
use Kununu\ArchitectureSniffer\Configuration\Group;
use Kununu\ArchitectureSniffer\Configuration\Rules;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustBeFinal;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustBeReadonly;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustExtend;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustImplement;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustNotDependOn;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustOnlyDependOn;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustOnlyHaveOnePublicMethod;
use Kununu\ArchitectureSniffer\Configuration\Rules\MustOnlyHaveOnePublicMethodNamed;
use PHPat\Test\Builder\Rule as PHPatRule;

final readonly class RuleBuilder
Expand All @@ -16,53 +23,53 @@
public static function getRules(Group $group, ArchitectureLibrary $library): iterable
{
if ($group->shouldExtend()) {
yield Rules\MustExtend::createRule(
yield MustExtend::createRule(
$group,
$library
);
}

if ($group->shouldImplement()) {
yield Rules\MustImplement::createRule(
yield MustImplement::createRule(
$group,
$library
);
}

if ($group->shouldBeFinal()) {
yield Rules\MustBeFinal::createRule(
yield MustBeFinal::createRule(
$group,
$library
);
}

if ($group->shouldBeReadonly()) {
yield Rules\MustBeReadonly::createRule(
yield MustBeReadonly::createRule(
$group,
$library
);
}

if ($group->shouldDependOn()) {
yield Rules\MustOnlyDependOn::createRule(
yield MustOnlyDependOn::createRule(
$group,
$library
);
}

if ($group->shouldNotDependOn()) {
yield Rules\MustNotDependOn::createRule(
yield MustNotDependOn::createRule(
$group,
$library
);
}

if ($group->shouldOnlyHaveOnePublicMethodNamed()) {
yield Rules\MustOnlyHaveOnePublicMethodNamed::createRule(
yield MustOnlyHaveOnePublicMethodNamed::createRule(
$group,
$library
);
yield Rules\MustOnlyHaveOnePublicMethod::createRule(
yield MustOnlyHaveOnePublicMethod::createRule(
$group,
$library
);
Expand Down
9 changes: 3 additions & 6 deletions Kununu/CsFixer/Command/CsFixerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@

final class CsFixerCommand extends BaseCommand
{
public const FAILURE = 1;
public const SUCCESS = 0;

private const ARGUMENT_FILES = 'files';
private const OPTION_CONFIG = 'config';
private const OPTION_EXTRA_ARGS = 'extra-args';
private const string ARGUMENT_FILES = 'files';
private const string OPTION_CONFIG = 'config';
private const string OPTION_EXTRA_ARGS = 'extra-args';

protected function configure(): void
{
Expand Down
6 changes: 3 additions & 3 deletions Kununu/Sniffs/Formatting/MethodSignatureArgumentsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected function getIndentationWhitespace(File $phpcsFile, int $prevIndex): st
*/
protected function getLineEndingPosition(array $tokens, int $position): int
{
while (!empty($tokens[$position]) && !str_contains($tokens[$position]['content'], PHP_EOL)) {
while (!empty($tokens[$position]) && !str_contains((string) $tokens[$position]['content'], PHP_EOL)) {
++$position;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ protected function getMethodSignatureMultilineLength(
// closing parenthesis
++$totalLength;
// column (:) and space before the returnType
$totalLength += mb_strlen($methodProperties['return_type']) + 2;
$totalLength += mb_strlen((string) $methodProperties['return_type']) + 2;

return $totalLength;
}
Expand All @@ -286,7 +286,7 @@ protected function getMethodSignatureMultilineLength(
protected function getParameterTotalLength(array $methodParameter): int
{
$length = 0;
$length += mb_strlen($methodParameter['content']);
$length += mb_strlen((string) $methodParameter['content']);

return $length;
}
Expand Down
2 changes: 1 addition & 1 deletion Kununu/Sniffs/PHP/NoNewLineBeforeDeclareStrictSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function process(File $phpcsFile, $stackPtr)
if ($declare !== false) {
$isEmptyLine = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, $declare);

if ($isEmptyLine !== false && str_contains($tokens[$isEmptyLine]['content'], "\n")) {
if ($isEmptyLine !== false && str_contains((string) $tokens[$isEmptyLine]['content'], "\n")) {
$error = 'Empty line before declare(strict_types=1) is not allowed';
$fix = $phpcsFile->addFixableError($error, $isEmptyLine, 'EmptyLineBeforeDeclare');

Expand Down
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,7 @@
class: PHPAT\PHPStan\PHPStanExtension
tags: [phpstan.extension]
```
- For more details and advanced configuration, see [Kununu/ArchitectureSniffer/README.md](Kununu/ArchitectureSniffer/README.md).

## Install

### Add custom private repositories to composer.json

```json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/kununu/code-tools.git",
"no-api": true
}
]
}
```
- For more details and advanced configuration, see [Kununu/ArchitectureSniffer/README.md](docs/ArchitectureSniffer/README.md).

### Require Library as a dev dependency

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"symfony/yaml": "^6.4"
},
"require-dev": {
"kununu/scripts": "^5.1",
"kununu/scripts": "^6.1",
"phpunit/phpunit": "^11.5"
},
"autoload": {
Expand Down Expand Up @@ -50,16 +50,18 @@
},
"scripts": {
"test-unit": "phpunit",
"cs-fixer-check": "php-cs-fixer check --config=php-cs-fixer.php Kununu/ tests/",
"cs-fixer-fix": "php-cs-fixer fix --config=php-cs-fixer.php Kununu/ tests/",
"cs-fixer-check": "php-cs-fixer check --config=php-cs-fixer.php",
"cs-fixer-fix": "php-cs-fixer fix --config=php-cs-fixer.php",
"cs-check": "phpcs --standard=phpcs.xml Kununu/ tests/",
"cs-fix": "phpcbf --standard=phpcs.xml Kununu/ tests/",
"stan": "phpstan analyze",
"rector": "rector process --dry-run Kununu/ tests/",
"rector": "rector process --dry-run Kununu/ tests/ -vvv",
"rector-fix": "rector process Kununu/ tests/",
"ci-checks": [
"@cs-fixer-check",
"@cs-check",
"@stan",
"@rector",
"@test-unit"
]
}
Expand Down
7 changes: 5 additions & 2 deletions php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
])
->setFinder(
Finder::create()
->exclude('vendor')
->exclude('var')
->exclude([
'vendor',
'var',
'_data',
])
->in(__DIR__)
);
2 changes: 1 addition & 1 deletion qodana.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: "1.0"
linter: jetbrains/qodana-php:2023.3
linter: jetbrains/qodana-php:2025.2
profile:
name: qodana.recommended
exclude:
Expand Down
8 changes: 5 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

use Rector\Config\RectorConfig;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withPhpSets(php83: true)
->withAttributesSets(phpunit: true)
->withComposerBased(phpunit: true)
->withSets([
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_110,
])
->withSkip([
WithConsecutiveRector::class,
AddOverrideAttributeToOverriddenMethodsRector::class,
__DIR__ . '/tests/bootstrap.php',
__DIR__ . '/rector.php',
])
->withImportNames();
4 changes: 2 additions & 2 deletions tests/SniffTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
class SniffTestCase extends TestCase
{
private const FILE_BEFORE = 'before/Fixme.php';
private const string FILE_BEFORE = 'before/Fixme.php';

private const FILE_AFTER = 'after/Fixme.php';
private const string FILE_AFTER = 'after/Fixme.php';

protected function assertSnifferFindsErrors(Sniff $sniffer, int $errorCount): array
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Kununu/CsFixer/Command/CsFixerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testCsFixerCommand(string $before, string $after): void
$application->add(new CsFixerCommand());

$command = $application->find('kununu:cs-fixer');
$tester = new CommandTester($command);
$tester = new CommandTester($command);

$exitCode = $tester->execute([
'files' => [$this->tempFile],
Expand All @@ -44,7 +44,7 @@ public static function fixerCasesProvider(): array

$cases = require $casesFile;

return array_map(fn ($case) => [$case['before'], $case['after']], $cases);
return array_map(fn($case) => [$case['before'], $case['after']], $cases);
}

private function contents(string $file): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testFailsWhenNotAGitRepo(): void
$app->add(new CsFixerGitHookCommand());

$command = $app->find('kununu:cs-fixer-git-hook');
$tester = new CommandTester($command);
$tester = new CommandTester($command);

chdir($this->repoDir);

Expand Down Expand Up @@ -54,7 +54,7 @@ public function testInstallsHookSuccessfully(): void
$app->add(new CsFixerGitHookCommand());

$command = $app->find('kununu:cs-fixer-git-hook');
$tester = new CommandTester($command);
$tester = new CommandTester($command);

$exitCode = $tester->execute([]);

Expand All @@ -67,7 +67,7 @@ public function testInstallsHookSuccessfully(): void
self::assertTrue(is_executable($hook), 'pre-commit should be executable');

$symlinkConfig = $gitPath . '/kununu/.php-cs-fixer.php';
$symlinkBin = $gitPath . '/kununu/php-cs-fixer';
$symlinkBin = $gitPath . '/kununu/php-cs-fixer';

self::assertTrue(is_link($symlinkConfig), '.php-cs-fixer.php symlink should exist');
self::assertTrue(is_link($symlinkBin), 'php-cs-fixer symlink should exist');
Expand Down