feat: initial commit of camelia/controllers

Framework-agnostic REST controller toolkit in vanilla PHP.

- Router with path parameters, 404 and 405 with an Allow header.
- Immutable Request, JsonRequest and Response; nothing is printed.
- CrudController over a ResourceGateway port the application implements.
- Composable Middleware/Pipeline chain.
- Security middlewares: BearerAuth, RequireRole, RateLimit, Cors.
- Transport middlewares: Logging, ContentNegotiation.
- Nine typed HTTP exceptions with snake_case JSON bodies.
- Declares PHP >=8.3 and no dependency on an ORM: ports are local.
- MIT license.
This commit is contained in:
dgarcia committed 2026-11-15 10:14:27 -03:00
commit 341d1bdc2c
52 files changed
+7552

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
# Mago toolchain configuration — camelia/controllers
# Docs: https://mago.carthage.software
# The library promises PHP >= 8.3. Pinning the parser to 8.2 keeps the formatter from emitting
# syntax the package cannot ship (for example `new Foo()->bar()`, which needs 8.4).
php-version = "8.2"
[source]
paths = ["src", "tests"]
includes = ["vendor"]
excludes = ["vendor", ".phpunit.cache", ".mago.cache"]
extensions = ["php"]
[formatter]
print-width = 100
tab-width = 4
use-tabs = false
end-of-line = "lf"
single-quote = true
trailing-comma = true
remove-trailing-close-tag = true
function-brace-style = "next-line"
method-brace-style = "next-line"
classlike-brace-style = "always-next-line"
# Disabled: this option rewrites `(new Foo())->bar()` into `new Foo()->bar()`, which is a PHP parse
# error whenever the result is assigned or returned. Reproduced with mago 1.60.1 on every run, so the
# key is turned off until the formatter is fixed upstream. Keep the parentheses: valid PHP.
first-method-chain-on-new-line = false
[analyzer]
# Tests are excluded from the Mago analyzer: they extend PHPUnit\Framework\TestCase and Mago does
# not load Composer's autoloader for external packages, so every test would report a false
# "non-existent class". PHPStan covers tests with the Composer autoloader available.
excludes = ["tests"]
find-unused-expressions = true
find-unused-definitions = true
find-unused-parameters = true
strict-list-index-checks = true
strict-array-index-existence = true
check-missing-type-hints = true
check-closure-missing-type-hints = true
check-use-statements = true
check-property-initialization = true
check-dead-catch = true
# Disabled: controllers are a thin translation layer whose contract is "every failure becomes a
# typed HTTP error". Annotating @throws on every handler would restate that design instead of
# documenting it. Consumers rely on the error-mapping table, not on per-method annotations.
check-throws = false
# Disabled: the boolean parameters left in the public API describe request data (whether a field is
# nullable, whether a route is the collection root), not a "do X or do Y" switch. Splitting them
# would duplicate every call site for no readability gain.
[linter.rules.no-boolean-flag-parameter]
enabled = false
# Disabled: this rule would turn every integer, bool and null literal argument into a named
# argument. For PHP standard-library calls such as substr($s, 0, 12) the parameter name adds noise
# without adding clarity and makes the diff unreadable.
[linter.rules.literal-named-argument]
enabled = false
# Disabled: every isset() here checks key existence in a map whose values are never null (route
# params, parsed body fields, header maps). isset() is the idiomatic and faster form for that case.
[linter.rules.no-isset]
enabled = false
# Disabled: readability proxies without an actionable change in this codebase.
[linter.rules.inline-variable-return]
enabled = false
[linter.rules.no-multi-assignments]
enabled = false
# Metric thresholds are raised on purpose, mirroring ../orm.
#
# Router, CrudController and the CrudController test mirror the public API contract: one method per
# route operation and one test per rule. Splitting them would duplicate the routing and metadata
# plumbing this design deliberately keeps in one place. The same reasoning applies to the request
# value objects, whose constructor parameters are the request parts (method, path, query, body,
# headers, attributes) rather than a control-flow switch.
[linter.rules.too-many-methods]
threshold = 20
[linter.rules.excessive-parameter-list]
threshold = 8
[linter.rules.cyclomatic-complexity]
threshold = 90
method-threshold = 20
# Disabled: every flagged parameter is the `$token` argument of a test closure built to exercise
# BearerAuth. The library marks its own sensitive parameters where they matter; repeating the
# attribute across test doubles adds noise without changing runtime behaviour.
[linter.rules.sensitive-parameter]
enabled = false