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/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: PHP_CS_FIXER_IGNORE_ENV=1 ./bin/php-cs-fixer fix --dry-run -v

- name: Static Analysis
run: ./bin/psalm
run: ./bin/psalm.phar

- name: Test
run: ./bin/phpunit -d memory_limit=-1 --coverage-clover clover.xml
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
/web
/bin/
!/bin/box.phar
!/bin/psalm.phar
phparkitect.phar
composer.lock
.php-version
composer.phar
.phpunit.cache/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ csfix: ## it launches cs fix
bin/php-cs-fixer fix -v

psalm: ## it launches psalm
bin/psalm
bin/psalm.phar

build: ## it launches all the build
composer install
Expand Down
Binary file added bin/psalm.phar
Binary file not shown.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"require-dev": {
"roave/security-advisories": "dev-master",
"symfony/var-dumper": "^3.0|^4.0|^5.0|^6.0|^7.0",
"vimeo/psalm": "^4.6",
"phpunit/phpunit": "^7.5|^9.0|^10.0",
"mikey179/vfsstream": "^1.6",
"phpspec/prophecy": "^1.10",
Expand All @@ -55,7 +54,8 @@
}
},
"config": {
"bin-dir": "bin"
"bin-dir": "bin",
"sort-packages": true
},
"bin": [
"bin-stub/phparkitect"
Expand Down
20 changes: 13 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutCoversAnnotation="true"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="false"
beStrictAboutCoversAnnotation="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="false"
failOnWarning="true"
verbose="true">

<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
3 changes: 2 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

findUnusedCode="false"
findUnusedBaselineEntry="false"
allowStringToStandInForClass="true"
>
<projectFiles>
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/ClassDescription.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Arkitect\Analyzer;
Expand Down Expand Up @@ -46,6 +47,7 @@ class ClassDescription
* @param list<FullyQualifiedClassName> $interfaces
* @param ?FullyQualifiedClassName $extends
* @param list<FullyQualifiedClassName> $attributes
* @param list<string> $docBlock
*/
public function __construct(
FullyQualifiedClassName $FQCN,
Expand Down
24 changes: 15 additions & 9 deletions src/Analyzer/FileVisitor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Arkitect\Analyzer;
Expand Down Expand Up @@ -30,7 +31,7 @@ public function enterNode(Node $node): void

foreach ($node->implements as $interface) {
$this->classDescriptionBuilder
->addInterface($interface->toString(), $interface->getLine());
->addInterface($interface->toString(), $interface->getLine());
}

if (!$node->isAnonymous() && null !== $node->extends) {
Expand Down Expand Up @@ -76,7 +77,8 @@ public function enterNode(Node $node): void
*
* @see FileVisitorTest::test_it_should_return_errors_for_const_outside_namespace
*/
if ($node instanceof Node\Expr\ClassConstFetch
if (
$node instanceof Node\Expr\ClassConstFetch
&& method_exists($node->class, 'toString')
) {
if ($this->isSelfOrStaticOrParent($node->class->toString())) {
Expand All @@ -93,7 +95,8 @@ public function enterNode(Node $node): void
*
* @see FileVisitorTest::test_should_returns_all_dependencies
*/
if ($node instanceof Node\Expr\StaticCall
if (
$node instanceof Node\Expr\StaticCall
&& method_exists($node->class, 'toString')
) {
if ($this->isSelfOrStaticOrParent($node->class->toString())) {
Expand All @@ -104,7 +107,8 @@ public function enterNode(Node $node): void
->addDependency(new ClassDependency($node->class->toString(), $node->getLine()));
}

if ($node instanceof Node\Expr\Instanceof_
if (
$node instanceof Node\Expr\Instanceof_
&& method_exists($node->class, 'toString')
) {
if ($this->isSelfOrStaticOrParent($node->class->toString())) {
Expand All @@ -114,11 +118,13 @@ public function enterNode(Node $node): void
->addDependency(new ClassDependency($node->class->toString(), $node->getLine()));
}

if ($node instanceof Node\Expr\New_
if (
$node instanceof Node\Expr\New_
&& !($node->class instanceof Node\Expr\Variable)
) {
if ((method_exists($node->class, 'isAnonymous') && $node->class->isAnonymous())
|| !method_exists($node->class, 'toString')) {
if ((method_exists($node->class, 'isAnonymous') && true === $node->class->isAnonymous())
|| !method_exists($node->class, 'toString')
) {
return;
}

Expand Down Expand Up @@ -215,7 +221,7 @@ public function enterNode(Node $node): void
$returnType = $node->returnType;
if ($returnType instanceof Node\Name\FullyQualified) {
$this->classDescriptionBuilder
->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine()));
->addDependency(new ClassDependency($returnType->toString(), $returnType->getLine()));
}
}
}
Expand Down Expand Up @@ -271,7 +277,7 @@ private function addParamDependency(Node\Param $node): void
$type = $nullableType->type;
}

if (method_exists($type, 'isSpecialClassName') && $type->isSpecialClassName()) {
if (method_exists($type, 'isSpecialClassName') && true === $type->isSpecialClassName()) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/CLI/Command/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$startTime = microtime(true);

try {
$verbose = $input->getOption('verbose');
$stopOnFailure = $input->getOption(self::STOP_ON_FAILURE_PARAM);
$useBaseline = $input->getOption(self::USE_BASELINE_PARAM);
$skipBaseline = $input->getOption(self::SKIP_BASELINE_PARAM);
$ignoreBaselineLinenumbers = $input->getOption(self::IGNORE_BASELINE_LINENUMBERS_PARAM);
$verbose = (bool) $input->getOption('verbose');
$stopOnFailure = (bool) $input->getOption(self::STOP_ON_FAILURE_PARAM);
$useBaseline = (string) $input->getOption(self::USE_BASELINE_PARAM);
$skipBaseline = (bool) $input->getOption(self::SKIP_BASELINE_PARAM);
$ignoreBaselineLinenumbers = (bool) $input->getOption(self::IGNORE_BASELINE_LINENUMBERS_PARAM);

if (true !== $skipBaseline && !$useBaseline && file_exists(self::DEFAULT_BASELINE_FILENAME)) {
$useBaseline = self::DEFAULT_BASELINE_FILENAME;
Expand Down
4 changes: 4 additions & 0 deletions src/ClassSet.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

declare(strict_types=1);

namespace Arkitect;

use Symfony\Component\Finder\Finder;

/**
* @template-implements \IteratorAggregate<string, \Symfony\Component\Finder\SplFileInfo>
*/
class ClassSet implements \IteratorAggregate
{
/** @var string */
Expand Down
15 changes: 12 additions & 3 deletions src/PHPUnit/ArchRuleCheckerConstraintAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Arkitect\PHPUnit;
Expand All @@ -10,11 +11,17 @@
use Arkitect\CLI\Progress\VoidProgress;
use Arkitect\CLI\Runner;
use Arkitect\CLI\TargetPhpVersion;
use Arkitect\Rules\ArchRule;
use Arkitect\Rules\ParsingErrors;
use Arkitect\Rules\Violations;
use PHPUnit\Framework\Constraint\Constraint;

/**
* @psalm-suppress UndefinedClass
*
* Since we declared phpunit as a dev dependency we cannot be sure the class PHPUnit\Framework\Constraint\Constraint
* will be available at runtime. Given arkitect will be used in a development environment, we can ignore this but it
* would be nice to have a way to check if the class is available at runtime.
*/
class ArchRuleCheckerConstraintAdapter extends Constraint
{
/** @var ClassSet */
Expand Down Expand Up @@ -47,8 +54,10 @@ public function toString(): string
return 'satisfies all architectural constraints';
}

protected function matches(/** @var $rule ArchRule */ $other): bool
{
protected function matches(
/** @var $rule ArchRule */
$other
): bool {
$this->runner->check(
ClassSetRules::create($this->classSet, $other),
new VoidProgress(),
Expand Down
4 changes: 4 additions & 0 deletions src/Rules/ParsingErrors.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

declare(strict_types=1);

namespace Arkitect\Rules;

use Arkitect\Exceptions\IndexNotFoundException;

/**
* @template-implements \IteratorAggregate<ParsingError>
*/
class ParsingErrors implements \IteratorAggregate, \Countable
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Rules/Violations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
use Arkitect\Exceptions\FailOnFirstViolationException;
use Arkitect\Exceptions\IndexNotFoundException;

/**
* @template-implements \IteratorAggregate<Violation>
*/
class Violations implements \IteratorAggregate, \Countable, \JsonSerializable
{
/**
* @var Violation[]
*/
private $violations;

/**
* @var bool
*/
Expand Down
Loading