Skip to content

Commit

Permalink
Merge branch 'develop' into DEV-71-replace-drupal-check-with-phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
becw committed Feb 20, 2025
2 parents bc372eb + cea5973 commit 4ae9b56
Show file tree
Hide file tree
Showing 20 changed files with 272 additions and 497 deletions.
15 changes: 11 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
build:
working_directory: ~/project
docker:
- image: cimg/php:8.1.18-browsers
- image: cimg/mysql:5.7
- image: cimg/php:8.3-browsers
- image: cimg/mysql:8.0
command: --max_allowed_packet=16M
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
Expand All @@ -17,6 +17,7 @@ jobs:
environment:
- PALANTIR_ENVIRONMENT: circleci
- DRUPAL_ROOT: docroot
- NODE_VERSION: 20

steps:
- run:
Expand All @@ -38,20 +39,26 @@ jobs:
name: Run code reviews
command: |
composer install --no-plugins
echo "phpstan for tasks"
vendor/bin/phpstan analyse src --level=2
composer run-script post-install-cmd
echo "phpcs for modules"
vendor/bin/phpcs defaults/standard/modules --standard="Drupal,DrupalPractice" -n --extensions="php,module,inc,install,test,profile,theme"
echo "phpmd for modules"
vendor/bin/phpmd defaults/standard/modules text defaults/standard/phpmd.xml --suffixes php,inc,module,theme,profile,install,test
echo "phpstan for modules"
vendor/bin/phpstan analyse defaults/standard/modules --level=2
echo "phpcs for tasks"
vendor/bin/phpcs src --standard="Drupal,DrupalPractice" -n --extensions="php,module,inc,install,test,profile,theme"
echo "phpmd for tasks"
vendor/bin/phpmd src text defaults/standard/phpmd.xml --suffixes php,inc,module,theme,profile,install,test
echo "phpstan for tasks"
vendor/bin/phpstan analyse src --level=2
# Install a drupal test project.
- run:
name: Create artifacts directory
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"cweagans/composer-patches": "^1.7",
"dmore/behat-chrome-extension": "^1.4",
"drupal/coder": "^8.3.6",
"drush/drush": ">=9",
"drush/drush": "^13",
"jangregor/phpstan-prophecy": "^1.0",
"mglaman/phpstan-drupal": "^1.2",
"palantirnet/phing-drush-task": "^1.1",
Expand All @@ -37,6 +37,7 @@
"allow-plugins": {
"cweagans/composer-patches": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phing/phing-composer-configurator": true,
"phpstan/extension-installer": true
}
},
Expand Down
24 changes: 7 additions & 17 deletions defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ build:
# The destination host, either 'acquia', 'pantheon', 'platformsh', or 'other'. This is
# currently only used when setting up the settings.php file for a Drupal site.
host: acquia
# Adding specific packages for specific host. One per line.
host_packages:
acquia:
- "typhonius/acquia-php-sdk-v2"

# Drupal configuration used by targets/drupal.xml
drupal:
Expand Down Expand Up @@ -134,9 +138,9 @@ drupal:
# $> gunzip -c FILENAME.sql.gz | drush sqlc
#
# Command to extract text contents of the backup file.
contents_command: gunzip -c
contents_command: gzip -dc
# Command to load database contents into Drupal.
mysql_command: drush sqlc
mysql_command: mysql --host=${drupal.site.database.host} --user=${drupal.site.database.username} --password=${drupal.site.database.password} --database=${drupal.site.database.database}

# Load a specific file rather than one matching the `export_pattern`. This can be used
# if your build relies on a seed database that is checked in to the repository.
Expand Down Expand Up @@ -191,14 +195,6 @@ acquia:
# Directory for storing downloaded database backups.
backups: artifacts/backups

# Max age of the downloaded backup database, in hours.
backup_age_hours: 24

# The Acquia Cloud hosting "realm" where the site is running.
# - Acquia Cloud Enterprise: 'prod'
# - Acquia Cloud Professional: 'devcloud'
realm: ""

