Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Check composite type contracts
run: |
phpstan analyse --level=max --no-progress --autoload-file=vendor/autoload.php \
src/EnumComposite.php src/EnumCompositeBuilder.php \
src/Extension/Composite/EnumComposite.php src/Extension/Composite/EnumCompositeBuilder.php \
examples/NativeExtension/Composite/EnumComposite.php docs/static-analysis/composite-positive.php
status=0
phpstan analyse --level=max --no-progress --error-format=json --autoload-file=vendor/autoload.php \
Expand Down
74 changes: 40 additions & 34 deletions README.md

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: php-enumex

services:
php:
image: php-enumex:local
image: ${COMPOSE_PROJECT_NAME}:local
pull_policy: never
container_name: php-enumex_php
volumes:
- .:/var/www/php-enumex
working_dir: /var/www/php-enumex
Expand All @@ -14,16 +15,13 @@ services:
- -c
- |
exec tail -f /dev/null
networks:
- php-enumex

composer:
image: php-enumex:local
image: ${COMPOSE_PROJECT_NAME}:local

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Handle Compose project names that are invalid Docker repository names

docker compose -p review_ config accepts the project name and resolves both images to review_:local, but docker compose -p review_ build composer fails with invalid reference format. The README presents -p as the way to isolate a checkout, so an otherwise valid override can prevent startup. Putting the project name in the tag of a fixed repository avoids this separator mismatch. I verified that both services start with php-enumex:${COMPOSE_PROJECT_NAME} and a project name ending in _. Compose project-name rules

build:
context: ./docker/php
args:
TIMEZONE: Asia/Tokyo
container_name: php-enumex_composer
environment:
COMPOSER_CACHE_DIR: /root/.cache/composer
volumes:
Expand All @@ -35,12 +33,6 @@ services:
- -c
- |
exec composer install --optimize-autoloader --no-interaction
networks:
- php-enumex

volumes:
composer-cache:

networks:
php-enumex:
name: php-enumex
34 changes: 34 additions & 0 deletions docs/adr/0012-organize-native-enum-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ADR 0012: Organize native enum extensions by concept

- Status: Accepted (for the next major development cycle; release version remains a separate decision)
- Date: 2026-12-03
- Related: ADR 0001, 0002, 0006, 0008, 0010, 0011

## Context

Native enum extension classes currently share the root package namespace. EnumCase, EnumCollection and EnumComposite are distinct concepts, but all extend native enum behavior through composition. Class-based Enum is a separate abstraction with its own historical contract; native enum traits add methods directly to enums. Composite already includes policy types and a builder. Collection may later gain a lazy view (ADR 0008). Organizing the API solely by current file count risks repeated namespace changes as these concepts evolve.

## Decision

Use `Notonza\PhpEnumEx\Extension` for external extensions of native enums, with concept-specific namespaces:

| Namespace relative to package root | Types |
| --- | --- |
| Extension\Case | EnumCase |
| Extension\Collection | EnumCollection |
| Extension\Composite | EnumComposite, EnumCompositeBuilder, CompositeOrder, CompositeDuplicates |

Mirror these namespaces under src/ using the existing PSR-4 mapping. Retain EnumTraits, ClassBased (including Exceptions), and Internal at their existing locations. Internal is for shared implementation details, not a public extension API. Keep class names and method contracts unchanged. Class-based nameToElement() remains supported.

A namespace may contain only one class: conceptual independence, not file count, determines its boundary. Add new concept namespaces when concrete needs justify them; do not pre-create empty directories or introduce speculative abstractions. A lazy collection view, specialized composite contracts, flags or enum-keyed maps are possible directions, not accepted features or API commitments.

## Alternatives

- Keep root-level types: concise imports, but weak grouping as extension concepts acquire related types.
- Move only composite support types: preserves short imports for principal types but separates the composite from its own policies and builder.
- Use Case, Collection and Composite directly under the package root: expresses concept boundaries but not their shared role as native enum extensions distinct from ClassBased and EnumTraits.
- Place Composite beside Extension: rejected because composite is itself a native enum extension.

## Consequences

Imports, fully qualified references, documentation, test fixtures and static-analysis paths must follow the new namespaces. This is a breaking namespace change intended for the next major release. Do not add compatibility aliases without a separate decision; v2 remains available at its release tag. Persisted class names and serialized objects referencing the old names may require application-level migration. Historical ADRs retain their original context and names; this record supersedes their previous namespace placement where applicable. The new structure does not change runtime semantics or establish any new collection or composite feature.
1 change: 1 addition & 0 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ These records capture the motivation and decisions behind PHP EnumEx, including
| [0009](0009-documentation-and-extension-composition.md) | Explain common enum behavior and composition through useful examples | Proposed |
| [0010](0010-composite-enum-cases.md) | Explore a composite of native enum cases | Proposed |
| [0011](0011-mapping-and-qualified-formatting.md) | Explicit mapping and qualified formatting APIs | Proposed |
| [0012](0012-organize-native-enum-extensions.md) | Organize native enum extensions by concept | Accepted |

