Skip to content

Commit

Permalink
Drop Laravel 8, allow Laravel 11 (#93)
Browse files Browse the repository at this point in the history
* bump dev deps

* drop Laravel 8, allow Laravel 11

* apply cs, make use of psr12

* rerun rector

* [rector] Rector fixes

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Jan 10, 2024
1 parent c8f99c5 commit 593c05f
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 84 deletions.
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
"keywords": ["static analysis", "phpstan-extension"],
"require": {
"php": "^8.1",
"illuminate/contracts": "^8.8 || ^9.0 || ^10.0",
"illuminate/filesystem": "^8.8 || ^9.0 || ^10.0",
"illuminate/view": "^8.8 || ^9.0 || ^10.0",
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0",
"illuminate/filesystem": "^9.0 || ^10.0 || ^11.0",
"illuminate/view": "^9.0 || ^10.0 || ^11.0",
"phpstan/phpstan": "^1.10"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"symplify/easy-coding-standard": "^12.0",
"rector/rector": "^0.15.20",
"laravel/framework": "^10.2",
"symplify/easy-ci": "^11.2",
"symplify/easy-coding-standard": "^12.1",
"rector/rector": "^0.19",
"nikic/php-parser": "^4.18",
"laravel/framework": "^10.40",
"symplify/easy-ci": "^11.3",
"tracy/tracy": "^2.9",
"tomasvotruba/class-leak": "*"
"tomasvotruba/class-leak": "^0.2.6"
},
"autoload": {
"psr-4": {
Expand Down
28 changes: 5 additions & 23 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
<?php

declare(strict_types=1);
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
// configs
__DIR__ . '/ecs.php',
__DIR__ . '/rector.php',
]);
$ecsConfig->skip(['*/Fixture/*']);
// this way you can add sets - group of rules
$ecsConfig->sets([
SetList::SPACES,
SetList::ARRAY,
SetList::STRICT,
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::COMMENTS,
SetList::PSR_12,
]);
$ecsConfig->rules([LineLengthFixer::class]);
};
return ECSConfig::configure()
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
->withRootFiles()
->withPreparedSets(psr12: true, common: true, symplify: true)
->withSkip(['*/Fixture/*']);
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ parameters:
# this package relies havily on the file analyse
- '#(Calling|Extending|) (.*?) is not covered by backward compatibility promise#'

# most likely exists in every laravel project
- '#class Illuminate\\Foundation\\Application#'

# test fixture where this is expected
-
message: '#File ends with a trailing whitespace#'
Expand Down
9 changes: 2 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

declare(strict_types=1);
use Rector\Config\RectorConfig;

use Rector\Php80\Rector\FuncCall\TokenGetAllToObjectRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Set\ValueObject\LevelSetList;
Expand All @@ -22,11 +21,7 @@

$rectorConfig->importNames();

$rectorConfig->skip([
'*/Fixture/*',
// buggy for follow up token updates
TokenGetAllToObjectRector::class,
]);
$rectorConfig->skip(['*/Fixture/*']);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
Expand Down
18 changes: 12 additions & 6 deletions src/NodeAnalyzer/BladeViewMethodsMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ final class BladeViewMethodsMatcher
/**
* @var string
*/
private const MAKE = 'make';
public const VIEW = 'view';

/**
* @var string
*/
public const VIEW = 'view';
private const MAKE = 'make';

/**
* @var string[]
Expand Down Expand Up @@ -125,9 +125,15 @@ private function isClassWithViewMethod(Type $objectType): bool
return false;
}

return $objectType->isInstanceOf(Component::class)->yes()
|| $objectType->isInstanceOf(Mailable::class)->yes()
|| $objectType->isInstanceOf(MailMessage::class)->yes();
if ($objectType->isInstanceOf(Component::class)->yes()) {
return true;
}

if ($objectType->isInstanceOf(Mailable::class)->yes()) {
return true;
}

return $objectType->isInstanceOf(MailMessage::class)->yes();
}

private function isCalledOnTypeABladeView(Type $objectType, string $methodName): bool
Expand All @@ -151,7 +157,7 @@ private function findTemplateNameArg(string $methodName, MethodCall $methodCall)
{
$args = $methodCall->getArgs();

if (count($args) === 0) {
if ($args === []) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/NodeAnalyzer/LaravelViewFunctionMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function match(FuncCall $funcCall, Scope $scope): array
return [];
}

$template = $funcCall->getArgs()[0]->value;
$template = $funcCall->getArgs()[0]
->value;

$resolvedTemplateFilePaths = $this->templateFilePathResolver->resolveExistingFilePaths($template, $scope);
if ($resolvedTemplateFilePaths === []) {
Expand Down
12 changes: 6 additions & 6 deletions src/PhpParser/NodeVisitor/BladeLineNumberNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

final class BladeLineNumberNodeVisitor extends NodeVisitorAbstract
{
/**
* @see https://regex101.com/r/GqrJOW/1
* @var string
*/
private const TEMPLATE_FILE_NAME_AND_LINE_NUMBER_REGEX = '#/\*\* file: (.*?), line: (\d+) \*/#';

/**
* Keyed by PHP line number. And inner array has `fileName` => `templateLineNumber`
*
* @var array<int, array<string, int>>
*/
private array $phpLineToBladeTemplateLineMap = [];

