Skip to content

Commit

Permalink
Hook up CI (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
benconvey authored May 29, 2024
1 parent a8b9038 commit c882099
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 140 deletions.
116 changes: 0 additions & 116 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,119 +56,3 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Architectural Rules
uses: docker://phparkitect/arkitect-github-actions:latest
env:
PHP_VERSION: ${{ matrix.php-versions }}
with:
args: check

phar:
runs-on: "ubuntu-20.04"
needs: build
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
tools: composer:v2.2
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}

- name: Install dependencies
run: composer install --prefer-dist --no-dev -o

- name: "Compile phparkitect phar"
run: php bin/box.phar compile -c ./box.json

- name: "Check phar"
run: php ./phparkitect.phar

- name: "Rename phar to avoid conflicts"
run: mv ./phparkitect.phar phparkitect-${{ github.sha }}.phar

- name: "Upload phar file artifact"
uses: actions/upload-artifact@v3
with:
name: phar-artifact
path: ./phparkitect-${{ github.sha }}.phar
retention-days: 1

smoke-test-phar:
needs: phar
runs-on: "ubuntu-20.04"
strategy:
matrix:
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
coverage-driver: [ 'pcov' ]

steps:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}

- name: "Download phar ./phparkitect-${{ github.sha }}.phar"
uses: actions/download-artifact@v3
with:
# will download phar in project root
name: phar-artifact

- name: "Smoke test phar"
run: php ./phparkitect-${{ github.sha }}.phar

publish_phar:
needs: [build, smoke-test-phar]
runs-on: "ubuntu-20.04"
if: github.event_name == 'release'
steps:
- name: "Download phar ./phparkitect-${{ github.sha }}.phar"
uses: actions/download-artifact@v3
with:
# will download phar in project root
name: phar-artifact

- name: Upload Release Asset
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./phparkitect-${{ github.sha }}.phar
asset_name: phparkitect.phar
tag: ${{ github.ref }}

publish_docker_images:
needs: [build, smoke-test-phar]
runs-on: "ubuntu-20.04"

if: github.ref == 'refs/heads/main' || github.event_name == 'release'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: crazy-max/ghaction-docker-meta@v2
with:
images: phparkitect/phparkitect
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, 'main') }}
type=ref,event=tag
flavor: |
latest=false
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

2 changes: 1 addition & 1 deletion src/Analyzer/ClassDependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ClassDependency
/** @var int */
private $line;

/** @var \Arkitect\Analyzer\FullyQualifiedClassName */
/** @var FullyQualifiedClassName */
private $FQCN;

public function __construct(string $FQCN, int $line)
Expand Down
4 changes: 2 additions & 2 deletions src/Analyzer/FileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FileParser implements Parser
/** @var \PhpParser\Parser */
private $parser;

/** @var \PhpParser\NodeTraverser */
/** @var NodeTraverser */
private $traverser;

