Skip to content

Commit

Permalink
Merge pull request #46 from worksome/feature/dependencies
Browse files Browse the repository at this point in the history
chore(deps): update dependencies
  • Loading branch information
owenvoke authored Oct 10, 2023
2 parents 9693940 + c9e5d0e commit 111e529
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
uses: ramsey/composer-install@v2

- name: Test php code
run: vendor/bin/pest --testsuite ${{ matrix.test-suite }}
run: vendor/bin/pest -p --testsuite ${{ matrix.test-suite }}
34 changes: 19 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"require": {
"php": "^8.2",
"composer-plugin-api": "^2.0",
"canvural/larastan-strict-rules": "^2.0",
"friendsofphp/php-cs-fixer": "^3.8",
"canvural/larastan-strict-rules": "^2.1.8",
"friendsofphp/php-cs-fixer": "^3.34.1",
"jetbrains/phpstorm-attributes": "^1.0",
"nunomaduro/larastan": "^2.3.4",
"phpstan/phpstan": "^1.6",
"phpstan/phpstan-mockery": "^1.0",
"rector/rector": "^0.16",
"slevomat/coding-standard": "^8.5",
"spaze/phpstan-disallowed-calls": "^2.8",
"squizlabs/php_codesniffer": "^3.6.1",
"symplify/easy-coding-standard": "^11.1",
"thecodingmachine/safe": "^2.0"
"nunomaduro/larastan": "^2.6.4",
"phpstan/phpstan": "^1.10.38",
"phpstan/phpstan-mockery": "^1.1.1",
"rector/rector": "^0.18.5",
"slevomat/coding-standard": "^8.14.1",
"spaze/phpstan-disallowed-calls": "^2.16",
"squizlabs/php_codesniffer": "^3.7.2",
"symplify/easy-coding-standard": "^11.5",
"thecodingmachine/safe": "^2.5"
},
"require-dev": {
"composer/composer": "^2.5",
"pestphp/pest": "^2.0",
"spatie/invade": "^1.0",
"spatie/ray": "^1.32"
"composer/composer": "^2.6.5",
"pestphp/pest": "^2.21",
"spatie/invade": "^1.1.1",
"spatie/ray": "^1.39"
},
"autoload": {
"psr-4": {
Expand All @@ -39,6 +39,10 @@
{
"name": "Oliver Nybroe",
"email": "[email protected]"
},
{
"name": "Owen Voke",
"email": "[email protected]"
}
],
"extra": {
Expand Down
11 changes: 11 additions & 0 deletions src/Enums/AttributeKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Worksome\CodingStyle\Enums;

enum AttributeKey: string
{
case Next = 'next';
case Parent = 'parent';
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Worksome\CodingStyle\Enums\AttributeKey;

/**
* @implements Rule<Node\Expr\MethodCall>
Expand Down Expand Up @@ -51,14 +51,14 @@ private function isCalledInRouteGroupClosure(Node\Expr\CallLike $node, Scope $sc
return false;
}

$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
$parent = $node->getAttribute(AttributeKey::Parent->value);

while ($parent !== null) {
if ($parent instanceof Node\Expr\StaticCall) {
return $parent->class->toString() === Route::class;
}

$parent = $parent->getAttribute(AttributeKey::PARENT_NODE);
$parent = $parent->getAttribute(AttributeKey::Parent->value);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PhpParser\Node;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Worksome\CodingStyle\Enums\AttributeKey;

final class PartialRouteResourceInspector
{
Expand Down Expand Up @@ -48,14 +48,14 @@ public function isApplicable(Node $node): bool

public function inspect(Node $node): array
{
$next = $node->getAttribute(AttributeKey::NEXT_NODE);
$next = $node->getAttribute(AttributeKey::Next->value);

while ($next !== null) {
if (in_array($next->name, $this->partialMethods)) {
return [$this->errorFor($next->name)];
}

$next = $next->getAttribute(AttributeKey::PARENT_NODE)->getAttribute(AttributeKey::NEXT_NODE);
$next = $next->getAttribute(AttributeKey::Parent->value)->getAttribute(AttributeKey::Next->value);
}

return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function uninstall(Composer $composer, IOInterface $io)
public function getCapabilities(): array
{
return [
CommandProvider::class => CodingStyleCommandProvider::class,
CommandProvider::class => CodingStyleCommandProvider::class,
];
}
}
30 changes: 17 additions & 13 deletions src/Rector/Generic/DisallowedAttributesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Worksome\CodingStyle\Rector\Generic;

use Illuminate\Support\Collection;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

class DisallowedAttributesRector extends AbstractRector implements ConfigurableRectorInterface
{
/** @var array<class-string> */
/** @var array<class-string> */
private array $disallowedAttributes = [];

public function getRuleDefinition(): RuleDefinition
Expand All @@ -30,29 +30,33 @@ class MyClass {}
);
}

/** {@inheritdoc} */
public function getNodeTypes(): array
{
return [Node\AttributeGroup::class];
}

/** {@inheritdoc} */
public function configure(array $configuration): void
{
$this->disallowedAttributes = $configuration;
}

/**
* @param Node\AttributeGroup $node
*/
/** @param Node\AttributeGroup $node */
public function refactor(Node $node)
{
Collection::make($node->attrs)->reject(function (Node\Attribute $node) {
foreach ($this->disallowedAttributes as $disallowedAttribute) {
if ($this->isName($node, $disallowedAttribute)) {
$this->removeNode($node);
return true;
}
foreach ($node->attrs as $key => $attribute) {
if (! $this->isNames($attribute, $this->disallowedAttributes)) {
continue;
}
return false;
})->whenEmpty(fn () => $this->removeNode($node));

unset($node->attrs[$key]);
}

if ($node->attrs === []) {
return NodeTraverser::REMOVE_NODE;
}

return null;
}
}

0 comments on commit 111e529

Please sign in to comment.