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
6 changes: 5 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
->setFinder($finder)
->setRiskyAllowed(true)
->setRules([
'@PER-CS' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
Expand Down Expand Up @@ -39,5 +40,8 @@
'list_syntax' => ['syntax' => 'short'],
'phpdoc_to_comment' => false,
'php_unit_method_casing' => ['case' => 'snake_case'],
'function_to_constant' => false
'function_to_constant' => false,
'php_unit_data_provider_static' => true ,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_array_type' => true
]);
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"ondram/ci-detector": "^4.1"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0",
"phpunit/phpunit": "^7.5|^9.0|^10.0",
"friendsofphp/php-cs-fixer": "^3.75",
"mikey179/vfsstream": "^1.6",
"phpspec/prophecy": "^1.10",
"friendsofphp/php-cs-fixer": "3.4.0",
"phpspec/prophecy-phpunit": "^2.3"
"phpspec/prophecy-phpunit": "^2.3",
"phpunit/phpunit": "^7.5|^9.0|^10.0",
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Analyzer/FileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FileParser implements Parser

private FileVisitor $fileVisitor;

/** @var ParsingError[] */
/** @var array<ParsingError> */
private array $parsingErrors;

public function __construct(
Expand All @@ -38,7 +38,7 @@ public function __construct(
}

/**
* @return ClassDescription[]
* @return array<ClassDescription>
*/
public function getClassDescriptions(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/FileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FileVisitor extends NodeVisitorAbstract
{
private ClassDescriptionBuilder $classDescriptionBuilder;

/** @var ClassDescription[] */
/** @var array<ClassDescription> */
private array $classDescriptions = [];

public function __construct(ClassDescriptionBuilder $classDescriptionBuilder)
Expand Down
1 change: 0 additions & 1 deletion src/Analyzer/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ protected function resolveAttrGroups(Node $node): void

/**
* @param Stmt\Use_::TYPE_* $type
* @param ?Name $prefix
*
* @psalm-suppress PossiblyNullArgument
*/
Expand Down
8 changes: 4 additions & 4 deletions src/CLI/Command/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$rulesFilename = $this->getConfigFilename($input);
if (!$onlyErrors) {
$output->writeln(sprintf("Config file: %s\n", $rulesFilename));
$output->writeln(\sprintf("Config file: %s\n", $rulesFilename));
}

$config = new Config();
Expand Down Expand Up @@ -267,9 +267,9 @@ private function printViolations(Violations $violations, OutputInterface $output
$output->writeln('<error>ERRORS!</error>');
}

$output->writeln(sprintf('%s', $violations->toString($format)));
$output->writeln(\sprintf('%s', $violations->toString($format)));
if (!$onlyErrors) {
$output->writeln(sprintf('<error>%s VIOLATIONS DETECTED!</error>', \count($violations)));
$output->writeln(\sprintf('<error>%s VIOLATIONS DETECTED!</error>', \count($violations)));
}
}

Expand All @@ -278,7 +278,7 @@ private function printParsedErrors(ParsingErrors $parsingErrors, OutputInterface
if (!$onlyErrors) {
$output->writeln('<error>ERROR ON PARSING THESE FILES:</error>');
}
$output->writeln(sprintf('%s', $parsingErrors->toString()));
$output->writeln(\sprintf('%s', $parsingErrors->toString()));
}

private function printNoViolationsDetectedMessage(OutputInterface $output, bool $onlyErrors = false, string $format = Printer::FORMAT_TEXT): void
Expand Down
17 changes: 8 additions & 9 deletions src/CLI/PhpArkitectApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

class PhpArkitectApplication extends \Symfony\Component\Console\Application
{
/** @var string */
private static $logo = <<< 'EOD'
____ _ _ ____ _ _ _ _ _
| _ \| | | | _ \ / \ _ __| | _(_) |_ ___ ___| |_
| |_) | |_| | |_) / _ \ | '__| |/ / | __/ _ \/ __| __|
| __/| _ | __/ ___ \| | | <| | || __/ (__| |_
|_| |_| |_|_| /_/ \_\_| |_|\_\_|\__\___|\___|\__|
EOD;
private static string $logo = <<< 'EOD'
____ _ _ ____ _ _ _ _ _
| _ \| | | | _ \ / \ _ __| | _(_) |_ ___ ___| |_
| |_) | |_| | |_) / _ \ | '__| |/ / | __/ _ \/ __| __|
| __/| _ | __/ ___ \| | | <| | || __/ (__| |_
|_| |_| |_|_| /_/ \_\_| |_|\_\_|\__\___|\___|\__|
EOD;

public function __construct()
{
Expand All @@ -29,6 +28,6 @@ public function __construct()

public function getLongVersion(): string
{
return sprintf("%s\n\n<info>%s</info> version <comment>%s</comment>", self::$logo, $this->getName(), $this->getVersion());
return \sprintf("%s\n\n<info>%s</info> version <comment>%s</comment>", self::$logo, $this->getName(), $this->getVersion());
}
}
4 changes: 2 additions & 2 deletions src/CLI/Printer/GitlabPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function print(array $violationsCollection): string
$allErrors = [];

/**
* @var string $key
* @var Violation[] $violationsByFqcn
* @var string $key
* @var array<Violation> $violationsByFqcn
*/
foreach ($violationsCollection as $class => $violationsByFqcn) {
foreach ($violationsByFqcn as $violation) {
Expand Down
4 changes: 2 additions & 2 deletions src/CLI/Printer/JsonPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function print(array $violationsCollection): string
$details = [];

/**
* @var string $key
* @var Violation[] $violationsByFqcn
* @var string $key
* @var array<Violation> $violationsByFqcn
*/
foreach ($violationsCollection as $class => $violationsByFqcn) {
$violationForThisFqcn = \count($violationsByFqcn);
Expand Down
4 changes: 2 additions & 2 deletions src/CLI/Printer/TextPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function print(array $violationsCollection): string
$errors = '';

/**
* @var string $key
* @var Violation[] $violationsByFqcn
* @var string $key
* @var array<Violation> $violationsByFqcn
*/
foreach ($violationsCollection as $key => $violationsByFqcn) {
$violationForThisFqcn = \count($violationsByFqcn);
Expand Down
2 changes: 1 addition & 1 deletion src/ClassSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class ClassSet implements \IteratorAggregate
{
/** @var string[] */
/** @var array<string> */
private array $directoryList;

private array $exclude;
Expand Down
2 changes: 1 addition & 1 deletion src/ClassSetRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ClassSetRules
{
private ClassSet $classSet;

/** @var ArchRule[] */
/** @var array<ArchRule> */
private array $rules;

private function __construct(ClassSet $classSet, ArchRule ...$rules)
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/IndexNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class IndexNotFoundException extends \Exception
{
public function __construct(int $index)
{
parent::__construct(sprintf('Index not found %d', $index));
parent::__construct(\sprintf('Index not found %d', $index));
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/PhpVersionNotValidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class PhpVersionNotValidException extends \Exception
{
public function __construct(string $phpVersion)
{
parent::__construct(sprintf('PHP version not valid for PHPArkitect parser %s', $phpVersion));
parent::__construct(\sprintf('PHP version not valid for PHPArkitect parser %s', $phpVersion));
}
}
2 changes: 1 addition & 1 deletion src/Expression/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function describe(ClassDescription $theClass, string $because): Descripti
*
* Not included directly in the interface to allow incremental implementation of it in the rules.
*/
//public function appliesTo(ClassDescription $theClass): bool;
// public function appliesTo(ClassDescription $theClass): bool;

/**
* Evaluates the expression for the class passed as parameter.
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/DependsOnlyOnTheseNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class DependsOnlyOnTheseNamespaces implements Expression
{
/** @var string[] */
/** @var array<string> */
private array $namespaces;

public function __construct(string ...$namespace)
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/Extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Extend implements Expression
{
/** @var string[] */
/** @var array<string> */
private array $classNames;

public function __construct(string ...$classNames)
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/NotDependsOnTheseNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class NotDependsOnTheseNamespaces implements Expression
{
/** @var string[] */
/** @var array<string> */
private array $namespaces;

public function __construct(string ...$namespace)
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/NotExtend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class NotExtend implements Expression
{
/** @var string[] */
/** @var array<string> */
private array $classNames;

public function __construct(string ...$classNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NotHaveDependencyOutsideNamespace implements Expression
{
private string $namespace;

/** @var string[] */
/** @var array<string> */
private array $externalDependenciesToExclude;

private bool $excludeCoreNamespace;
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/NotResideInTheseNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class NotResideInTheseNamespaces implements Expression
{
/** @var string[] */
/** @var array<string> */
private $namespaces;

public function __construct(string ...$namespaces)
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/ResideInOneOfTheseNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class ResideInOneOfTheseNamespaces implements Expression
{
/** @var string[] */
/** @var array<string> */
private $namespaces;

public function __construct(string ...$namespaces)
Expand Down
4 changes: 2 additions & 2 deletions src/RuleBuilders/Architecture/Architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Architecture implements Component, DefinedBy, Where, MayDependOnComponents
private $componentName;
/** @var array<string, string> */
private $componentSelectors;
/** @var array<string, string[]> */
/** @var array<string, array<string>> */
private $allowedDependencies;
/** @var array<string, string[]> */
/** @var array<string, array<string>> */
private $componentDependsOnlyOnTheseNamespaces;

private function __construct()
Expand Down
2 changes: 1 addition & 1 deletion src/RuleBuilders/Architecture/MayDependOnComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface MayDependOnComponents
/**
* May depend on the specified components, plus itself.
*
* @param string[] $componentNames
* @param array<string> $componentNames
*
* @return Where&Rules
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ShouldOnlyDependOnComponents
/**
* May depend ONLY on the specified components, thus it can only depend on itself if itself is specified.
*
* @param string[] $componentNames
* @param array<string> $componentNames
*
* @return Where&Rules
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/ParsingErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ParsingErrors implements \IteratorAggregate, \Countable
{
/**
* @var ParsingError[]
* @var array<ParsingError>
*/
private $parsingErrors;

Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Violations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class Violations implements \IteratorAggregate, \Countable, \JsonSerializable
{
/**
* @var Violation[]
* @var array<Violation>
*/
private array $violations;

Expand Down
24 changes: 12 additions & 12 deletions tests/E2E/Cli/CheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function test_json_format_output(): void

$display = $cmdTester->getDisplay();

$this->assertJson($display);
self::assertJson($display);
}

public function test_json_format_output_no_errors(): void
Expand All @@ -189,10 +189,10 @@ public function test_json_format_output_no_errors(): void

$display = $cmdTester->getDisplay();

$this->assertJson($display);
self::assertJson($display);

$json = json_decode($display, true);
$this->assertCount(0, $json);
self::assertCount(0, $json);
}

public function test_gitlab_format_output(): void
Expand All @@ -205,7 +205,7 @@ public function test_gitlab_format_output(): void

$display = $cmdTester->getDisplay();

$this->assertJson($display);
self::assertJson($display);

self::assertSame(<<<JSON
[{"description":"should have a name that matches *Controller because all controllers should be end name with Controller","check_name":"App\\\\Controller\\\\Foo.should-have-a-name-that-matches-controller-because-all-controllers-should-be-end-name-with-controller","fingerprint":"1e960c3f49b5ec63ece40321072ef2bd0bc33ad11b7be326f304255d277dc860","severity":"major","location":{"path":"Controller\/Foo.php","lines":{"begin":1}}}]
Expand All @@ -223,10 +223,10 @@ public function test_gitlab_format_output_no_errors(): void

$display = $cmdTester->getDisplay();

$this->assertJson($display);
self::assertJson($display);

$json = json_decode($display, true);
$this->assertCount(0, $json);
self::assertCount(0, $json);
}

protected function runCheck(
Expand Down Expand Up @@ -274,27 +274,27 @@ protected function runCheck(

protected function assertCheckHasErrors(ApplicationTester $applicationTester, ?string $expectedOutput = null): void
{
$this->assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode());
self::assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode());
if (null != $expectedOutput) {
$actualOutput = str_replace(["\r", "\n"], '', $applicationTester->getDisplay());
$expectedOutput = str_replace(["\r", "\n"], '', $expectedOutput);
$this->assertStringContainsString($expectedOutput, $actualOutput);
self::assertStringContainsString($expectedOutput, $actualOutput);
}
}

protected function assertCheckHasNoErrorsLike(ApplicationTester $applicationTester, ?string $expectedOutput = null): void
{
$this->assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode());
self::assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode());
if (null != $expectedOutput) {
$actualOutput = str_replace(["\r", "\n"], '', $applicationTester->getDisplay());
$expectedOutput = str_replace(["\r", "\n"], '', $expectedOutput);
$this->assertStringNotContainsString($expectedOutput, $actualOutput);
self::assertStringNotContainsString($expectedOutput, $actualOutput);
}
}

protected function assertCheckHasSuccess(ApplicationTester $applicationTester): void
{
$this->assertEquals(self::SUCCESS_CODE, $applicationTester->getStatusCode(), 'Command failed: '.$applicationTester->getDisplay());
$this->assertStringNotContainsString('ERRORS!', $applicationTester->getDisplay(), 'Error message not expected in successful execution');
self::assertEquals(self::SUCCESS_CODE, $applicationTester->getStatusCode(), 'Command failed: '.$applicationTester->getDisplay());
self::assertStringNotContainsString('ERRORS!', $applicationTester->getDisplay(), 'Error message not expected in successful execution');
}
}
Loading