# Acquia site/application name.
site: ""

Expand All @@ -209,12 +205,6 @@ acquia:
# Acquia environment to download backups from.
env: "prod"

# Acquia Cloud API credentials file, downloaded from your Acquia account. Do not check
# this file into your codebase.
cloud:
conf: "${env.HOME}/.acquia/cloudapi.conf"


# Configuration to use the PHP interpreter's built in linter to check for syntax errors
# and deprecated code. This property is used by the <phplint> task in the
# defaults/build.xml template.
Expand Down Expand Up @@ -259,7 +249,7 @@ phpmd:
# Output format for phpmd.
format: text
# Comma-separated list of ruleset paths or names.
rulesets: "${build.thebuild.dir}/defaults/standard/phpmd.xml"
rulesets: "${build.dir}/phpmd.xml"
# File extensions to review.
suffixes: php,inc,module,theme,profile,install,test

Expand Down
27 changes: 16 additions & 11 deletions defaults/install/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
build:
working_directory: ~/${projectname}
docker:
- image: cimg/php:8.1-browsers
- image: cimg/mysql:5.7
- image: cimg/php:8.3-browsers
- image: cimg/mysql:8.0
command: --max_allowed_packet=16M
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
Expand All @@ -20,7 +20,7 @@ jobs:
environment:
- PALANTIR_ENVIRONMENT: circleci
- DRUPAL_ROOT: ${drupal.root}
- NODE_VERSION: 8
- NODE_VERSION: 20

steps:
- run:
Expand Down Expand Up @@ -50,10 +50,11 @@ jobs:
name: Configure URL in /etc/hosts
command: echo 127.0.0.1 ${CIRCLE_PROJECT_REPONAME}.local | sudo tee -a /etc/hosts

# Composer package cache
# Package cache
- restore_cache:
keys:
- composer-v1-
- package-cache-v1-

# Source cache
- restore_cache:
keys:
Expand All @@ -64,15 +65,19 @@ jobs:
- run:
name: Composer install
command: composer install --no-interaction --prefer-dist
- run:
name: Yarn install
command: yarn install

# Composer package cache - update when the contents of the Composer cache directory
# change
- run: ls -1R ~/.cache/composer/ > /tmp/composer-cache.txt
# Package cache. This is updated when the contents of the ~/.cache directory change.
# Both Composer and Yarn use this directory.
- run: ls -1R ~/.cache/ > /tmp/package-cache.txt
- save_cache:
key: composer-v1-{{ checksum "/tmp/composer-cache.txt" }}
key: package-cache-v1-{{ checksum "/tmp/package-cache.txt" }}
paths:
- ~/.cache/composer
# Source cache - update when branch changes
- ~/.cache

# Source cache. This is updated for each different branch.
- save_cache:
key: source-v1-{{ .Branch }}
paths:
Expand Down
4 changes: 2 additions & 2 deletions defaults/install/.circleci/deploy-acquia-example
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
deploy:
working_directory: ~/project
docker:
- image: cimg/php:8.1-browsers
- image: cimg/php:8.3-browsers
environment:
- NODE_VERSION: 8
- NODE_VERSION: 20
- GITHUB_PUBKEY: "github.com,192.30.253.113 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
- ACQUIA_PUBKEY: "svn-23450.prod.hosting.acquia.com,54.245.120.237 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDit0Rj8j59i9Gj2vOg2TXjIbPswIc27PwncapyBLi9R3FtECXq+md1BfykBJjME83m78CtqkTlWwNZu+LyhF+IYlshKo82JXQzV4kWwi5L9H7KpdyFDMDLVCNVYmU4EQY9ngRq1cwbMBYsfWxv4sSlbsvZv2C8U7luNoc4SiBY4sGpgiMJLFOHWRw6YvhOamLTKfxSoJUT8uRbfkamxas1EK21XjvrdUSN0Bf5LmTdvs/9iIaUH4AlYr0SW0tc2IbIuoFVxuvSzZj2GJjmtCcW1poDMQLTGq+EuO4Mk1WyoUSJC9L8CFonKH7++EPHopvIbPMinO4r2zLEot3lL5TH"

