Skip to content
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
7 changes: 7 additions & 0 deletions .github/linters/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>

<ruleset name="super-linter">
<rule ref="PSR12">
<exclude name="PSR12.Properties.ConstantVisibility.NotFound" />
</rule>
</ruleset>
6 changes: 6 additions & 0 deletions .github/linters/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: max
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '#constructor invoked with#'
- '#FunctionVariant constructor expects#'
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on: push

jobs:
php-tests:

strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
prefer: ['lowest', 'stable']

name: Test on PHP ${{ matrix.php }} with ${{ matrix.prefer }} composer prefer option
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Check PHP Version
run: php -v

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.prefer }}-
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-composer-${{ matrix.prefer }}-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-${{ matrix.prefer }} --prefer-dist --no-progress

- name: Run tests
run: composer test

linter:
name: Linter
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.1

- name: Install dependencies
run: composer update --prefer-stable --prefer-dist --no-progress

- name: Lint Code
uses: github/super-linter@v3
env:
FILTER_REGEX_EXCLUDE: .*vendor.*
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_PHP_PSALM: false
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Enum class reflection extension for PHPStan

[![Build Status](https://travis-ci.org/timeweb/phpstan-enum.svg?branch=master)](https://travis-ci.org/timeweb/phpstan-enum)
[![Packagist Version](https://img.shields.io/packagist/v/timeweb/phpstan-enum)](https://packagist.org/packages/timeweb/phpstan-enum)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/timeweb/phpstan-enum/ci)

* [PHPStan](https://phpstan.org/)
* [PHP Enum](https://github.com/myclabs/php-enum)
Expand All @@ -11,13 +12,13 @@ This extension defines dynamic methods for `MyCLabs\Enum\Enum` subclasses.

To use this extension, require it with [Composer](https://getcomposer.org)

```
```bash
composer require --dev timeweb/phpstan-enum
```

And include extension.neon in your project's PHPStan config

```
```yaml
includes:
- vendor/timeweb/phpstan-enum/extension.neon
```
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
"require": {
"php": "~7.1|^8.0",
"myclabs/php-enum": "^1.2",
"phpstan/phpstan": "^0.10|^0.11|^0.12"
"phpstan/phpstan": "^0.10|^0.11|^0.12.34"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^7.0|^9.0"
},
"autoload": {
"psr-4": {
"Timeweb\\PHPStan\\": "src/"
}
},
"autoload-dev": {
"classmap": [
"tests/_fixture/"
]
"psr-4": {
"Timeweb\\Tests\\PHPStan\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php

class EnumFixture extends MyCLabs\Enum\Enum
declare(strict_types=1);

namespace Timeweb\Tests\PHPStan\Fixture;

use MyCLabs\Enum\Enum;

class EnumFixture extends Enum
{
const MEMBER = 'member';

Expand Down
25 changes: 17 additions & 8 deletions tests/Reflection/EnumMethodsClassReflectionExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

declare(strict_types=1);

namespace Timeweb\Tests\PHPStan\Reflection;

use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Testing\TestCase;
use PHPStan\Type\VerbosityLevel;
use Timeweb\PHPStan\Reflection\EnumMethodReflection;
use Timeweb\PHPStan\Reflection\EnumMethodsClassReflectionExtension;
use Timeweb\Tests\PHPStan\Fixture\EnumFixture;

/**
* @coversDefaultClass Timeweb\PHPStan\Reflection\EnumMethodsClassReflectionExtension
* @coversDefaultClass \Timeweb\PHPStan\Reflection\EnumMethodsClassReflectionExtension
*/
class EnumMethodsClassReflectionExtensionTest extends TestCase
{
Expand All @@ -23,7 +26,7 @@ class EnumMethodsClassReflectionExtensionTest extends TestCase
*/
protected $reflectionExtension;

public function setUp()
public function setUp(): void
{
$this->broker = $this->createBroker();
$this->reflectionExtension = new EnumMethodsClassReflectionExtension();
Expand All @@ -33,14 +36,17 @@ public function setUp()
* @covers ::hasMethod
* @dataProvider methodNameDataProvider
*/
public function testEnumMethodsCanBeFoundInEnumSubclasses(bool $expected, string $methodName)
public function testEnumMethodsCanBeFoundInEnumSubclasses(bool $expected, string $methodName): void
{
$classReflection = $this->broker->getClass(EnumFixture::class);
$hasMethod = $this->reflectionExtension->hasMethod($classReflection, $methodName);

$this->assertEquals($expected, $hasMethod);
}

/**
* @return array[]
*/
public function methodNameDataProvider(): array
{
return [
Expand All @@ -52,7 +58,7 @@ public function methodNameDataProvider(): array
/**
* @covers ::hasMethod
*/
public function testEnumMethodsCannotBeFoundInNonEnumSubclasses()
public function testEnumMethodsCannotBeFoundInNonEnumSubclasses(): void
{
$classReflection = $this->broker->getClass(EnumFixture::class);
$hasMethod = $this->reflectionExtension->hasMethod($classReflection, 'SOME_NAME');
Expand All @@ -62,9 +68,9 @@ public function testEnumMethodsCannotBeFoundInNonEnumSubclasses()

/**
* @covers ::getMethod
* @uses Timeweb\PHPStan\Reflection\EnumMethodReflection
* @uses \Timeweb\PHPStan\Reflection\EnumMethodReflection
*/
public function testEnumMethodReflectionCanBeObtained()
public function testEnumMethodReflectionCanBeObtained(): void
{
$classReflection = $this->broker->getClass(EnumFixture::class);
$methodReflection = $this->reflectionExtension->getMethod($classReflection, 'SOME_NAME');
Expand All @@ -80,10 +86,10 @@ public function testEnumMethodReflectionCanBeObtained()
* @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::isPublic
* @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getPrototype
* @covers \Timeweb\PHPStan\Reflection\EnumMethodReflection::getVariants
* @uses Timeweb\PHPStan\Reflection\EnumMethodReflection
* @uses \Timeweb\PHPStan\Reflection\EnumMethodReflection
* @dataProvider enumFixtureProperties
*/
public function testEnumMethodProperties(string $propertyName)
public function testEnumMethodProperties(string $propertyName): void
{
$classReflection = $this->broker->getClass(EnumFixture::class);
$methodReflection = $this->reflectionExtension->getMethod($classReflection, $propertyName);
Expand All @@ -97,6 +103,9 @@ public function testEnumMethodProperties(string $propertyName)
$this->assertSame(EnumFixture::class, $parametersAcceptor->getReturnType()->describe(VerbosityLevel::value()));
}

/**
* @return string[][]
*/
public function enumFixtureProperties(): array
{
return [
Expand Down