Skip to content

Commit

Permalink
feat: adds pest-arch-ignore-line or pest-arch-ignore-next-line
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Aug 7, 2024
1 parent 0518fcc commit 4e334d6
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ parameters:
ignoreErrors:
- "#has a nullable return type declaration.#"
- "# with a nullable type declaration.#"
- "#has parameter \\$closure with null as default value.#"
4 changes: 2 additions & 2 deletions src/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* argument is the test description; the second argument
* is a closure that contains the test expectations.
*/
function arch(?string $description = null, ?Closure $closure = null): TestCall
function arch(?string $description = null, ?Closure $closure = null): TestCall // @phpstan-ignore-line
{
$test = test(...func_get_args());
$test = test(...func_get_args()); // @phpstan-ignore-line

assert(! $test instanceof HigherOrderTapProxy);

Expand Down
23 changes: 23 additions & 0 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,29 @@ public function targeted(callable $callback, LayerOptions $options, callable $fa
}

$path = (string) realpath($object->path);

$line = $lineFinder($path);

$file = file($path);

if (is_array($file)) {
if (array_key_exists($line - 1, $file)) {
$lineContent = $file[$line - 1];

if (str_contains($lineContent, '@pest-arch-ignore-line')) {
continue;
}
}

if (array_key_exists($line - 2, $file)) {
$lineContent = $file[$line - 2];

if (str_contains($lineContent, '@pest-arch-ignore-next-line')) {
continue;
}
}
}

$path = substr($path, strlen(TestSuite::getInstance()->rootPath) + 1);

$failure(new Violation($path, $line, $line));
Expand Down Expand Up @@ -229,6 +251,7 @@ private function getUsagePathAndLines(Layer $layer, string $objectName, string $
/** @var ObjectDescription $dependOnObject */
$dependOnObject = array_pop($dependOnObjects);

/** @var class-string<\PhpParser\Node> $class */
$class = PhpCoreExpressions::getClass($target) ?? Name::class;

$nodes = ServiceContainer::$nodeFinder->findInstanceOf(
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Architectable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait Architectable
*/
public function arch(): TestCaseOptions
{
$options = $this->options ??= new TestCaseOptions();
$options = $this->options ??= new TestCaseOptions;

return $this->options = $options;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Objects/FunctionDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ final class FunctionDescription extends ObjectDescription // @phpstan-ignore-lin
*/
public static function make(string $path): self
{
$description = new self();
$description = new self;

try {
$description->path = (new ReflectionFunction($path))->getFileName();
} catch (\Throwable) {
$description->path = (string) (new ReflectionFunction($path))->getFileName();
} catch (\Throwable) { // @phpstan-ignore-line
$description->path = $path;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Objects/VendorObjectDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class VendorObjectDescription extends ObjectDescription // @phpstan-ignore
*/
public static function make(string $path): ?self // @phpstan-ignore-line
{
$object = new self();
$object = new self;

try {
$vendorObject = ObjectDescriptionBase::make($path);
Expand Down
3 changes: 1 addition & 2 deletions src/PendingArchExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ final class PendingArchExpectation
public function __construct(
private readonly Expectation $expectation,
private array $excludeCallbacks,
) {
}
) {}

/**
* Filters the given "targets" by only classes.
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixtures/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

namespace Tests\Fixtures;

abstract class Controller
{
}
abstract class Controller {}
2 changes: 1 addition & 1 deletion tests/Fixtures/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ProductController
public function index(): array
{
return [
new Product(),
new Product,
];
}
}
4 changes: 1 addition & 3 deletions tests/Fixtures/Functions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

if (! function_exists('my_request_global_function')) {
function my_request_global_function(): void
{
}
function my_request_global_function(): void {}
}
2 changes: 1 addition & 1 deletion tests/Fixtures/Misc/DependsOnVendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class DependsOnVendor
{
public function makeStrFromVendor(): Str
{
return new Str();
return new Str;
}
}
4 changes: 1 addition & 3 deletions tests/Fixtures/NamespacedFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Tests\Fixtures {
if (! function_exists('my_request_namespaced_function')) {
function my_request_namespaced_function(): void
{
}
function my_request_namespaced_function(): void {}
}
}
4 changes: 1 addition & 3 deletions tests/Fixtures/Support/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Tests\Fixtures\Support;

class Env
{
}
class Env {}

0 comments on commit 4e334d6

Please sign in to comment.