Expand Down
4 changes: 2 additions & 2 deletions defaults/install/.circleci/deploy-pantheon.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
deploy:
working_directory: ~/project
docker:
- image: cimg/php:8.1-browsers
- image: cimg/php:8.3-browsers
environment:
- NODE_VERSION: 8
- NODE_VERSION: 20
- GITHUB_PUBKEY: "github.com,192.30.253.113 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="
- PANTHEON_PUBKEY: "[codeserver.dev.56f20816-b4b7-4517-a90f-667b4785708d.drush.in]:2222,[35.193.151.123]:2222 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSY3gnr0DrbqJJSnEFy6jazDmAdBm4Zs/EkWIQa7x31qgSYyYJMz5V+pk62lBf2BN42VtubwO83vW9G+yG2K1RGOvZJaK5GBvBb/Ws2ZPcp/4sNHpPzkdd75e5/Pk8AWA59XUbJcBWmrDrHMbWV1j2zqPPikxbqGeTTjSx4QR18LIRei5OwT6VQnaVnJqPAqFZ+oCbpr0DL96foL3UEY8EWT/6GH2cANEGZO4ppbhdDw4uG6TaI7S0lxWMQEVy+iwjCNH/nanjd73cwoYd90E0OVdgNDr3hVbIuE6sUW6UwlaAwuyOM/xJYPg1y0rF66958pyVJlZ9KD5A0kY3bHg7"

Expand Down
9 changes: 9 additions & 0 deletions defaults/install/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ddev docker env file.
# See: https://ddev.readthedocs.io/en/stable/users/extend/customization-extendibility/#providing-custom-environment-variables-to-a-container

# Copy this file into .env (ie. remove .example)

# Set Acquia Cloud API keys.
# See DevOps secure note in 1Password.
export ACQUIA_CLOUD_API_KEY='REPLACE_ME'
export ACQUIA_CLOUD_API_SECRET='REPLACE_ME'
2 changes: 1 addition & 1 deletion defaults/install/.platform.app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - https://github.com/platformsh/platformsh-example-drupal8/blob/master/.platform.app.yaml

name: 'app'
type: 'php:7.2'
type: 'php:8.3'

relationships:
database: 'mysqldb:mysql'
Expand Down
2 changes: 1 addition & 1 deletion defaults/install/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default:
extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
Drupal\MinkExtension:
goutte: ~
browserkit_http: ~
chrome:
api_url: "http://chrome:9222"
browser_name: chrome
Expand Down
31 changes: 5 additions & 26 deletions defaults/install/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@
<exec command="vendor/bin/phpcs" logoutput="true" checkreturn="true" />

<!-- Run PHP Mess Detector. -->
<property name="phpmd.command" value="vendor/bin/phpmd ${phpmd.directories} ${phpmd.format} ${phpmd.rulesets} --suffixes ${phpmd.suffixes}" />
<echo msg="$> ${phpmd.command}" />
<exec command="${phpmd.command}" logoutput="true" checkreturn="true" />
<echo msg="$> vendor/bin/phpmd" />
<exec command="vendor/bin/phpmd ${phpmd.directories} ${phpmd.format} ${phpmd.rulesets} --suffixes ${phpmd.suffixes}" logoutput="true" checkreturn="true" />

<!-- Run phpstan. -->
<property name="phpstan.command" value="vendor/bin/phpstan analyse" />
Expand Down Expand Up @@ -152,7 +151,7 @@
<target name="eslint" depends="install-node-dependencies">
<!-- Lint custom module and theme (by default) javascript. -->
<echo msg="$> yarn run eslint --ext ${eslint.extensions} ${eslint.directory}" />
<exec command="yarn run eslint --fix-dry-run --ext ${eslint.extensions} --resolve-plugins-relative-to ${drupal.root}/core --no-error-on-unmatched-pattern ${eslint.directory}" logoutput="true" checkreturn="true" />
<exec command="yarn run eslint --fix-dry-run --ext ${eslint.extensions} --no-error-on-unmatched-pattern ${eslint.directory}" logoutput="true" checkreturn="true" />
</target>


