Home

Awesome

Advent of Code solutions in PHP by TBali

php v8.3 build AoC stars license

Installation

The solutions are using only the standard php library, they have NO 3rd-party package dependencies. However, Composer is used for its class autoloader:

composer install

Note: Some solutions require more memory than what a default PHP installation provides, so it is recommended to set memory_limit = -1 in php.ini.

Batch solution runner

Run solutions from the project base directory with:

php src/aoc.php [LANGUAGE] [YEAR] [DAY]
ArgumentEffect
LANGUAGE giveninvoke interpreter with standalone solution scripts
all given as the LANGUAGEinvoke standalone solution scripts in all languages
LANGUAGE not giveninvoke class-based PHP solutions
none of YEAR and DAY givenrun all solutions
only YEAR givenrun all solutions for that season only
both YEAR and DAY givenrun a specific solution

On Windows, the shortcut .\aoc.bat [LANGUAGE] [YEAR] [DAY] also works.

Possible values for LANGUAGE: all, dart, f#, go, groovy, java, javascript, lua, perl, php, python, ruby, scala.

Puzzle input

Class-based PHP solutions

Standalone script-based solutions

Custom Composer scripts

The following helper commands are defined in composer.json:

CommandDescription
startRun all solutions with AocRunner
testRun solutions and create test coverage report with PHPUnit
csCheck coding style compliance to PSR12 with PHP_CodeSniffer
cs-fixerCheck coding style compliance to PSR12 plus extra rules with PHP-CS-Fixer (no fix applied)
cs-fixer-doApply coding style fixes with PHP-CS-Fixer
docCreate documentation with phpDocumentor
lintCheck syntax errors with Parallel-Lint
locGet code summary report with phploc
metricsGenerate code metrics report with PhpMetrics
stanRun static analysis with PHPStan
qaRun code quality checks: PHP_CodeSniffer, PHP-CS-Fixer, PHPStan
qa-fullRun all code quality checks: PHP_CodeSniffer, PHP-CS-Fixer, PHPStan, Parallel-Lint, PhpMetrics, phpDocumentor, PHPUnit, and run all solutions
open-coverOpen generated test coverage report in browser (fixed file path)
open-docOpen generated documentation in browser (fixed file path)
open-metricsOpen generated code metrics report in browser (fixed file path)
cleanDelete generated cache and report files in .tools and docs directories (Windows only)

Note: The above tools are NOT listed in composer.json as dev dependencies. Instead, the commands must be available in the PATH. See minimum version requirements in the config files.