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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/tests export-ignore
/phpunit.xml export-ignore
/docs export-ignore
/AGENTS.md export-ignore
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,35 @@ jobs:
fi
php docs/static-analysis/check-selection-report.php "$RUNNER_TEMP/selection-positive.json"

- name: Check composite type contracts
run: |
phpstan analyse --level=max --no-progress --autoload-file=vendor/autoload.php \
src/EnumComposite.php src/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 \
docs/static-analysis/composite-negative.php > "$RUNNER_TEMP/composite-negative.json" || status=$?
if [ "$status" -ne 1 ]; then
exit 1
fi
php -r '
$report = json_decode(file_get_contents($argv[1]), true, flags: JSON_THROW_ON_ERROR);
$lines = [];
foreach ($report["files"] as $file => $result) {
foreach ($result["messages"] as $message) {
echo $message["line"], ": ", $message["message"], PHP_EOL;
if (($message["identifier"] ?? null) !== "argument.type") {
exit(1);
}
$lines[] = $message["line"];
}
}
sort($lines);
if ($report["totals"]["errors"] !== 0 || $lines !== [16, 17, 18, 19]) {
exit(1);
}
' "$RUNNER_TEMP/composite-negative.json"

- name: Run PHPUnit
run: vendor/bin/phpunit

Expand Down
86 changes: 86 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Agent Guidelines

## Design Philosophy

**Same enum, different behavior.**

- Extend native enums through composition rather than replacing them.
- Preserve native enum identity and logical values. Keep identity, structural equality, presentation, behavior, and context distinct.
- Prefer native PHP features when sufficient; introduce abstractions only when they provide meaningful benefits.
- Respect class-based enums as an independent abstraction.

## Architecture

- Separate responsibilities and use composition, inheritance, and strategy according to the needs of each abstraction.
- Avoid unnecessary dependencies between abstractions. Use explicit construction contracts for extensible classes.
- Consult the [architecture decision records](docs/adr/README.md) before changing established design decisions.
- Distinguish accepted decisions from proposed or superseded designs. A proposed ADR is not an implementation request or an implemented specification.

## Coding Style

Follow [EnumEx Coding Style](docs/coding-style.md). Preserve intentional alignment and semantic whitespace; avoid blanket formatting changes. Use modern PHP features appropriate to the supported PHP versions.

## Type Safety and Static Analysis

- Prefer precise native types and PHPDoc generics where they express the actual contract.
- Preserve strict comparison and avoid unintended scalar coercion.
- Do not unnecessarily change natural PHP code or public APIs solely to accommodate analyzer limitations.
- Prefer narrowly scoped, justified annotations when analyzer-specific workarounds are necessary. Do not suppress unrelated diagnostics.

See [Static Analysis](docs/static-analysis/README.md).

## Documentation

- Keep implementation, PHPDoc, README files, executable examples, and tests consistent.
- Include concrete usage examples in public API documentation where practical.
- Preserve the historical documentation of class-based enums.
- Record significant architectural decisions in ADRs, including context, alternatives, rationale, and status.

## Testing and Validation

- Follow the validation steps in [.github/workflows/ci.yml](.github/workflows/ci.yml).
- Run PHPUnit, executable examples with assertions enabled, relevant static-analysis checks, and distribution archive checks as applicable.
- Verify compatibility with all supported PHP versions (currently PHP 8.4 and 8.5).
- Never report checks as successful unless actually executed or verified. Distinguish failures, known pre-existing diagnostics, and checks not performed.

## Public API Compatibility

Treat released public APIs as compatibility commitments. Do not introduce breaking changes without explicit justification and maintainer approval. Avoid silently changing the meaning of existing operations or discarding caller-supplied information.

## Security and Privacy

Never expose confidential, sensitive, personal, or environment-specific information in the public repository or associated development activities.

Do not publish:

- Credentials, passwords, API tokens, access keys, private keys, or sensitive environment variable values.
- Personal information not explicitly intended for publication.
- Actual absolute local filesystem paths, home directory paths, local usernames, or machine-specific identifiers.
- Private hostnames, internal network addresses, or environment-specific configuration.
- Private repository contents, unpublished design documents, or internal handover notes.
- Unredacted logs, stack traces, screenshots, or diagnostic output containing sensitive information.

Use repository-relative paths, fictional examples, and neutral placeholders such as `<project-root>` and `<username>` instead of actual environment-specific information.

These restrictions apply to code, comments, documentation, tests, fixtures, commit messages, pull requests, issues, reviews, CI output, and published artifacts. Inspect the intended diff and public output before committing, pushing, or posting. Do not include secrets or private information in a report about a potential disclosure; notify the maintainer through an appropriate non-public channel without reproducing sensitive values.

Do not rewrite published history or take destructive remediation actions without explicit authorization.

## Development Workflow

- Distinguish design consultation, agreed design decisions, and implementation requests.
- Inspect the current implementation, relevant ADRs, and branch state before making changes.
- Keep changes focused on the requested scope. Do not implement unrelated proposals.
- Evaluate review findings against the intended design rather than applying them mechanically.
- Commit, push, open or merge pull requests, publish releases, or modify repository settings only within the maintainer's authorization. Do not rewrite published tags or history without explicit authorization.

### Independent Reviews

When assigned to independently review a pull request:

- Review the actual diff and surrounding implementation at the current PR head. Assess correctness, design contracts, compatibility, type safety, tests, documentation, and security as relevant.
- Verify independently rather than assuming the author's claims or existing CI results establish correctness. Record the reviewed commit and checks performed, including limitations.
- Report actionable findings with severity, repository-relative file and line references, a concrete explanation, and a reproduction or test where practical. Distinguish defects from suggestions and unresolved design questions.
- Do not modify the implementation, push fixes, or merge the PR unless separately authorized.
- **Post the review outcome as a comment on the target GitHub pull request after completing the review, even when no actionable findings are identified.** A chat-only report does not complete the review. Use a PR review or PR conversation comment, and include the overall conclusion, findings or absence of findings, verification results, and remaining risks.
- Follow the Security and Privacy rules when posting. If posting is unavailable, report that limitation and provide a sanitized comment draft; do not claim that it was posted.
Loading