Expand All @@ -165,28 +164,8 @@

<!-- Target: install-node-dependencies -->
<target name="install-node-dependencies" depends="" description="Install project, core, and custom module node dependencies">
<echo msg="Seeing if project npm packages are installed and at the expected version." />
<exec command="yarn install --check-files --verbose" returnProperty="project_dependencies" logoutput="true" />
<if>
<not>
<equals arg1="${project_dependencies}" arg2="0" />
</not>
<then>
<echo msg="Install project node dependencies to get eslint libraries." />
<exec dir="${drupal.root}/.." command="yarn install" logoutput="true" />
</then>
</if>
<echo msg="Seeing if Drupal core npm packages are installed and at the expected version." />
<exec dir="${drupal.root}/core" command="yarn install --check-files --verbose" returnProperty="core_dependencies" logoutput="true" />
<if>
<not>
<equals arg1="${core_dependencies}" arg2="0" />
</not>
<then>
<echo msg="Install Core node dependencies to get eslint libraries." />
<exec dir="${drupal.root}/core" command="yarn install" logoutput="true" checkreturn="true" />
</then>
</if>
<echo msg="Install project node dependencies to get eslint libraries." />
<exec dir="${drupal.root}/.." command="yarn install" logoutput="true" />
</target>


Expand Down
78 changes: 78 additions & 0 deletions defaults/install/phpmd.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0"?>
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PMD Ruleset for Drupal" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
A PMD Ruleset for Drupal coding standards.
</description>

<!--
Include each rule explicitly so we know what we have.
@see https://github.com/phpmd/phpmd/blob/master/src/main/resources/rulesets/
-->

<!-- Clean Code -->
<!--
These don't align with Drupal standards, so they are excluded.
@todo Static calls are hard to test and extend, is there a way to whitelist the ones that are OK?
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<rule ref="rulesets/cleancode.xml/ElseExpression"/>
<rule ref="rulesets/cleancode.xml/StaticAccess"/>
-->

<!-- Code Size -->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/TooManyFields"/>

<!-- Controversial -->
<rule ref="rulesets/controversial.xml/Superglobals"/>
<!--
These checks do not need to be included since PHPCS will check for style.
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<rule ref="rulesets/controversial.xml/CamelCaseParameterName"/>
<rule ref="rulesets/controversial.xml/CamelCaseVariableName"/>
-->

<!-- Design -->
<rule ref="rulesets/design.xml/ExitExpression"/>
<rule ref="rulesets/design.xml/EvalExpression"/>
<rule ref="rulesets/design.xml/GotoStatement"/>
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<rule ref="rulesets/design.xml/CouplingBetweenObjects"/>
<rule ref="rulesets/design.xml/DevelopmentCodeFragment"/>

<!-- Naming -->
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<!-- Allow $id as a variable name. -->
<property name="exceptions" description="Comma-separated list of exceptions" value="id"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<!-- Bump variable length to a more reasonable number. -->
<property name="maximum" description="The variable length reporting threshold" value="35"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName"/>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>

<!-- Unused Code -->
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--
Hooks often have unused parameters, so ignore this warning.
@todo is there a way to allow unused parameters in hooks but not elsewhere?
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
-->

</ruleset>
2 changes: 1 addition & 1 deletion defaults/install/the-build/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ drupal:

# OPTIONAL: The Drupal database name defaults to the site's "dir" value.
database:
database: "drupal"
database: "db"

# Multisites created by `phing drupal-add-multisite` will be automatically added here.
# @multisite_placeholder@
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: the-build utility module
description: 'Base settings from palantirnet/the-build.'
type: module
core_version_requirement: ^9 || ^10
core_version_requirement: ^9 || ^10 || ^11
hide: true

dependencies:
Expand Down
Loading

0 comments on commit 4ae9b56

Please sign in to comment.