/** @var FileVisitor */
Expand All @@ -35,7 +35,7 @@ public function __construct(

$lexer = new Emulative([
'usedAttributes' => ['comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos'],
'phpVersion' => $targetPhpVersion->get() ?? phpversion(),
'phpVersion' => $targetPhpVersion->get() ?? phpversion(),
]);

$this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, $lexer);
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/FileParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class FileParserFactory
{
public static function createFileParser(
TargetPhpVersion $targetPhpVersion = null,
?TargetPhpVersion $targetPhpVersion = null,
bool $parseCustomAnnotations = true
): FileParser {
return new FileParser(
Expand Down
22 changes: 11 additions & 11 deletions src/Analyzer/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class NameResolver extends NodeVisitorAbstract
* @param ErrorHandler|null $errorHandler Error handler
* @param array $options Options
*/
public function __construct(ErrorHandler $errorHandler = null, array $options = [])
public function __construct(?ErrorHandler $errorHandler = null, array $options = [])
{
$this->nameContext = new NameContext($errorHandler ?? new ErrorHandler\Throwing());
$this->preserveOriginalNames = $options['preserveOriginalNames'] ?? false;
Expand Down Expand Up @@ -91,7 +91,7 @@ public function enterNode(Node $node)
{
if ($node instanceof Stmt\Namespace_) {
$this->nameContext->startNamespace($node->name);
} elseif ($node instanceof Stmt\Use_) {
} elseif ($node instanceof Use_) {
foreach ($node->uses as $use) {
$this->addAlias($use, $node->type, null);
}
Expand Down Expand Up @@ -161,14 +161,14 @@ public function enterNode(Node $node)
}

if (null !== $arrayItemType) {
$node->type = $this->resolveName(new Node\Name($arrayItemType), Use_::TYPE_NORMAL);
$node->type = $this->resolveName(new Name($arrayItemType), Use_::TYPE_NORMAL);

return;
}
}

foreach ($phpDocNode->getVarTagValues() as $tagValue) {
$type = $this->resolveName(new Node\Name((string) $tagValue->type), Use_::TYPE_NORMAL);
$type = $this->resolveName(new Name((string) $tagValue->type), Use_::TYPE_NORMAL);
$node->type = $type;
break;
}
Expand All @@ -177,7 +177,7 @@ public function enterNode(Node $node)
foreach ($phpDocNode->getTags() as $tagValue) {
if ('@' === $tagValue->name[0] && !str_contains($tagValue->name, '@var')) {
$customTag = str_replace('@', '', $tagValue->name);
$type = $this->resolveName(new Node\Name($customTag), Use_::TYPE_NORMAL);
$type = $this->resolveName(new Name($customTag), Use_::TYPE_NORMAL);
$node->type = $type;

break;
Expand Down Expand Up @@ -207,10 +207,10 @@ public function enterNode(Node $node)
}
} elseif ($node instanceof Expr\FuncCall) {
if ($node->name instanceof Name) {
$node->name = $this->resolveName($node->name, Stmt\Use_::TYPE_FUNCTION);
$node->name = $this->resolveName($node->name, Use_::TYPE_FUNCTION);
}
} elseif ($node instanceof Expr\ConstFetch) {
$node->name = $this->resolveName($node->name, Stmt\Use_::TYPE_CONSTANT);
$node->name = $this->resolveName($node->name, Use_::TYPE_CONSTANT);
} elseif ($node instanceof Stmt\TraitUse) {
foreach ($node->traits as &$trait) {
$trait = $this->resolveClassName($trait);
Expand Down Expand Up @@ -282,7 +282,7 @@ protected function resolveName(Name $name, int $type): Name

protected function resolveClassName(Name $name): Name
{
return $this->resolveName($name, Stmt\Use_::TYPE_NORMAL);
return $this->resolveName($name, Use_::TYPE_NORMAL);
}

/**
Expand All @@ -308,7 +308,7 @@ protected function resolveAttrGroups(Node $node): void
}
}

private function addAlias(Stmt\UseUse $use, int $type, Name $prefix = null): void
private function addAlias(Stmt\UseUse $use, int $type, ?Name $prefix = null): void
{
// Add prefix for group uses
/** @var Name $name */
Expand Down Expand Up @@ -339,7 +339,7 @@ private function resolveSignature($node): void
$arrayItemType = $this->getArrayItemType($phpDocParam->type);

if (null !== $arrayItemType) {
$param->type = $this->resolveName(new Node\Name($arrayItemType), Use_::TYPE_NORMAL);
$param->type = $this->resolveName(new Name($arrayItemType), Use_::TYPE_NORMAL);
}
}
}
Expand All @@ -356,7 +356,7 @@ private function resolveSignature($node): void
}

if (null !== $arrayItemType) {
$node->returnType = $this->resolveName(new Node\Name($arrayItemType), Use_::TYPE_NORMAL);
$node->returnType = $this->resolveName(new Name($arrayItemType), Use_::TYPE_NORMAL);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CLI/TargetPhpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private function __construct(?string $version)
$this->version = $version;
}

public static function create(string $version = null): self
public static function create(?string $version = null): self
{
if (null === $version) {
return new self(phpversion());
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/NotExtendFromNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NotExtendFromNamespace implements Expression
private $namespace;

/** @var string[] */
private array $exceptions;
private $exceptions;

public function __construct(string $namespace, array $exceptions = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/Expression/ForClasses/NotImplementFromNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class NotImplementFromNamespace implements Expression
private $namespace;

/** @var string[] */
private array $exclusionList;
private $exclusionList;

public function __construct(string $namespace, array $exclusionList = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/RuleBuilders/Architecture/Architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function mustNotDependOnComponents(string ...$componentNames)
return $this;
}

public function rules(string $because = null): iterable
public function rules(?string $because = null): iterable
{
foreach ($this->componentSelectors as $name => $selector) {
if (isset($this->allowedDependencies[$name])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Violation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Violation implements \JsonSerializable
/** @var string */
private $error;

public function __construct(string $fqcn, string $error, int $line = null)
public function __construct(string $fqcn, string $error, ?int $line = null)
{
$this->fqcn = $fqcn;
$this->error = $error;
Expand Down
8 changes: 4 additions & 4 deletions tests/E2E/Cli/CheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public function test_you_can_ignore_the_default_baseline(): void

protected function runCheck(
$configFilePath = null,
bool $stopOnFailure = null,
string $useBaseline = null,
?bool $stopOnFailure = null,
?string $useBaseline = null,
$generateBaseline = false,
bool $skipBaseline = false
): ApplicationTester {
Expand Down Expand Up @@ -195,7 +195,7 @@ protected function runCheck(
return $appTester;
}

protected function assertCheckHasErrors(ApplicationTester $applicationTester, string $expectedOutput = null): void
protected function assertCheckHasErrors(ApplicationTester $applicationTester, ?string $expectedOutput = null): void
{
$this->assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode());
if (null != $expectedOutput) {
Expand All @@ -204,7 +204,7 @@ protected function assertCheckHasErrors(ApplicationTester $applicationTester, st
}
}

protected function assertCheckHasNoErrorsLike(ApplicationTester $applicationTester, string $expectedOutput = null): void
protected function assertCheckHasNoErrorsLike(ApplicationTester $applicationTester, ?string $expectedOutput = null): void
{
$this->assertEquals(self::ERROR_CODE, $applicationTester->getStatusCode());
if (null != $expectedOutput) {
Expand Down

0 comments on commit c882099

Please sign in to comment.