Accepted means the architectural direction has been agreed. Open implementation details are identified separately and must not be treated as finalized API contracts. Amend or supersede these records when decisions change.
2 changes: 1 addition & 1 deletion docs/static-analysis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The composite check analyses the implementation, executable example and positive

```sh
phpstan analyse --level=max --autoload-file=vendor/autoload.php \
src/EnumComposite.php src/EnumCompositeBuilder.php \
src/Extension/Composite/EnumComposite.php src/Extension/Composite/EnumCompositeBuilder.php \
examples/NativeExtension/Composite/EnumComposite.php docs/static-analysis/composite-positive.php
phpstan analyse --level=max --autoload-file=vendor/autoload.php docs/static-analysis/composite-negative.php
```
Expand Down
4 changes: 2 additions & 2 deletions docs/static-analysis/collection-negative.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace EnumExStaticAnalysisNegative;

use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

enum Status {
case Paid;
Expand Down
8 changes: 4 additions & 4 deletions docs/static-analysis/collection-positive.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace EnumExStaticAnalysis;

use Closure;
use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;
use function PHPStan\Testing\assertType;

enum Status {
Expand Down Expand Up @@ -43,11 +43,11 @@ function checkFactory(Closure $factory): void {
}

$default = EnumCollection::of(Status::class);
assertType('Notonza\PhpEnumEx\EnumCase<EnumExStaticAnalysis\Status>', $default->fromName('Paid'));
assertType('Notonza\PhpEnumEx\Extension\Case\EnumCase<EnumExStaticAnalysis\Status>', $default->fromName('Paid'));
assertType('EnumExStaticAnalysis\Status', $default->fromName('Paid')->unwrap());

$explicit = $default->wrapCasesAs(EnumCase::of(...));
assertType('Notonza\PhpEnumEx\EnumCase<EnumExStaticAnalysis\Status>', $explicit->fromName('Paid'));
assertType('Notonza\PhpEnumEx\Extension\Case\EnumCase<EnumExStaticAnalysis\Status>', $explicit->fromName('Paid'));
assertType('EnumExStaticAnalysis\Status', $explicit->fromName('Paid')->unwrap());

$custom = EnumCollection::of(Status::class)->wrapCasesAs(static fn (Status $case) => new LocalizedStatus($case, 'ja'));
Expand Down
2 changes: 1 addition & 1 deletion docs/static-analysis/composite-negative.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace EnumExStaticAnalysisCompositeNegative;

use Notonza\PhpEnumEx\EnumComposite;
use Notonza\PhpEnumEx\Extension\Composite\EnumComposite;

enum Status {
case Paid;
Expand Down
18 changes: 9 additions & 9 deletions docs/static-analysis/composite-positive.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace EnumExStaticAnalysisComposite;

use Notonza\PhpEnumEx\CompositeDuplicates;
use Notonza\PhpEnumEx\CompositeOrder;
use Notonza\PhpEnumEx\EnumComposite;
use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates;
use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder;
use Notonza\PhpEnumEx\Extension\Composite\EnumComposite;
use function PHPStan\Testing\assertType;

enum Status {
Expand Down Expand Up @@ -36,16 +36,16 @@ public function __construct(
$builder = EnumComposite::as(CompositeOrder::Insensitive);
$custom = new Policy(Status::Paid, Role::Admin);

assertType('Notonza\PhpEnumEx\EnumComposite', $standard);
assertType('Notonza\PhpEnumEx\EnumCompositeBuilder', $builder);
assertType('Notonza\PhpEnumEx\EnumComposite', $builder->of(Status::Paid, Role::Admin));
assertType('Notonza\PhpEnumEx\EnumComposite', Policy::of(Status::Paid, Role::Admin));
assertType('Notonza\PhpEnumEx\EnumComposite', Policy::as()->of(Status::Paid, Role::Admin));
assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', $standard);
assertType('Notonza\PhpEnumEx\Extension\Composite\EnumCompositeBuilder', $builder);
assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', $builder->of(Status::Paid, Role::Admin));
assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', Policy::of(Status::Paid, Role::Admin));
assertType('Notonza\PhpEnumEx\Extension\Composite\EnumComposite', Policy::as()->of(Status::Paid, Role::Admin));

assertType('list<UnitEnum>', $standard->unwrap());
assertType('UnitEnum', $standard->at(0));
assertType('ArrayIterator<int, UnitEnum>', $standard->getIterator());
assertType('Notonza\PhpEnumEx\CompositeOrder', $standard->order());
assertType('Notonza\PhpEnumEx\Extension\Composite\CompositeOrder', $standard->order());

foreach ($standard as $index => $case) {
assertType('int', $index);
Expand Down
4 changes: 2 additions & 2 deletions examples/NativeExtension/Backed/ByteUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

require_once __DIR__ . '/../../../vendor/autoload.php';

use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

enum ByteUnit: int {
case BYTE = 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/NativeExtension/Backed/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_once __DIR__ . '/../../../vendor/autoload.php';

use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;

enum Currency: string {
case JPY = 'JPY';
Expand Down
4 changes: 2 additions & 2 deletions examples/NativeExtension/Collections/FilePermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

require_once __DIR__ . '/../../../vendor/autoload.php';

use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

enum NoPermission {
}
Expand Down
6 changes: 3 additions & 3 deletions examples/NativeExtension/Composite/ConstructionPolicies.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

use InvalidArgumentException;
use LogicException;
use Notonza\PhpEnumEx\CompositeDuplicates;
use Notonza\PhpEnumEx\CompositeOrder;
use Notonza\PhpEnumEx\EnumComposite;
use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates;
use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder;
use Notonza\PhpEnumEx\Extension\Composite\EnumComposite;

enum WorkflowStep {
case Prepare;
Expand Down
6 changes: 3 additions & 3 deletions examples/NativeExtension/Composite/EnumComposite.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
require_once __DIR__ . '/../../../vendor/autoload.php';

use InvalidArgumentException;
use Notonza\PhpEnumEx\CompositeDuplicates;
use Notonza\PhpEnumEx\CompositeOrder;
use Notonza\PhpEnumEx\EnumComposite;
use Notonza\PhpEnumEx\Extension\Composite\CompositeDuplicates;
use Notonza\PhpEnumEx\Extension\Composite\CompositeOrder;
use Notonza\PhpEnumEx\Extension\Composite\EnumComposite;

enum Country {
case Japan;
Expand Down
2 changes: 1 addition & 1 deletion examples/NativeExtension/Composition/OrderStatusBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use Examples\NativeExtension\Presentation\OrderStatus;
use Examples\NativeExtension\Presentation\OrderStatusPresentation;
use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;

/** @extends EnumCase<OrderStatus> */
final readonly class OrderStatusBadge extends EnumCase {
Expand Down
2 changes: 1 addition & 1 deletion examples/NativeExtension/External/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum PaymentStatus: string {
require_once __DIR__ . '/../../../vendor/autoload.php';

use Examples\NativeExtension\External\Vendor\PaymentStatus;
use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;

/** @extends EnumCase<PaymentStatus> */
final readonly class PaymentStatusPolicy extends EnumCase {
Expand Down
2 changes: 1 addition & 1 deletion examples/NativeExtension/Inheritance/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require_once __DIR__ . '/../../../vendor/autoload.php';

use BackedEnum;
use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;

enum ArticlePermission: int {
case Read = 1;
Expand Down
4 changes: 2 additions & 2 deletions examples/NativeExtension/Presentation/OrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
require_once __DIR__ . '/../../../vendor/autoload.php';

use DomainException;
use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

enum OrderStatus {
case Pending;
Expand Down
4 changes: 2 additions & 2 deletions examples/NativeExtension/Strategies/AirmailPostage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

require_once __DIR__ . '/../../../vendor/autoload.php';

use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

enum AirmailWeight: int {
case UpTo25Grams = 25;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_once __DIR__ . '/AirmailPostage.php';

use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

enum AirmailRegion {
case Asia;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_once __DIR__ . '/AirmailPostage.php';

use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

final class AirmailRateFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

require_once __DIR__ . '/AirmailPostage.php';

use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;

final class AirmailRate {

Expand Down
2 changes: 1 addition & 1 deletion src/EnumCase.php → src/Extension/Case/EnumCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Notonza\PhpEnumEx;
namespace Notonza\PhpEnumEx\Extension\Case;

use Notonza\PhpEnumEx\Internal\CaseFormatter;
use Notonza\PhpEnumEx\Internal\NativeCaseValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

declare(strict_types=1);

namespace Notonza\PhpEnumEx;
namespace Notonza\PhpEnumEx\Extension\Collection;

use Closure;
use Countable;
use Generator;
use InvalidArgumentException;
use IteratorAggregate;
use LogicException;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Internal\CaseFormatter;
use Notonza\PhpEnumEx\Internal\NativeCasePredicate;
use Notonza\PhpEnumEx\Internal\NativeCaseValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Notonza\PhpEnumEx;
namespace Notonza\PhpEnumEx\Extension\Composite;

/** Determines how repeated native cases are handled during construction. */
enum CompositeDuplicates {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Notonza\PhpEnumEx;
namespace Notonza\PhpEnumEx\Extension\Composite;

/** Determines whether order matters in policy-based composite equality. */
enum CompositeOrder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Notonza\PhpEnumEx;
namespace Notonza\PhpEnumEx\Extension\Composite;

use ArrayIterator;
use Countable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Notonza\PhpEnumEx;
namespace Notonza\PhpEnumEx\Extension\Composite;

use Closure;
use UnitEnum;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/NativeCasePredicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Notonza\PhpEnumEx\Internal;

use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Closure;
use Generator;
use UnitEnum;
Expand Down
4 changes: 2 additions & 2 deletions tests/NativeCollection/EnumCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use InvalidArgumentException;
use LogicException;
use Notonza\PhpEnumEx\EnumCase;
use Notonza\PhpEnumEx\EnumCollection;
use Notonza\PhpEnumEx\Extension\Case\EnumCase;
use Notonza\PhpEnumEx\Extension\Collection\EnumCollection;
use Notonza\PhpEnumEx\EnumTraits\EnumCollections;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand Down
Loading