Skip to content

Commit

Permalink
Merge pull request #343 from ergebnis/fix/single-namespace-segment
Browse files Browse the repository at this point in the history
Fix: Properly determine classy name within namespace with single segment
  • Loading branch information
ergebnis-bot authored Feb 1, 2021
2 parents 7dfb744 + 1b58328 commit 72840bd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on: # yamllint disable-line rule:truthy

env:
MIN_COVERED_MSI: 86
MIN_MSI: 85
MIN_MSI: 84
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.0...main`][1.1.0...main].
For a full diff see [`1.1.1...main`][1.1.1...main].

## [`1.1.1`][1.1.1]

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

### Fixed

* Determine classy names within namespace with single segment on PHP 8.0 ([#343]), by [@localheinz]

## [`1.1.0`][1.1.0]

Expand Down Expand Up @@ -92,21 +100,24 @@ For a full diff see [`0.4.0...0.5.0`][0.4.0...0.5.0].
[1.0.0]: https://github.com/localheinz/ergebnis/classy/releases/tag/1.0.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

[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
[0.5.1...0.5.2]: https://github.com/ergebnis/classy/compare/0.5.1...0.5.2
[0.5.2...1.0.0]: https://github.com/ergebnis/classy/compare/0.5.2...1.0.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...main]: https://github.com/ergebnis/classy/compare/1.1.0...main
[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

[#77]: https://github.com/ergebnis/classy/pull/77
[#88]: https://github.com/ergebnis/classy/pull/88
[#100]: https://github.com/ergebnis/classy/pull/100
[#103]: https://github.com/ergebnis/classy/pull/103
[#231]: https://github.com/ergebnis/classy/pull/231
[#235]: https://github.com/ergebnis/classy/pull/235
[#343]: https://github.com/ergebnis/classy/pull/343

[@ergebnis]: https://github.com/ergebnis
[@localheinz]: https://github.com/localheinz
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
COMPOSER_ROOT_VERSION:=1.0-dev
MIN_COVERED_MSI:=86
MIN_MSI:=85
MIN_MSI:=84

.PHONY: it
it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets
Expand Down
13 changes: 9 additions & 4 deletions src/Constructs.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ public static function fromSource(string $source): array
$count = \count($sequence);
$namespacePrefix = '';

$namespaceSegmentOrNamespaceToken = \T_STRING;
$namespaceSegmentOrNamespaceTokens = [
\T_STRING,
];

// https://wiki.php.net/rfc/namespaced_names_as_token
if (\PHP_VERSION_ID >= 80000 && \defined('T_NAME_QUALIFIED')) {
/** @var int $namespaceSegmentOrNamespaceToken */
$namespaceSegmentOrNamespaceToken = \T_NAME_QUALIFIED;
/** @var array<int> $namespaceSegmentOrNamespaceTokens */
$namespaceSegmentOrNamespaceTokens = [
\T_STRING,
\T_NAME_QUALIFIED,
];
}

for ($index = 0; $index < $count; ++$index) {
Expand All @@ -57,7 +62,7 @@ public static function fromSource(string $source): array
for ($index = self::significantAfter($index, $sequence, $count); $index < $count; ++$index) {
$token = $sequence[$index];

if (\is_array($token) && $namespaceSegmentOrNamespaceToken !== $token[0]) {
if (\is_array($token) && !\in_array($token[0], $namespaceSegmentOrNamespaceTokens, true)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Ergebnis;

class Foo {}

interface Bar {}

trait Baz {}
8 changes: 8 additions & 0 deletions test/Unit/ConstructsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ private function casesWithClassyConstructs(): array
'Ergebnis\\Classy\\Test\\Fixture\\Classy\\WithinMultipleNamespaces\\Foo\\Foo',
],
],
'within-namespace-with-single-segment' => [
__DIR__ . '/../Fixture/Classy/WithinNamespaceWithSingleSegment/source.php',
[
'Ergebnis\\Bar',
'Ergebnis\\Baz',
'Ergebnis\\Foo',
],
],
'with-methods-named-after-keywords' => [
__DIR__ . '/../Fixture/Classy/WithMethodsNamedAfterKeywords/source.php',
[
Expand Down

0 comments on commit 72840bd

Please sign in to comment.