/**
* @see https://regex101.com/r/GqrJOW/1
* @var string
*/
private const TEMPLATE_FILE_NAME_AND_LINE_NUMBER_REGEX = '#/\*\* file: (.*?), line: (\d+) \*/#';

/**
* @param Stmt[] $nodes
*
Expand Down
3 changes: 2 additions & 1 deletion src/Rules/BladeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace TomasVotruba\Bladestan\Rules;

use PhpParser\Node;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function __construct(

public function getNodeType(): string
{
return Node\Expr\CallLike::class;
return CallLike::class;
}

public function processNode(Node $node, Scope $scope): array
Expand Down
22 changes: 11 additions & 11 deletions src/TemplateCompiler/Reflection/PrivatesAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ final class PrivatesAccessor
{
public function getPrivateProperty(object $object, string $propertyName): mixed
{
$propertyReflection = $this->resolvePropertyReflection($object, $propertyName);
$propertyReflection->setAccessible(true);
$reflectionProperty = $this->resolvePropertyReflection($object, $propertyName);
$reflectionProperty->setAccessible(true);

return $propertyReflection->getValue($object);
return $reflectionProperty->getValue($object);
}

public function setPrivateProperty(object $object, string $propertyName, mixed $value): void
{
$reflectionProperty = $this->resolvePropertyReflection($object, $propertyName);
$reflectionProperty->setAccessible(true);

$reflectionProperty->setValue($object, $value);
}

private function resolvePropertyReflection(object $object, string $propertyName): ReflectionProperty
Expand All @@ -31,12 +39,4 @@ private function resolvePropertyReflection(object $object, string $propertyName)
$errorMessage = sprintf('Property "$%s" was not found in "%s" class', $propertyName, $object::class);
throw new RuntimeException($errorMessage);
}

public function setPrivateProperty(object $object, string $propertyName, mixed $value): void
{
$propertyReflection = $this->resolvePropertyReflection($object, $propertyName);
$propertyReflection->setAccessible(true);

$propertyReflection->setValue($object, $value);
}
}
4 changes: 2 additions & 2 deletions src/ValueObject/CompiledTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final class CompiledTemplate
public function __construct(
private readonly string $bladeFilePath,
private readonly string $phpFilePath,
private readonly PhpFileContentsWithLineMap $lineMap,
private readonly PhpFileContentsWithLineMap $phpFileContentsWithLineMap,
private readonly int $phpLine,
) {
}
Expand All @@ -26,7 +26,7 @@ public function getPhpFilePath(): string

public function getLineMap(): PhpFileContentsWithLineMap
{
return $this->lineMap;
return $this->phpFileContentsWithLineMap;
}

public function getPhpLine(): int
Expand Down
14 changes: 7 additions & 7 deletions src/ViewRuleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function processNode(
$call->getLine()
);

if ($compiledTemplate === null) {
if (! $compiledTemplate instanceof CompiledTemplate) {
continue;
}

Expand All @@ -68,6 +68,11 @@ public function processNode(
return $ruleErrors;
}

public function setRegistry(Registry $registry): void
{
$this->registry = $registry;
}

/**
* @return RuleError[]
*/
Expand Down Expand Up @@ -105,7 +110,7 @@ private function compileToPhp(
string $templateFilePath,
array $variablesAndTypes,
string $filePath,
int $phpLine
int $phpLine
): ?CompiledTemplate {
$fileContents = file_get_contents($templateFilePath);
if ($fileContents === false) {
Expand All @@ -125,9 +130,4 @@ private function compileToPhp(

return new CompiledTemplate($filePath, $tmpFilePath, $phpFileContentsWithLineMap, $phpLine);
}

public function setRegistry(Registry $registry): void
{
$this->registry = $registry;
}
}
12 changes: 8 additions & 4 deletions tests/Blade/PhpLineToTemplateLineResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static function provideData(): Iterator
echo 'foo';
/* file: foo.blade.php, line: 6 */
echo 'foo';
PHP,
PHP
,
[],
];

Expand All @@ -53,7 +54,8 @@ public static function provideData(): Iterator
<?php
/** file: foo.blade.php, line: 5 */
echo 'foo';
PHP,
PHP
,
[
3 => [
'foo.blade.php' => 5,
Expand All @@ -68,7 +70,8 @@ public static function provideData(): Iterator
echo 'foo';
/** file: foo.blade.php, line: 55 */
echo 'bar';
PHP,
PHP
,
[
3 => [
'foo.blade.php' => 5,
Expand All @@ -88,7 +91,8 @@ public static function provideData(): Iterator
echo 'bar';
/** file: bar.blade.php, line: 55 */
echo 'baz';
PHP,
PHP
,
[
3 => [
'foo.blade.php' => 5,
Expand Down
10 changes: 5 additions & 5 deletions tests/Rules/BladeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

final class BladeRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return self::getContainer()->getByType(BladeRule::class);
}

/**
* @param mixed[] $expectedErrorsWithLines
*/
Expand Down Expand Up @@ -104,4 +99,9 @@ public static function getAdditionalConfigFiles(): array
{
return [__DIR__ . '/config/configured_extension.neon'];
}

protected function getRule(): Rule
{
return self::getContainer()->getByType(BladeRule::class);
}
}

0 comments on commit 593c05f

Please sign in to comment.