Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: find computed properties in abstract classes #4

Merged
merged 2 commits into from
Sep 6, 2024
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
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Tests

on:
Expand All @@ -7,11 +8,6 @@ on:
- 'docs/**'
branches:
- "**"
pull_request:
types: [ready_for_review, synchronize, opened]
paths-ignore:
- "**.md"
- 'docs/**'

jobs:
tests:
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"test:phpstan": "phpstan analyze --ansi",
"test:phpstan:src": "phpstan analyze --ansi",
"test:phpstan:integration": "phpstan analyze --ansi -c tests/phpstan-tests.neon",
"test:phpunit": "phpunit --colors=always",
"test": [
"@test:phpstan",
"@test:phpstan:src",
"@test:phpstan:integration",
"@test:phpunit"
]
}
Expand Down
6 changes: 3 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
level: max
paths:
- src
level: max
paths:
- src
4 changes: 0 additions & 4 deletions src/Properties/ComputedPropertyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
return false;
}

if ($classReflection->isAbstract()) {
return false;
}

if ($classReflection->hasNativeMethod($this->getterPropertyName($propertyName))) {
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Fixtures/AbstractBaseComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace CalebDW\LarastanLivewire\Tests\Fixtures;

use Livewire\Component;

abstract class AbstractBaseComponent extends Component
{
use TraitWithComputedProperties;

public function testIntegration(): string
{
return $this->traitMethod
.$this->trait_method
.$this->traitGetter
.$this->trait_getter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

declare(strict_types=1);

namespace CalebDW\LarastanLivewire\Tests\stubs;
namespace CalebDW\LarastanLivewire\Tests\Fixtures;

use Livewire\Attributes\Computed;
use Livewire\Component;

final class TestComponentWithComputedProperties extends Component
class TestComponentWithComputedProperties extends AbstractBaseComponent
{
use TraitWithComputedProperties;

public function notAComputedProperty(): bool
{
return true;
Expand All @@ -25,6 +22,8 @@ private function privateMethod(): bool
#[Computed]
protected function protectedMethod(): bool
{
$this->privateMethod();

return true;
}

Expand Down Expand Up @@ -73,4 +72,27 @@ public function getGetterStyleProperty(): array
{
return ['foo', 'bar'];
}

public function testIntegration(): string
{
return $this->privateMethod
.$this->private_method
.$this->protectedMethod
.$this->protected_method
.$this->property
.$this->propertyWithComments
.$this->property_with_comments
.$this->deprecatedProperty
.$this->deprecated_property
.$this->deprecatedPropertyWithDescription
.$this->deprecated_property_with_description
.$this->propertyWithGenerics[0]
.$this->property_with_generics[0]
.$this->getterStyle[0]
.$this->getter_style[0]
.$this->traitMethod
.$this->trait_method
.$this->traitGetter
.$this->trait_getter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace CalebDW\LarastanLivewire\Tests\stubs;
namespace CalebDW\LarastanLivewire\Tests\Fixtures;

use Livewire\Attributes\Computed;

Expand All @@ -18,4 +18,12 @@ public function getTraitGetterProperty(): bool
{
return true;
}

public function testIntegration(): string
{
return $this->traitMethod
.$this->trait_method
.$this->traitGetter
.$this->trait_getter;
}
}
2 changes: 1 addition & 1 deletion tests/Properties/ComputedPropertyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace CalebDW\LarastanLivewire\Tests\Properties;

use CalebDW\LarastanLivewire\Properties\ComputedPropertyExtension;
use CalebDW\LarastanLivewire\Tests\stubs\TestComponentWithComputedProperties;
use CalebDW\LarastanLivewire\Tests\Fixtures\TestComponentWithComputedProperties;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\VerbosityLevel;
Expand Down
6 changes: 6 additions & 0 deletions tests/phpstan-tests.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- ../extension.neon
parameters:
level: max
paths:
- Fixtures
Loading