Skip to content

Commit

Permalink
Merge pull request #478 from ergebnis/feature/enum
Browse files Browse the repository at this point in the history
Enhancement: Add support for `enum`
  • Loading branch information
localheinz authored Dec 30, 2021
2 parents 5e00916 + 108bdd1 commit 8d30c4a
Show file tree
Hide file tree
Showing 18 changed files with 410 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on: # yamllint disable-line rule:truthy
- "main"

env:
MIN_COVERED_MSI: 86
MIN_MSI: 84
MIN_COVERED_MSI: 85
MIN_MSI: 82
PHP_EXTENSIONS: "mbstring, tokenizer"

jobs:
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

For a full diff see [`1.1.1...main`][1.1.1...main].
For a full diff see [`1.2.0...main`][1.2.0...main].

## [`1.2.0`][1.2.0]

For a full diff see [`1.1.1...1.2.0`][1.1.0...1.2.0].

### Added

- Added support for `enum` ([#478]), by [@localheinz]

### Deprecated

Expand Down Expand Up @@ -105,6 +113,7 @@ For a full diff see [`0.4.0...0.5.0`][0.4.0...0.5.0].
[1.0.1]: https://github.com/localheinz/ergebnis/classy/releases/tag/1.0.1
[1.1.0]: https://github.com/localheinz/ergebnis/classy/releases/tag/1.1.0
[1.1.1]: https://github.com/localheinz/ergebnis/classy/releases/tag/1.1.1
[1.2.0]: https://github.com/localheinz/ergebnis/classy/releases/tag/1.2.0

[0.4.0...0.5.0]: https://github.com/ergebnis/classy/compare/0.4.0...0.5.0
[0.5.0...0.5.1]: https://github.com/ergebnis/classy/compare/0.5.0...0.5.1
Expand All @@ -113,7 +122,8 @@ For a full diff see [`0.4.0...0.5.0`][0.4.0...0.5.0].
[1.0.0...1.0.1]: https://github.com/ergebnis/classy/compare/1.0.0...1.0.1
[1.0.1...1.1.0]: https://github.com/ergebnis/classy/compare/1.0.1...1.1.0
[1.1.0...1.1.1]: https://github.com/ergebnis/classy/compare/1.1.0...1.1.1
[1.1.1...main]: https://github.com/ergebnis/classy/compare/1.1.1...main
[1.1.1...1.2.0]: https://github.com/ergebnis/classy/compare/1.1.1...1.2.0
[1.2.0...main]: https://github.com/ergebnis/classy/compare/1.2.0...main

[#77]: https://github.com/ergebnis/classy/pull/77
[#88]: https://github.com/ergebnis/classy/pull/88
Expand All @@ -123,6 +133,7 @@ For a full diff see [`0.4.0...0.5.0`][0.4.0...0.5.0].
[#235]: https://github.com/ergebnis/classy/pull/235
[#343]: https://github.com/ergebnis/classy/pull/343
[#467]: https://github.com/ergebnis/classy/pull/467
[#478]: https://github.com/ergebnis/classy/pull/478

[@ergebnis]: https://github.com/ergebnis
[@localheinz]: https://github.com/localheinz
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MIN_COVERED_MSI:=86
MIN_MSI:=84
MIN_COVERED_MSI:=85
MIN_MSI:=82

.PHONY: it
it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets
Expand Down
1 change: 1 addition & 0 deletions composer-require-checker.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"string",
"true",
"void",
"T_ENUM",
"T_NAME_QUALIFIED"
]
}
47 changes: 47 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
<code>$constructs</code>
</MissingConstructor>
</file>
<file src="test/Fixture/Classy/Php81/WithinMultipleNamespaces/source.php">
<ParseError occurrences="1">
<code>Qux</code>
</ParseError>
</file>
<file src="test/Fixture/Classy/Php81/WithinNamespace/source.php">
<ParseError occurrences="1">
<code>Qux</code>
</ParseError>
</file>
<file src="test/Fixture/Classy/Php81/WithinNamespaceWithBraces/source.php">
<ParseError occurrences="1">
<code>Qux</code>
</ParseError>
</file>
<file src="test/Unit/ConstructTest.php">
<DeprecatedMethod occurrences="1">
<code>__toString</code>
Expand All @@ -27,6 +42,38 @@
</MixedArgument>
<TooManyArguments occurrences="1"/>
</file>
<file src="test/Unit/ConstructsTest.php">
<MixedArgument occurrences="13">
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Bar::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Baz::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Foo::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Qux::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Bar::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Baz::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Foo::class</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Qux::class</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Bar::class</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Baz::class</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Foo::class</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Qux::class</code>
<code>Test\Fixture\Classy\Php81\WithinNamespace\Qux::class</code>
</MixedArgument>
<UndefinedClass occurrences="13">
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Bar</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Baz</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Foo</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar\Qux</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Bar</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Baz</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Foo</code>
<code>Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo\Qux</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Bar</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Baz</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Foo</code>
<code>Test\Fixture\Classy\Php81\WithinNamespaceWithBraces\Qux</code>
<code>Test\Fixture\Classy\Php81\WithinNamespace\Qux</code>
</UndefinedClass>
</file>
<file src="test/Util/Scenario.php">
<RedundantCast occurrences="1">
<code>\array_values</code>
Expand Down
18 changes: 17 additions & 1 deletion src/Constructs.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ public static function fromSource(string $source): array
];
}

$classyTokens = [
\T_CLASS,
\T_INTERFACE,
\T_TRAIT,
];

// https://wiki.php.net/rfc/enumerations
if (\PHP_VERSION_ID >= 80100 && \defined('T_ENUM')) {
$classyTokens = [
\T_CLASS,
\T_ENUM,
\T_INTERFACE,
\T_TRAIT,
];
}

for ($index = 0; $index < $count; ++$index) {
$token = $sequence[$index];

Expand Down Expand Up @@ -80,7 +96,7 @@ public static function fromSource(string $source): array
}

// skip non-classy tokens
if (!\is_array($token) || !\in_array($token[0], [\T_CLASS, \T_INTERFACE, \T_TRAIT], true)) {
if (!\is_array($token) || !\in_array($token[0], $classyTokens, true)) {
continue;
}

Expand Down
22 changes: 22 additions & 0 deletions test/Fixture/Classy/Php81/WithMethodsNamedAfterKeywords/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithMethodsNamedAfterKeywords;

class Foo
{
public function class()
{
}

public function enum()
{
}

public function interface()
{
}

public function trait()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithMethodsNamedAfterKeywordsAndReturnType;


class Foo
{
public function class(): string
{
}

public function enum(): string
{
}

public function interface(): string
{
}

public function trait(): string
{
}
}
23 changes: 23 additions & 0 deletions test/Fixture/Classy/Php81/WithinMultipleNamespaces/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Foo;
{
class Foo {}

interface Bar {}

trait Baz {}

enum Qux {}
}

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinMultipleNamespaces\Bar;
{
class Foo {}

interface Bar {}

trait Baz {}

enum Qux {}
}
11 changes: 11 additions & 0 deletions test/Fixture/Classy/Php81/WithinNamespace/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinNamespace;

class Foo {}

interface Bar {}

trait Baz {}

enum Qux {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinNamespaceAndMultiLineComments;

/* foo */ class /* bar */ Foo /* baz */ {}

/* foo */ interface /* bar */ Bar /* baz */ {}

/* foo */ trait /* bar */ Baz /* baz */ {}

/* foo */ enum /* bar */ Qux /* baz */ {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinNamespaceAndShellStyleComments;

class # foo
Foo # bar
{}

interface # foo
Bar # bar
{}

trait # foo
Baz // bar
{}

enum # foo
Baz // bar
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinNamespaceAndSingleLineComments;

class // foo
Foo // bar
{}

interface // foo
Bar // bar
{}

trait // foo
Baz // bar
{}
12 changes: 12 additions & 0 deletions test/Fixture/Classy/Php81/WithinNamespaceWithBraces/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Ergebnis\Classy\Test\Fixture\Classy\Php81\WithinNamespaceWithBraces
{
class Foo {}

interface Bar {}

trait Baz {}

enum Qux {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Ergebnis;

class Foo {}

interface Bar {}

trait Baz {}

enum Qux {}
9 changes: 9 additions & 0 deletions test/Fixture/Classy/Php81/WithoutNamespace/source.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

class Foo {}

interface Bar {}

trait Baz {}

enum Qux {}
Loading

0 comments on commit 8d30c4a

Please sign in to comment.