Skip to content

Instantly share code, notes, and snippets.

@alexander-schranz
Last active October 25, 2023 13:50
Show Gist options
  • Save alexander-schranz/6b4d7a97c3f050dc08aede7156ab9f75 to your computer and use it in GitHub Desktop.
Save alexander-schranz/6b4d7a97c3f050dc08aede7156ab9f75 to your computer and use it in GitHub Desktop.
PHP Tools default cache files and directories

PHP Tool Cache Files and Directories

Collecting here which PHP Tools use caches here and for which usecase.

The widely used sys_get_temp_dir() method represents TMPDIR environment variable if not specially sys_temp_dir is defined in the php.ini file.

PHPStan

Can avoid reanalyzing unrelated files:

sys_get_temp_dir() . '/phpstan/'

Documentation: https://phpstan.org/config-reference#caching

Rector

Can avoid reanalyzing unrelated files:

sys_get_temp_dir() . '/rector_cached_files/'

Requires to be enabled in CI.

Documentation: https://getrector.com/documentation/cache-in-ci

PHPCSFixer

Avoid reanalyzing unchanged files:

getcwd() . '/.php-cs-fixer.cache'

Documentation: https://cs.symfony.com/doc/usage.html#caching

PHPUnit

Can be used to rerun defects:

getcwd() . '/.phpunit.result.cache'

Documentation: https://docs.phpunit.de/en/9.6/configuration.html?highlight=cache#the-cacheresult-attribute

Deptrac

Avoid reanalyzing unchanged files:

getcwd() . '/.deptrac.cache'

Documentation: https://github.com/qossmic/deptrac/blob/main/docs/configuration.md#parameters

Twig CS Fixer

getcwd() . '/.twig-cs-fixer.cache'

Documentation: https://github.com/VincentLanglet/Twig-CS-Fixer#cache

# HINT: The repository need to "Disable" "Use separate caches for protected branches" in the "CI/CD Settings"
# else no cache is reused from protected branches, which we want to speedup the merge requests.
stages:
- Install
- Test
workflow:
rules:
# https://docs.gitlab.com/ee/ci/caching/#use-a-variable-to-control-a-jobs-cache-policy
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
CACHE_POLICY: pull # on non default branches caches are only
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE != "merge_request_event"
variables:
CACHE_POLICY: pull-push # on default branch caches are updated
- when: never
Lint:
stage: Test
needs:
- Install
image: php:8.1.18-cli
cache:
# add some cache to speed up the linting specially avoid rector timeouts
# see also https://docs.gitlab.com/ee/ci/caching/#use-the-same-cache-for-all-branches to active cache between protected and nonprotected branches
- key: cache-lint-php
policy: $CACHE_POLICY
paths:
- /tmp/phpstan/
- /tmp/rector_cached_files/
- .php-cs-fixer.cache
- .deptrac.cache
- .twig-cs-fixer.cache
# before_script:
# - echo 'sys_temp_dir = "/tmp" >> /usr/local/etc/php/conf.d/zz-custom.ini
script:
- php composer.phar lint
Test:
stage: Test
needs:
- Install
tags:
- large
image: php:8.1.18-cli
services:
- postgres:13-alpine
variables:
APP_ENV: test
before_script:
- apt-get update && apt-get install -y libpq-dev
- docker-php-ext-install pdo_pgsql
- docker-php-ext-enable pcov
- php composer.phar bootstrap-test-environment
script:
- php composer.phar test-with-coverage
- php composer.phar check-coverage
artifacts:
name: code-coverage
expire_in: 72 hours
when: always
paths:
- .phpunit.result.cache
- var/reports/html
reports:
junit: var/reports/junit.xml
Install:
stage: Install
image: composer:latest
script:
- composer install --no-interaction --prefer-dist --no-scripts --ignore-platform-req="php" --ignore-platform-req="ext-intl" --ignore-platform-req="ext-gd" --ignore-platform-req="ext-xsl" --ignore-platform-req="ext-sysvsem"
- composer dump-autoload --optimize --classmap-authoritative
- curl --show-error --silent https://getcomposer.org/installer | php
artifacts:
name: composer-dependencies
expire_in: 24 hours
paths:
- vendor
- composer.phar
cache:
key: composer
paths:
- .composer-cache/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment