This document provides a guide for software engineering agents working on the Intervention Gif codebase.
intervention/gif -- Native PHP GIF encoder/decoder library. Parses and generates GIF binary data. Part of the Intervention Image ecosystem.
- Language: PHP 8.3+ | Namespace:
Intervention\Gif
The codebase mirrors the GIF89a binary specification. Each GIF format block has three corresponding classes:
src/Blocks/<Name>.php-- Data model (value object)src/Decoders/<Name>Decoder.php-- Binary stream readersrc/Encoders/<Name>Encoder.php-- Binary stream writer
Encoder/decoder resolution is convention-based via CanDecode/CanEncode traits.
All block models extend AbstractEntity (which implements Stringable).
The project uses Composer to manage dependencies. These dependencies are installed automatically when using the Docker test runners.
The following commands are used to ensure code quality and correctness.
The project uses PHPUnit for unit and feature testing.
-
Run all tests:
docker compose run --rm tests
-
Run a single test file: To run a specific test file, provide the path to the file.
docker compose run --rm tests tests/Unit/BuilderTest.php
-
Run a single test method: Use the
--filteroption to run a specific test method by its name.docker compose run --rm tests tests/Unit/BuilderTest.php --filter testMethodName
-
Check test coverage:
docker compose run --rm coverage
PHPStan is used for static analysis to find potential bugs.
- Run static analysis:
docker compose run --rm analysis
The project adheres to the PSR-12 coding standard with additional rules. PHP CodeSniffer is used to enforce these standards.
- Check for coding standard violations:
docker compose run --rm standards
Consistency is key. Adhere to the following guidelines when writing code.
- PSR-12: The primary coding standard is PSR-12.
- Indentation: Use 4 spaces for indentation, not tabs.
- Line Endings: Use Unix-style line endings (LF).
- Strict Types: All PHP files must start with
declare(strict_types=1);. - Class Structure: Follow the ordering defined in
phpcs.xml:usesenum casesconstantsstatic propertiespropertiesconstructorstatic constructorsmethodsmagic methods
- Classes:
PascalCase. - Methods:
camelCase. - Variables:
camelCase. - Constants:
UPPER_CASEwith underscore separators. - File Names: File names must match the class name they contain (e.g.,
MyClass.phpforclass MyClass).
- One class per
usestatement: Do not group multiple classes in a singleusestatement. - No leading backslash:
usestatements must not start with a backslash. - Order:
usestatements should be ordered alphabetically. Unused imports must be removed.
- Strict Typing: All code should be strictly typed.
- Parameter Types: All method parameters must have a type hint.
- Return Types: All methods must have a return type hint.
- Property Types: All class properties must have a type hint.
- Nullable Types: Use nullable types (
?TypeName) when anullvalue is explicitly allowed.
- Exceptions should be used for error handling.
- When catching exceptions, be as specific as possible. Avoid catching generic
\Exceptionor\Throwable. - Exception messages should be clear and descriptive.
- PHPDoc blocks are required for all classes, properties, and methods.
- Follow the annotation order defined in
phpcs.xml. - Use DocBlocks to provide context and explain complex logic. Do not restate the obvious from the code signature.